+ // Search how to restore the backtracking point
+ State* init_state = nullptr;
+ std::deque<Transition*> replay_recipe;
+ for (auto* s = backtracking_point.get(); s != nullptr; s = s->get_parent_state().get()) {
+#if SIMGRID_HAVE_STATEFUL_MC
+ if (s->get_system_state() != nullptr) { // Found a state that I can restore
+ init_state = s;
+ break;
+ }
+#endif
+ if (s->get_transition_in() != nullptr) // The root has no transition_in
+ replay_recipe.push_front(s->get_transition_in().get());
+ }
+
+ // Restore the init_state, if any
+ if (init_state != nullptr) {
+#if SIMGRID_HAVE_STATEFUL_MC
+ const auto* system_state = init_state->get_system_state();
+ system_state->restore(*get_remote_app().get_remote_process_memory());
+ on_restore_system_state_signal(init_state, get_remote_app());
+#endif
+ } else { // Restore the initial state if no intermediate state was found
+ get_remote_app().restore_initial_state();
+ on_restore_initial_state_signal(get_remote_app());
+ }
+