I visited Abu Sariha Hudhaifa b. Usaid al-Ghifari who said: I listened with these two ears of mine Allahs Messenger ﷺ as saying: The semen stays in the womb for forty nights, then the angel, gives it a shape. Zubair said: I think that he said: One who fashions that and decides whether he would be male or female. Then he (the angel) says: Would his limbs be full or imperfect? And then the Lord makes thein full and perfect or otherwise as He desires. Then he says: My Lord, what about his livelihood, and his death and what about his disposition? And then the Lord decides about his misfortune and fortune. (Using translation from Muslim 2645c)
"إِنَّ النطفةَ تقعُ في الرحمِ أَربعين ليلةً، ثم يتَصَوَّرُ ، عليها الملَكُ الذى يُخَلِّقُهَا، فيقولُ: ياربِّ، أذَكَرٌ أو أُنثى؟ فيجعَلُه اللَّه ذكرًا أو أُنثَى، ثم يقولُ: ياربِّ أسَوِىٌّ أو غيرُ سَوِىٍّ؟ فيجعَلُه اللَّه سَوِيًّا أوْ غيرَ سوىٍّ، ثم يقول: يارَبِّ ما رزقُه؟ ما أجلُه؟ ما خُلُقُهُ؟ ثم يَجْعلُه اللَّهُ شَقِيًا أوْ سَعِيدًا".