anchor.diff:        P, Debug, S, Q, State_Data,
         NextEventsR, Hibernate, TimeoutsR, Postpone,
         CallEnter, StateCall, Actions).
  +
  +%% Check the result of Module:callback_mode()
  +%%
  +loop_callback_mode_result(
  +  P, Debug, S, Q, State_Data,
  +  NextEventsR, Hibernate, TimeoutsR, Postpone,
  +  StateCall, CallbackEvent,
  +  CallbackMode, [H|T], NewCallbackMode, NewStateEnter) ->
  +    %%
  +    case callback_mode(H) of
  +        true ->
  +            loop_callback_mode_result(
  +              P, Debug, S, Q, State_Data,
  +              NextEventsR, Hibernate, TimeoutsR, Postpone,
  +              StateCall, CallbackEvent,
  +              CallbackMode, T, H, NewStateEnter);
  +        false ->
  +            case state_enter(H) of
  +                true ->
  +                    loop_callback_mode_result(
  +                      P, Debug, S, Q, State_Data,
  +                      NextEventsR, Hibernate, TimeoutsR, Postpone,
  +                      StateCall, CallbackEvent,
  +                      CallbackMode, T, NewCallbackMode, true);
  +                false ->
  +                    terminate(
  +                      error,
  +                      {bad_return_from_callback_mode,CallbackMode},
  +                      ?STACKTRACE(),
  +                      P, Debug, S, Q)
  +            end
  +    end;
  +loop_callback_mode_result(
  +  P, Debug, S, Q, State_Data,
  +  NextEventsR, Hibernate, TimeoutsR, Postpone,
  +  StateCall, CallbackEvent,
  +  CallbackMode, [], NewCallbackMode, NewStateEnter) ->
  +    %%
  +    case NewCallbackMode of
  +        undefined ->
  +            terminate(
  +              error,
  +              {bad_return_from_callback_mode,CallbackMode},
  +              ?STACKTRACE(),
  +              P, Debug, S, Q);
  +        _ ->
  +            P_1 =
  +                P#params{
  +                  callback_mode = NewCallbackMode,
  +                  state_enter = NewStateEnter},
  +            loop_state_callback(
  +              P_1, Debug, S, Q, State_Data,
  +              NextEventsR, Hibernate, TimeoutsR, Postpone,
  +              StateCall, CallbackEvent)
  +    end.
   
   %% Process the result from the state function
   %%
  
positive.code: %%
  %% %CopyrightBegin%
  %%
  %% Copyright Ericsson AB 2016-2019. All Rights Reserved.
  %%
  %% Licensed under the Apache License, Version 2.0 (the "License");
  %% you may not use this file except in compliance with the License.
  
negative.code:       NextEventsR, Hibernate, TimeoutsR, Postpone,
        StateCall, CallbackEvent).
  %%
  loop_state_callback(
    #params{callback_mode = undefined, module = Module} = P,
    Debug, S, Q, State_Data,
    NextEventsR, Hibernate, TimeoutsR, Postpone,
    StateCall, CallbackEvent) ->
      %%
      %% Figure out the callback mode
      %%
      try Module:callback_mode() of
  	CallbackMode ->
  	    loop_callback_mode_result(
                P, Debug, S, Q, State_Data,
                NextEventsR, Hibernate, TimeoutsR, Postpone,
                StateCall, CallbackEvent,
                CallbackMode, listify(CallbackMode), undefined, false)
      catch
  	CallbackMode ->
  	    loop_callback_mode_result(
                P, Debug, S, Q, State_Data,
                NextEventsR, Hibernate, TimeoutsR, Postpone,
                StateCall, CallbackEvent,
                CallbackMode, listify(CallbackMode), undefined, false);
  	Class:Reason:Stacktrace ->
  	    terminate(
  	      Class, Reason, Stacktrace, P, Debug, S, Q)
      end;
  loop_state_callback(
    #params{callback_mode = CallbackMode, module = Module} = P,
    Debug, S, Q, {State,Data} = State_Data,
  