splite _state_gen.c from reg_state.c