State Machine Example code in C