Why do babies cry to fight sleep?

It is well known that babies cry just before sleep. Sometimes the cries have specific origins that cause pain or discomfort. But as everyone knows, even when all those factors have been eliminated every baby still appears to cry in an attempt to fight sleep itself.

This question is NOT asking for a solution. This is a scientific question. I am asking why? Why do they fight sleep? Is there a survival advantage? Is there a physiological explanation? What research has been carried out into it to determine the reason for the "sleep fight"?

Could it be that a good cry before sleep actually has a physiological payoff that confers a survival advantage? Does it "prepare" the baby's breathing pathways before sleep, for example?

Are there some meta-analyses or epidemiological factors we can do to check this hypothesis? Are those babies that die of SIDS those that do not cry as much before sleep? Is there any epidemiological data to test such ideas?