Welcome to just answer
For the brain to work normally, it must receive blood from the heart. The heart is a pump and in order to pump blood out to the tissues including the brain, it has to receive it back from the body. There are factors that control the blood coming back from the body. One of them is the pressure inside the chest. If the pressure inside the chest is high, the blood is not able to travel against high pressure and no blood reaches the heart and no blood comes out of the heart.
When you cough, the pressure inside the chest rises quite a lot, and if the cough is continuous, this means that the pressure does not have enough time to go down and it rises to an extent that the flow of blood back to the heart is minimal and so the blood being pumped out of the heart to the tissues is minimal also and so the blood reaching the brain in minimal and this means that the brain would stop functioning and one would lose consciousness.
This is called cough syncope.
However the jerking of your legs at night is known as Restless leg syndrome
It is a condition in which your legs feel extremely uncomfortable while you're sitting or lying down. It makes you feel like getting up and moving around.
The exact cause is not known however it is usually associated with iron deficiency anemia, peripheral neuropathy, pregnancy and renal failure
This condition can be treated by Tab Requip and Tab Klonopin
I hope this answers your question
Let me know if you have any further questions
Also press the accept button if you feel satisfied with my response
Regard's Dr Wajid