Automated finite state machine extraction