Convert state.cpp to C