As far as I can recall there are only two films with a strong, recognizable musical theme or theme song…Elia Kazan‘s East of Eden (’55) and Robert Altman‘s The Long Goodbye (’73)…these two may be the only films in which the musical theme is sung or hummed by characters within the film itself.
Which means, obviously, that the theme was composed and performed before principal photography on these films began.
In Eden, Julie Harris hums Leonard Rosenman‘s main theme (which begins at the :40 mark in the below video), and in The Long Goodbye, a lounge singer croaks or croons John Williams and Johnny Mercer‘s “Long Goodbye” tune in the Hollywood bar in which Marlowe retrieves his messages.
There are probably other films that have operated this way, theme-song-wise — I just can’t remember them.