In ASE block the reference for current source is derived from the IMO. If external clock is selected then IMO is disabled. If the internal oscillator is turned OFF, the current source is disabled and the ramp voltage stays at ground. This causes the comparator to not trip and gives the 0xFFFF code. The internal oscillator must always be on when using the ADC.
The internal oscillator can be enabled by clearing bit 1 of register OSC_CR2 (bank1 address E2h). Use the following code snippet do the same in main.c:
OSC_CR2 &= ~0x02;
Having the IMO ON will not alter the system clock frequency when external clock is selected - that is determined only by the external clock. It will just result in a somewhat higher chip current compared to operating with the IMO disabled.