anchor.diff:  	    end
       end.
   
  -%% Enqueue immediate timeout events and start event timer
  -process_timeout_events(TimerRefs, TimerTypes, [], EventsR) ->
  -    {TimerRefs, TimerTypes, EventsR};
  -process_timeout_events(
  -  TimerRefs, TimerTypes,
  -  [{timeout,0,TimerMsg}|TimeoutEvents], []) ->
  -    %% No enqueued events - insert a timeout zero event
  -    TimeoutEvent = {timeout,TimerMsg},
  -    process_timeout_events(
  -      TimerRefs, TimerTypes,
  -      TimeoutEvents, [TimeoutEvent]);
  -process_timeout_events(
  -  TimerRefs, TimerTypes,
  -  [{timeout,Time,TimerMsg}], []) ->
  -    %% No enqueued events - start event timer
  -    TimerRef = erlang:start_timer(Time, self(), TimerMsg),
  -    process_timeout_events(
  -      TimerRefs#{TimerRef => timeout}, TimerTypes#{timeout => TimerRef},
  -      [], []);
  -process_timeout_events(
  -  TimerRefs, TimerTypes,
  -  [{timeout,_Time,_TimerMsg}|TimeoutEvents], EventsR) ->
  -    %% There will be some other event so optimize by not starting
  -    %% an event timer to just have to cancel it again
  -    process_timeout_events(
  -      TimerRefs, TimerTypes,
  -      TimeoutEvents, EventsR);
  -process_timeout_events(
  -  TimerRefs, TimerTypes,
  -  [{_TimeoutType,_TimeoutMsg} = TimeoutEvent|TimeoutEvents], EventsR) ->
  -    process_timeout_events(
  -      TimerRefs, TimerTypes,
  -      TimeoutEvents, [TimeoutEvent|EventsR]).
  +%% Enqueue immediate timeout events (timeout 0 events)
  +%%
  +%% Event timer timeout 0 events gets special treatment since
  +%% an event timer is cancelled by any received event,
  +%% so if there are enqueued events before the event timer
  +%% timeout 0 event - the event timer is cancelled hence no event.
  +%%
  +%% Other (state_timeout) timeout 0 events that are after
  +%% the event timer timeout 0 events are considered to
  +%% belong to timers that were started after the event timer
  +%% timeout 0 event fired, so they do not cancel the event timer.
  +%%
  +prepend_timeout_events([], EventsR) ->
  +    EventsR;
  +prepend_timeout_events([{timeout,_} = TimeoutEvent|TimeoutEvents], []) ->
  +    prepend_timeout_events(TimeoutEvents, [TimeoutEvent]);
  +prepend_timeout_events([{timeout,_}|TimeoutEvents], EventsR) ->
  +    prepend_timeout_events(TimeoutEvents, EventsR);
  +prepend_timeout_events([TimeoutEvent|TimeoutEvents], EventsR) ->
  +    %% Just prepend all others
  +    prepend_timeout_events(TimeoutEvents, [TimeoutEvent|EventsR]).
   
   
   
  
positive.code: 	    {error,
  	     {bad_action_from_state_function,Action},
  	     ?STACKTRACE()};
  	infinity -> % Ignore - timeout will never happen
  	    parse_actions(
  	      Debug, S, State, Actions,
  	      Hibernate, TimeoutsR, Postpone, NextEventsR);
  	Time when is_integer(Time), Time >= 0 ->
  	    Timeout = {timeout,Time,Time},
  	    parse_actions(
  	      Debug, S, State, Actions,
  
negative.code: 	    %% Unseen type - handle
  	    NewSeen = Seen#{TimerType => true},
  	    if
  		Time =:= infinity ->
  		    %% Cancel any running timer
  		    {NewTimerTypes,NewCancelTimers} =
  