Finite State Machine Design and Optimization