I have heard several songs by different artists or bands which are used in their albums as well as in the movies. So sometimes I don't understand whether these songs are made for the films or they are bought by the producers legally after the artists made it for their albums? Do the producers sometimes sponsor the song on the album?
Example 1: "Love Story" by Taylor Swift used in Letters to Juliet movie.
Example 2: "New Divide" by Linkin Park in the end of one of the Transformers movies. (I cant remember exactly which part the song is used in).
So how does the whole procedure work?