   are if statements optimized out of a state machines compiled code
  When you have a long list of if statements in a state machine will those if statments get optimised out of the compiled code? 
  How could they be? Presuming the condition is not a constant, they must be evaluated at runtime to take the correct branches. ;  Use a switch statement (don''t put in a default section) and any decent compiler will convert it into a jump table for you. That way it is a simple non-conditional operation to jump to the appropriate code for your state instead of a bunch of expensive conditionals. ;  A number of methods have been developed for compile time branch prediction, avoiding the overhead of control flow changes. Googling for "branch prediction" offered a slew of informative and highly readable articles. Another related goodie to look up is predication, which is becoming more prevalent on newer processor architectures. Finally, with newer languages like C# there exists a multitude of chances to optimize code flow branches with runtime profiling and re-just-in-time-compiling the code on the next execution, with the hindsight of profile data to optimize likely control flow. ;  Some of it is also platform specific.  Processors handle branches different they are one of the most difficult portions of code to pipeline.  And for this reason they are also of course the hardest to optimize. (However this is such an old problem that the SPARC chips and Hyperthreading may have found a way to better solve the problem.)  Also it would be cool to see how multiprocessor handle the same problem... but I don''t know I''ll leave the for later. 