Simple low-level state machine in C.