let type_trans auto env tr =
  let needs_pebble = not (single_path auto tr) in
  Aorai_option.debug
    "Analyzing transition %s -> %s: %a (needs pebble: %B)"
    tr.start.name tr.stop.name Promelaoutput.print_parsed tr.cross needs_pebble;
  match tr.cross with
    | Seq seq ->
      let default_state = find_otherwise_trans auto tr.start in
      let has_default_state = Extlib.has_some default_state in
      let _,states, transitions,_,_ =
        type_seq has_default_state tr env needs_pebble tr.start tr.stop seq
      in
      let (states, transitions as auto) =
        if List.exists (fun st -> st.multi_state <> None) states then begin
        (* We have introduced some multi-state somewhere, we have to introduce
           pebbles and propagate them from state to state. *)

          let start = tr.start in
          let count = (* TODO: make it an integer. *)
            Cil.makeGlobalVar
              (get_fresh ("aorai_cnt_" ^ start.name)) Cil.intType
          in
          add_aux_variable count;
          let transitions =
            List.map
              (fun trans ->
                match trans.cross with
                  | Epsilon _ -> trans
                  | Normal(cond,actions) ->
                    let (dest,d_aux) = memo_multi_state tr.stop in
                    let actions =
                      if tr.start.nums <> start.nums then begin
                        let src,s_aux = memo_multi_state tr.start in
                        Pebble_move(dest,d_aux,src,s_aux) :: actions
                      end else begin
                        let v = Cil.cvar_to_lvar count in
                        let incr = Counter_incr (TVar v, TNoOffsetin
                        let init = Pebble_init (dest, d_aux, v) in
                        init::incr::actions
                      end
                    in
                    { trans with
                      cross = Normal(cond, actions) })
              transitions
          in
          states, transitions
        end else
          states, transitions
      in
      if has_default_state then begin
        (* For each intermediate state, add a transition
           to the end of the sequence *)

        let default_state = Extlib.the default_state in
        let treat_one_state acc st =
          if st.nums = tr.stop.nums || st.nums = tr.start.nums then acc
          else begin
            let trans = Path_analysis.get_transitions_of_state st auto in
            let cond =
              List.fold_left
                (fun acc tr ->
                  match tr.cross with
                    | Epsilon (cond,_) | Normal(cond,_) ->
                      let cond = change_bound_var tr.stop st cond in
                      tor cond acc)
                TFalse trans
            in
            let cond =
              tnot (fst (Logic_simplification.simplifyCond cond))
            in
            match cond with
                TFalse -> acc
              | _ ->
                Aorai_option.debug
                  "Adding default transition %s -> %s: %a"
                  st.name default_state.name Promelaoutput.print_condition cond;
                new_trans st default_state (Normal (cond,[])) :: acc
          end
        in
        let default_trans = List.fold_left treat_one_state transitions states in
        Aorai_option.debug "Resulting transitions:@\n%a"
          (Pretty_utils.pp_list ~sep:"@\n"
             (fun fmt tr -> Format.fprintf fmt "%s -> %s:@[%a@]"
               tr.start.name tr.stop.name print_epsilon_trans tr.cross))
          default_trans;
        states, default_trans
      end else begin
        Aorai_option.debug "Resulting transitions:@\n%a"
          (Pretty_utils.pp_list ~sep:"@\n"
             (fun fmt tr -> Format.fprintf fmt "%s -> %s:@[%a@]"
               tr.start.name tr.stop.name print_epsilon_trans tr.cross))
          transitions;
        states, transitions
      end
    | Otherwise -> [],[]