Reverse engineering is an essential part of the modernization process that enables the evolution of existing software assets. The extraction of state machines out of existing code is an important aspect of the reverse engineering process. However, none of the reverse engineering tools fully support an automatic extraction of state machines. In our work we investigated the process of manual extraction of hierarchical state machines from the source code of an embedded C application and identified the steps of the process that can be automated. We learned that manual creation of state machines out of code is a very complicated task mostly because of the large amount of potential states that can be created by a relatively small amount of global variables. To reduce the complexity of this task we developed a methodology to decompose the code into smaller parts of functionally related elements. We showed how this technique and other system analysis mechanisms provided by the System Grokking technology can automate steps of the state machine extraction process.