As a preview, to provide the correct C ABI to main() you need to zero the BSS (this is how your static variables get initialized), maybe copy the initalized data, call the constructors and destructors for C++ / C (gcc extension), provide memcpy() and others stdlib functions (which gcc will use even if you don't), etc. You can do all of this without assembly in C, but it does take some effort.
by Jessica McKellar
It's disturbing how many Pascal-isms still pervade my thinking, even 20 years since I last (willingly) touched the language.
I always imagined something 'called us', then just returning from that would be enough to get everything shutdown.
Certainly when I wrote 6502 code, or 68000 code, I would just return.
On the iPhone, you get advised you are shutting down, do your clean-up, then someone shuts down the message loop and you are gone.