I'm answering this question (mostly) based on prior knowledge.
Inside the womb, the foetus relies on the mother for oxygen i.e. it receives oxygen from the mother's bloodstream via the umbilical cord. A foetus doesn't use its lungs for breathing inside the womb. Ever.
Besides, lungs of a foetus are considered fully matured no earlier than the 36th week of pregnancy. (Though there are exceptions to this)
During fetal life the baby's lungs are filled with fluid and they do not perform any respiratory functions. 
At birth, the baby is forced to breath on its own for the first time. Hence, the baby cries - or more precisely - gasps for air.
This 'cry' of the baby is actually a strong respiratory effort, thereby aiding the baby in its first breath. This is also why newborns don't produce tears on their first cry. Because it's not really a cry, it's a gasp for air.
Now the reason why such a considerable effort is required for the newborn to breathe is because:
A) Lungs are being used for the first time, and
B) The lungs of a foetus are filled with amniotic fluid when it's inside the womb. Effort is needed to push this fluid out from the lungs after birth.
I'm not aware if there's any genetics involved in this. I don't think there is.
Source:  http://www.thehindu.com/todays-paper/tp-features/tp-sci-tech-and-agri/babys-first-cry/article2267767.ece