The original book that led to the movies Last Man On Earth, The Omega Man and I Am Legend (and have I missed any?) has a somewhat pessimistic ending (Richard Matheson's great I Am Legend). I know that Hollywood often likes to sugar-coat stories as audiences often react badly to pessimism (e.g. the original cuts of Blade Runner, The Long Kiss Goodnight and many others).
But this is not a universal rule and some movies don't feel compelled to be upbeat (e.g. from two very different eras, Reservoir Dogs and The Parallax View).
So why not for I Am Legend? Has nobody ever attempted a pessimistic version? And what did Richard Matheson think of the movie adaptations?
Original ending:
In the book, the protagonist turns out to actually be The Legend, as opposed to the vampires of 'myth'. To this end, he suddenly realizes that he is the boogyman, a creature that walks by day and kills scores of the 'new population'. It transpires that the infected are actually starting to improve, so he allows himself to be caught and executed for his crimes - thus becoming the legend.