PLCgen: split generated `MAIN` over multiple functions to prevent too large code
Probably, we should have separate functions for the following: read inputs, init state, update timers, one per uncontrollable event, one per controllable event, write outputs). This gives a good balance between not too much code (and temporary variables) per function, while also not too many functions.
See also discussions in #912 (closed).
Addresses #912 (closed), #679