This is a bad implementation of coroutines in c. I was expirementing with standart c ways to implement coroutines without system specific code. The problem here is wastfull usage of the stack when a lot of the function calls do not return and there is no need for a prolog/saving the return address.. I am not sure if there is a way in the c standart to not save the return address on function call, I hope with setjmp() and longjmp() it will be possible to prevent all the function calls.
Next try I am going to tackle the problem using setjmp() and longjmp()
After more reading, this is not possible without custom assembly code. Because setjmp and longjmp will corrupt the stack, implementing coroutines in C requires creating separate stacks for each routine.