(* Generated by coq-of-rust *)
Require Import CoqOfRust.CoqOfRust.

Module control_flow.
  (*
  pub fn verify_function<'a>(
      verifier_config: &'a VerifierConfig,
      module: &'a CompiledModule,
      index: FunctionDefinitionIndex,
      function_definition: &'a FunctionDefinition,
      code: &'a CodeUnit,
      _meter: &mut (impl Meter + ?Sized), // TODO: metering
  ) -> PartialVMResult<FunctionContext<'a>> {
      let function_handle = module.function_handle_at(function_definition.function);
  
      if module.version() <= 5 {
          control_flow_v5::verify(verifier_config, Some(index), code)?;
          Ok(FunctionContext::new(module, index, code, function_handle))
      } else {
          verify_fallthrough(Some(index), code)?;
          let function_context = FunctionContext::new(module, index, code, function_handle);
          verify_reducibility(verifier_config, &function_context)?;
          Ok(function_context)
      }
  }
  *)
  Definition verify_function (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [],
        [ impl_Meter__plus___Sized ],
        [ verifier_config; module; index; function_definition; code; _meter ] =>
      ltac:(M.monadic
        (let verifier_config := M.alloc (| verifier_config |) in
        let module := M.alloc (| module |) in
        let index := M.alloc (| index |) in
        let function_definition := M.alloc (| function_definition |) in
        let code := M.alloc (| code |) in
        let _meter := M.alloc (| _meter |) in
        M.catch_return (|
          ltac:(M.monadic
            (M.read (|
              let~ function_handle :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.path "move_binary_format::file_format::CompiledModule",
                      "function_handle_at",
                      []
                    |),
                    [
                      M.read (| module |);
                      M.read (|
                        M.SubPointer.get_struct_record_field (|
                          M.read (| function_definition |),
                          "move_binary_format::file_format::FunctionDefinition",
                          "function"
                        |)
                      |)
                    ]
                  |)
                |) in
              M.match_operator (|
                M.alloc (| Value.Tuple [] |),
                [
                  fun γ =>
                    ltac:(M.monadic
                      (let γ :=
                        M.use
                          (M.alloc (|
                            BinOp.le (|
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.path "move_binary_format::file_format::CompiledModule",
                                  "version",
                                  []
                                |),
                                [ M.read (| module |) ]
                              |),
                              Value.Integer IntegerKind.U32 5
                            |)
                          |)) in
                      let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                      let~ _ :=
                        M.match_operator (|
                          M.alloc (|
                            M.call_closure (|
                              M.get_trait_method (|
                                "core::ops::try_trait::Try",
                                Ty.apply
                                  (Ty.path "core::result::Result")
                                  []
                                  [
                                    Ty.tuple [];
                                    Ty.path "move_binary_format::errors::PartialVMError"
                                  ],
                                [],
                                "branch",
                                []
                              |),
                              [
                                M.call_closure (|
                                  M.get_function (|
                                    "move_bytecode_verifier::control_flow_v5::verify",
                                    []
                                  |),
                                  [
                                    M.read (| verifier_config |);
                                    Value.StructTuple
                                      "core::option::Option::Some"
                                      [ M.read (| index |) ];
                                    M.read (| code |)
                                  ]
                                |)
                              ]
                            |)
                          |),
                          [
                            fun γ =>
                              ltac:(M.monadic
                                (let γ0_0 :=
                                  M.SubPointer.get_struct_tuple_field (|
                                    γ,
                                    "core::ops::control_flow::ControlFlow::Break",
                                    0
                                  |) in
                                let residual := M.copy (| γ0_0 |) in
                                M.alloc (|
                                  M.never_to_any (|
                                    M.read (|
                                      M.return_ (|
                                        M.call_closure (|
                                          M.get_trait_method (|
                                            "core::ops::try_trait::FromResidual",
                                            Ty.apply
                                              (Ty.path "core::result::Result")
                                              []
                                              [
                                                Ty.path
                                                  "move_bytecode_verifier::absint::FunctionContext";
                                                Ty.path "move_binary_format::errors::PartialVMError"
                                              ],
                                            [
                                              Ty.apply
                                                (Ty.path "core::result::Result")
                                                []
                                                [
                                                  Ty.path "core::convert::Infallible";
                                                  Ty.path
                                                    "move_binary_format::errors::PartialVMError"
                                                ]
                                            ],
                                            "from_residual",
                                            []
                                          |),
                                          [ M.read (| residual |) ]
                                        |)
                                      |)
                                    |)
                                  |)
                                |)));
                            fun γ =>
                              ltac:(M.monadic
                                (let γ0_0 :=
                                  M.SubPointer.get_struct_tuple_field (|
                                    γ,
                                    "core::ops::control_flow::ControlFlow::Continue",
                                    0
                                  |) in
                                let val := M.copy (| γ0_0 |) in
                                val))
                          ]
                        |) in
                      M.alloc (|
                        Value.StructTuple
                          "core::result::Result::Ok"
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "move_bytecode_verifier::absint::FunctionContext",
                                "new",
                                []
                              |),
                              [
                                M.read (| module |);
                                M.read (| index |);
                                M.read (| code |);
                                M.read (| function_handle |)
                              ]
                            |)
                          ]
                      |)));
                  fun γ =>
                    ltac:(M.monadic
                      (let~ _ :=
                        M.match_operator (|
                          M.alloc (|
                            M.call_closure (|
                              M.get_trait_method (|
                                "core::ops::try_trait::Try",
                                Ty.apply
                                  (Ty.path "core::result::Result")
                                  []
                                  [
                                    Ty.tuple [];
                                    Ty.path "move_binary_format::errors::PartialVMError"
                                  ],
                                [],
                                "branch",
                                []
                              |),
                              [
                                M.call_closure (|
                                  M.get_function (|
                                    "move_bytecode_verifier::control_flow::verify_fallthrough",
                                    []
                                  |),
                                  [
                                    Value.StructTuple
                                      "core::option::Option::Some"
                                      [ M.read (| index |) ];
                                    M.read (| code |)
                                  ]
                                |)
                              ]
                            |)
                          |),
                          [
                            fun γ =>
                              ltac:(M.monadic
                                (let γ0_0 :=
                                  M.SubPointer.get_struct_tuple_field (|
                                    γ,
                                    "core::ops::control_flow::ControlFlow::Break",
                                    0
                                  |) in
                                let residual := M.copy (| γ0_0 |) in
                                M.alloc (|
                                  M.never_to_any (|
                                    M.read (|
                                      M.return_ (|
                                        M.call_closure (|
                                          M.get_trait_method (|
                                            "core::ops::try_trait::FromResidual",
                                            Ty.apply
                                              (Ty.path "core::result::Result")
                                              []
                                              [
                                                Ty.path
                                                  "move_bytecode_verifier::absint::FunctionContext";
                                                Ty.path "move_binary_format::errors::PartialVMError"
                                              ],
                                            [
                                              Ty.apply
                                                (Ty.path "core::result::Result")
                                                []
                                                [
                                                  Ty.path "core::convert::Infallible";
                                                  Ty.path
                                                    "move_binary_format::errors::PartialVMError"
                                                ]
                                            ],
                                            "from_residual",
                                            []
                                          |),
                                          [ M.read (| residual |) ]
                                        |)
                                      |)
                                    |)
                                  |)
                                |)));
                            fun γ =>
                              ltac:(M.monadic
                                (let γ0_0 :=
                                  M.SubPointer.get_struct_tuple_field (|
                                    γ,
                                    "core::ops::control_flow::ControlFlow::Continue",
                                    0
                                  |) in
                                let val := M.copy (| γ0_0 |) in
                                val))
                          ]
                        |) in
                      let~ function_context :=
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.path "move_bytecode_verifier::absint::FunctionContext",
                              "new",
                              []
                            |),
                            [
                              M.read (| module |);
                              M.read (| index |);
                              M.read (| code |);
                              M.read (| function_handle |)
                            ]
                          |)
                        |) in
                      let~ _ :=
                        M.match_operator (|
                          M.alloc (|
                            M.call_closure (|
                              M.get_trait_method (|
                                "core::ops::try_trait::Try",
                                Ty.apply
                                  (Ty.path "core::result::Result")
                                  []
                                  [
                                    Ty.tuple [];
                                    Ty.path "move_binary_format::errors::PartialVMError"
                                  ],
                                [],
                                "branch",
                                []
                              |),
                              [
                                M.call_closure (|
                                  M.get_function (|
                                    "move_bytecode_verifier::control_flow::verify_reducibility",
                                    []
                                  |),
                                  [ M.read (| verifier_config |); function_context ]
                                |)
                              ]
                            |)
                          |),
                          [
                            fun γ =>
                              ltac:(M.monadic
                                (let γ0_0 :=
                                  M.SubPointer.get_struct_tuple_field (|
                                    γ,
                                    "core::ops::control_flow::ControlFlow::Break",
                                    0
                                  |) in
                                let residual := M.copy (| γ0_0 |) in
                                M.alloc (|
                                  M.never_to_any (|
                                    M.read (|
                                      M.return_ (|
                                        M.call_closure (|
                                          M.get_trait_method (|
                                            "core::ops::try_trait::FromResidual",
                                            Ty.apply
                                              (Ty.path "core::result::Result")
                                              []
                                              [
                                                Ty.path
                                                  "move_bytecode_verifier::absint::FunctionContext";
                                                Ty.path "move_binary_format::errors::PartialVMError"
                                              ],
                                            [
                                              Ty.apply
                                                (Ty.path "core::result::Result")
                                                []
                                                [
                                                  Ty.path "core::convert::Infallible";
                                                  Ty.path
                                                    "move_binary_format::errors::PartialVMError"
                                                ]
                                            ],
                                            "from_residual",
                                            []
                                          |),
                                          [ M.read (| residual |) ]
                                        |)
                                      |)
                                    |)
                                  |)
                                |)));
                            fun γ =>
                              ltac:(M.monadic
                                (let γ0_0 :=
                                  M.SubPointer.get_struct_tuple_field (|
                                    γ,
                                    "core::ops::control_flow::ControlFlow::Continue",
                                    0
                                  |) in
                                let val := M.copy (| γ0_0 |) in
                                val))
                          ]
                        |) in
                      M.alloc (|
                        Value.StructTuple
                          "core::result::Result::Ok"
                          [ M.read (| function_context |) ]
                      |)))
                ]
              |)
            |)))
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Function_verify_function :
    M.IsFunction "move_bytecode_verifier::control_flow::verify_function" verify_function.
  
  (*
  fn verify_fallthrough(
      current_function_opt: Option<FunctionDefinitionIndex>,
      code: &CodeUnit,
  ) -> PartialVMResult<()> {
      let current_function = current_function_opt.unwrap_or(FunctionDefinitionIndex(0));
      match code.code.last() {
          None => Err(PartialVMError::new(StatusCode::EMPTY_CODE_UNIT)),
          Some(last) if !last.is_unconditional_branch() => {
              Err(PartialVMError::new(StatusCode::INVALID_FALL_THROUGH)
                  .at_code_offset(current_function, (code.code.len() - 1) as CodeOffset))
          }
          Some(_) => Ok(()),
      }
  }
  *)
  Definition verify_fallthrough (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ current_function_opt; code ] =>
      ltac:(M.monadic
        (let current_function_opt := M.alloc (| current_function_opt |) in
        let code := M.alloc (| code |) in
        M.read (|
          let~ current_function :=
            M.alloc (|
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "core::option::Option")
                    []
                    [ Ty.path "move_binary_format::file_format::FunctionDefinitionIndex" ],
                  "unwrap_or",
                  []
                |),
                [
                  M.read (| current_function_opt |);
                  Value.StructTuple
                    "move_binary_format::file_format::FunctionDefinitionIndex"
                    [ Value.Integer IntegerKind.U16 0 ]
                ]
              |)
            |) in
          M.match_operator (|
            M.alloc (|
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "slice")
                    []
                    [ Ty.path "move_binary_format::file_format::Bytecode" ],
                  "last",
                  []
                |),
                [
                  M.call_closure (|
                    M.get_trait_method (|
                      "core::ops::deref::Deref",
                      Ty.apply
                        (Ty.path "alloc::vec::Vec")
                        []
                        [
                          Ty.path "move_binary_format::file_format::Bytecode";
                          Ty.path "alloc::alloc::Global"
                        ],
                      [],
                      "deref",
                      []
                    |),
                    [
                      M.SubPointer.get_struct_record_field (|
                        M.read (| code |),
                        "move_binary_format::file_format::CodeUnit",
                        "code"
                      |)
                    ]
                  |)
                ]
              |)
            |),
            [
              fun γ =>
                ltac:(M.monadic
                  (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in
                  M.alloc (|
                    Value.StructTuple
                      "core::result::Result::Err"
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.path "move_binary_format::errors::PartialVMError",
                            "new",
                            []
                          |),
                          [
                            Value.StructTuple
                              "move_core_types::vm_status::StatusCode::EMPTY_CODE_UNIT"
                              []
                          ]
                        |)
                      ]
                  |)));
              fun γ =>
                ltac:(M.monadic
                  (let γ0_0 :=
                    M.SubPointer.get_struct_tuple_field (| γ, "core::option::Option::Some", 0 |) in
                  let last := M.copy (| γ0_0 |) in
                  let γ :=
                    M.alloc (|
                      UnOp.not (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.path "move_binary_format::file_format::Bytecode",
                            "is_unconditional_branch",
                            []
                          |),
                          [ M.read (| last |) ]
                        |)
                      |)
                    |) in
                  let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                  M.alloc (|
                    Value.StructTuple
                      "core::result::Result::Err"
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.path "move_binary_format::errors::PartialVMError",
                            "at_code_offset",
                            []
                          |),
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "move_binary_format::errors::PartialVMError",
                                "new",
                                []
                              |),
                              [
                                Value.StructTuple
                                  "move_core_types::vm_status::StatusCode::INVALID_FALL_THROUGH"
                                  []
                              ]
                            |);
                            M.read (| current_function |);
                            M.rust_cast
                              (BinOp.Wrap.sub (|
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply
                                      (Ty.path "alloc::vec::Vec")
                                      []
                                      [
                                        Ty.path "move_binary_format::file_format::Bytecode";
                                        Ty.path "alloc::alloc::Global"
                                      ],
                                    "len",
                                    []
                                  |),
                                  [
                                    M.SubPointer.get_struct_record_field (|
                                      M.read (| code |),
                                      "move_binary_format::file_format::CodeUnit",
                                      "code"
                                    |)
                                  ]
                                |),
                                Value.Integer IntegerKind.Usize 1
                              |))
                          ]
                        |)
                      ]
                  |)));
              fun γ =>
                ltac:(M.monadic
                  (let γ0_0 :=
                    M.SubPointer.get_struct_tuple_field (| γ, "core::option::Option::Some", 0 |) in
                  M.alloc (| Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] |)))
            ]
          |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Function_verify_fallthrough :
    M.IsFunction "move_bytecode_verifier::control_flow::verify_fallthrough" verify_fallthrough.
  
  (*
  fn verify_reducibility<'a>(
      verifier_config: &VerifierConfig,
      function_context: &'a FunctionContext<'a>,
  ) -> PartialVMResult<()> {
      let current_function = function_context
          .index()
          .unwrap_or(FunctionDefinitionIndex(0));
      let err = move |code: StatusCode, offset: CodeOffset| {
          Err(PartialVMError::new(code).at_code_offset(current_function, offset))
      };
  
      let summary = LoopSummary::new(function_context.cfg());
      let mut partition = LoopPartition::new(&summary);
  
      // Iterate through nodes in reverse pre-order so more deeply nested loops (which would appear
      // later in the pre-order) are processed first.
      for head in summary.preorder().rev() {
          // If a node has no back edges, it is not a loop head, so doesn't need to be processed.
          let back = summary.back_edges(head);
          if back.is_empty() {
              continue;
          }
  
          // Collect the rest of the nodes in `head`'s loop, in `body`.  Start with the nodes that
          // jump back to the head, and grow `body` by repeatedly following predecessor edges until
          // `head` is found again.
  
          let mut body = BTreeSet::new();
          for node in back {
              let node = partition.containing_loop( *node);
  
              if node != head {
                  body.insert(node);
              }
          }
  
          let mut frontier: Vec<_> = body.iter().copied().collect();
          while let Some(node) = frontier.pop() {
              for pred in summary.pred_edges(node) {
                  let pred = partition.containing_loop( *pred);
  
                  // `pred` can eventually jump back to `head`, so is part of its body.  If it is not
                  // a descendant of `head`, it implies that `head` does not dominate a node in its
                  // loop, therefore the CFG is not reducible, according to Property 1 (see doc
                  // comment).
                  if !summary.is_descendant(/* ancestor */ head, /* descendant */ pred) {
                      return err(StatusCode::INVALID_LOOP_SPLIT, summary.block(pred));
                  }
  
                  let body_extended = pred != head && body.insert(pred);
                  if body_extended {
                      frontier.push(pred);
                  }
              }
          }
  
          // Collapse all the nodes in `body` into `head`, so it appears as one node when processing
          // outer loops (this performs a sequence of Operation 4(b), followed by a 4(a)).
          let depth = partition.collapse_loop(head, &body);
          if let Some(max_depth) = verifier_config.max_loop_depth {
              if depth as usize > max_depth {
                  return err(StatusCode::LOOP_MAX_DEPTH_REACHED, summary.block(head));
              }
          }
      }
  
      Ok(())
  }
  *)
  Definition verify_reducibility (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ verifier_config; function_context ] =>
      ltac:(M.monadic
        (let verifier_config := M.alloc (| verifier_config |) in
        let function_context := M.alloc (| function_context |) in
        M.catch_return (|
          ltac:(M.monadic
            (M.read (|
              let~ current_function :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "core::option::Option")
                        []
                        [ Ty.path "move_binary_format::file_format::FunctionDefinitionIndex" ],
                      "unwrap_or",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.path "move_bytecode_verifier::absint::FunctionContext",
                          "index",
                          []
                        |),
                        [ M.read (| function_context |) ]
                      |);
                      Value.StructTuple
                        "move_binary_format::file_format::FunctionDefinitionIndex"
                        [ Value.Integer IntegerKind.U16 0 ]
                    ]
                  |)
                |) in
              let~ err :=
                M.alloc (|
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0; α1 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let code := M.copy (| γ |) in
                                    M.match_operator (|
                                      M.alloc (| α1 |),
                                      [
                                        fun γ =>
                                          ltac:(M.monadic
                                            (let offset := M.copy (| γ |) in
                                            Value.StructTuple
                                              "core::result::Result::Err"
                                              [
                                                M.call_closure (|
                                                  M.get_associated_function (|
                                                    Ty.path
                                                      "move_binary_format::errors::PartialVMError",
                                                    "at_code_offset",
                                                    []
                                                  |),
                                                  [
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.path
                                                          "move_binary_format::errors::PartialVMError",
                                                        "new",
                                                        []
                                                      |),
                                                      [ M.read (| code |) ]
                                                    |);
                                                    M.read (| current_function |);
                                                    M.read (| offset |)
                                                  ]
                                                |)
                                              ]))
                                      ]
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                |) in
              let~ summary :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.path "move_bytecode_verifier::loop_summary::LoopSummary",
                      "new",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.path "move_bytecode_verifier::absint::FunctionContext",
                          "cfg",
                          []
                        |),
                        [ M.read (| function_context |) ]
                      |)
                    ]
                  |)
                |) in
              let~ partition :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.path "move_bytecode_verifier::loop_summary::LoopPartition",
                      "new",
                      []
                    |),
                    [ summary ]
                  |)
                |) in
              let~ _ :=
                M.use
                  (M.match_operator (|
                    M.alloc (|
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::iter::traits::collect::IntoIterator",
                          Ty.apply (Ty.path "core::iter::adapters::rev::Rev") [] [ Ty.associated ],
                          [],
                          "into_iter",
                          []
                        |),
                        [
                          M.call_closure (|
                            M.get_trait_method (|
                              "core::iter::traits::iterator::Iterator",
                              Ty.associated,
                              [],
                              "rev",
                              []
                            |),
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.path "move_bytecode_verifier::loop_summary::LoopSummary",
                                  "preorder",
                                  []
                                |),
                                [ summary ]
                              |)
                            ]
                          |)
                        ]
                      |)
                    |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let iter := M.copy (| γ |) in
                          M.loop (|
                            ltac:(M.monadic
                              (let~ _ :=
                                M.match_operator (|
                                  M.alloc (|
                                    M.call_closure (|
                                      M.get_trait_method (|
                                        "core::iter::traits::iterator::Iterator",
                                        Ty.apply
                                          (Ty.path "core::iter::adapters::rev::Rev")
                                          []
                                          [ Ty.associated ],
                                        [],
                                        "next",
                                        []
                                      |),
                                      [ iter ]
                                    |)
                                  |),
                                  [
                                    fun γ =>
                                      ltac:(M.monadic
                                        (let _ :=
                                          M.is_struct_tuple (| γ, "core::option::Option::None" |) in
                                        M.alloc (|
                                          M.never_to_any (| M.read (| M.break (||) |) |)
                                        |)));
                                    fun γ =>
                                      ltac:(M.monadic
                                        (let γ0_0 :=
                                          M.SubPointer.get_struct_tuple_field (|
                                            γ,
                                            "core::option::Option::Some",
                                            0
                                          |) in
                                        let head := M.copy (| γ0_0 |) in
                                        let~ back :=
                                          M.alloc (|
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.path
                                                  "move_bytecode_verifier::loop_summary::LoopSummary",
                                                "back_edges",
                                                []
                                              |),
                                              [ summary; M.read (| head |) ]
                                            |)
                                          |) in
                                        let~ _ :=
                                          M.match_operator (|
                                            M.alloc (| Value.Tuple [] |),
                                            [
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ :=
                                                    M.use
                                                      (M.alloc (|
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path "alloc::vec::Vec")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "move_bytecode_verifier::loop_summary::NodeId";
                                                                Ty.path "alloc::alloc::Global"
                                                              ],
                                                            "is_empty",
                                                            []
                                                          |),
                                                          [ M.read (| back |) ]
                                                        |)
                                                      |)) in
                                                  let _ :=
                                                    M.is_constant_or_break_match (|
                                                      M.read (| γ |),
                                                      Value.Bool true
                                                    |) in
                                                  M.alloc (|
                                                    M.never_to_any (|
                                                      M.read (| M.continue (||) |)
                                                    |)
                                                  |)));
                                              fun γ =>
                                                ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                                            ]
                                          |) in
                                        let~ body :=
                                          M.alloc (|
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::set::BTreeSet")
                                                  []
                                                  [
                                                    Ty.path
                                                      "move_bytecode_verifier::loop_summary::NodeId";
                                                    Ty.path "alloc::alloc::Global"
                                                  ],
                                                "new",
                                                []
                                              |),
                                              []
                                            |)
                                          |) in
                                        let~ _ :=
                                          M.use
                                            (M.match_operator (|
                                              M.alloc (|
                                                M.call_closure (|
                                                  M.get_trait_method (|
                                                    "core::iter::traits::collect::IntoIterator",
                                                    Ty.apply
                                                      (Ty.path "&")
                                                      []
                                                      [
                                                        Ty.apply
                                                          (Ty.path "alloc::vec::Vec")
                                                          []
                                                          [
                                                            Ty.path
                                                              "move_bytecode_verifier::loop_summary::NodeId";
                                                            Ty.path "alloc::alloc::Global"
                                                          ]
                                                      ],
                                                    [],
                                                    "into_iter",
                                                    []
                                                  |),
                                                  [ M.read (| back |) ]
                                                |)
                                              |),
                                              [
                                                fun γ =>
                                                  ltac:(M.monadic
                                                    (let iter := M.copy (| γ |) in
                                                    M.loop (|
                                                      ltac:(M.monadic
                                                        (let~ _ :=
                                                          M.match_operator (|
                                                            M.alloc (|
                                                              M.call_closure (|
                                                                M.get_trait_method (|
                                                                  "core::iter::traits::iterator::Iterator",
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "core::slice::iter::Iter")
                                                                    []
                                                                    [
                                                                      Ty.path
                                                                        "move_bytecode_verifier::loop_summary::NodeId"
                                                                    ],
                                                                  [],
                                                                  "next",
                                                                  []
                                                                |),
                                                                [ iter ]
                                                              |)
                                                            |),
                                                            [
                                                              fun γ =>
                                                                ltac:(M.monadic
                                                                  (let _ :=
                                                                    M.is_struct_tuple (|
                                                                      γ,
                                                                      "core::option::Option::None"
                                                                    |) in
                                                                  M.alloc (|
                                                                    M.never_to_any (|
                                                                      M.read (| M.break (||) |)
                                                                    |)
                                                                  |)));
                                                              fun γ =>
                                                                ltac:(M.monadic
                                                                  (let γ0_0 :=
                                                                    M.SubPointer.get_struct_tuple_field (|
                                                                      γ,
                                                                      "core::option::Option::Some",
                                                                      0
                                                                    |) in
                                                                  let node := M.copy (| γ0_0 |) in
                                                                  let~ node :=
                                                                    M.alloc (|
                                                                      M.call_closure (|
                                                                        M.get_associated_function (|
                                                                          Ty.path
                                                                            "move_bytecode_verifier::loop_summary::LoopPartition",
                                                                          "containing_loop",
                                                                          []
                                                                        |),
                                                                        [
                                                                          partition;
                                                                          M.read (|
                                                                            M.read (| node |)
                                                                          |)
                                                                        ]
                                                                      |)
                                                                    |) in
                                                                  M.match_operator (|
                                                                    M.alloc (| Value.Tuple [] |),
                                                                    [
                                                                      fun γ =>
                                                                        ltac:(M.monadic
                                                                          (let γ :=
                                                                            M.use
                                                                              (M.alloc (|
                                                                                M.call_closure (|
                                                                                  M.get_trait_method (|
                                                                                    "core::cmp::PartialEq",
                                                                                    Ty.path
                                                                                      "move_bytecode_verifier::loop_summary::NodeId",
                                                                                    [
                                                                                      Ty.path
                                                                                        "move_bytecode_verifier::loop_summary::NodeId"
                                                                                    ],
                                                                                    "ne",
                                                                                    []
                                                                                  |),
                                                                                  [ node; head ]
                                                                                |)
                                                                              |)) in
                                                                          let _ :=
                                                                            M.is_constant_or_break_match (|
                                                                              M.read (| γ |),
                                                                              Value.Bool true
                                                                            |) in
                                                                          let~ _ :=
                                                                            M.alloc (|
                                                                              M.call_closure (|
                                                                                M.get_associated_function (|
                                                                                  Ty.apply
                                                                                    (Ty.path
                                                                                      "alloc::collections::btree::set::BTreeSet")
                                                                                    []
                                                                                    [
                                                                                      Ty.path
                                                                                        "move_bytecode_verifier::loop_summary::NodeId";
                                                                                      Ty.path
                                                                                        "alloc::alloc::Global"
                                                                                    ],
                                                                                  "insert",
                                                                                  []
                                                                                |),
                                                                                [
                                                                                  body;
                                                                                  M.read (| node |)
                                                                                ]
                                                                              |)
                                                                            |) in
                                                                          M.alloc (|
                                                                            Value.Tuple []
                                                                          |)));
                                                                      fun γ =>
                                                                        ltac:(M.monadic
                                                                          (M.alloc (|
                                                                            Value.Tuple []
                                                                          |)))
                                                                    ]
                                                                  |)))
                                                            ]
                                                          |) in
                                                        M.alloc (| Value.Tuple [] |)))
                                                    |)))
                                              ]
                                            |)) in
                                        let~ frontier :=
                                          M.alloc (|
                                            M.call_closure (|
                                              M.get_trait_method (|
                                                "core::iter::traits::iterator::Iterator",
                                                Ty.apply
                                                  (Ty.path "core::iter::adapters::copied::Copied")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::set::Iter")
                                                      []
                                                      [
                                                        Ty.path
                                                          "move_bytecode_verifier::loop_summary::NodeId"
                                                      ]
                                                  ],
                                                [],
                                                "collect",
                                                [
                                                  Ty.apply
                                                    (Ty.path "alloc::vec::Vec")
                                                    []
                                                    [
                                                      Ty.path
                                                        "move_bytecode_verifier::loop_summary::NodeId";
                                                      Ty.path "alloc::alloc::Global"
                                                    ]
                                                ]
                                              |),
                                              [
                                                M.call_closure (|
                                                  M.get_trait_method (|
                                                    "core::iter::traits::iterator::Iterator",
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::set::Iter")
                                                      []
                                                      [
                                                        Ty.path
                                                          "move_bytecode_verifier::loop_summary::NodeId"
                                                      ],
                                                    [],
                                                    "copied",
                                                    [
                                                      Ty.path
                                                        "move_bytecode_verifier::loop_summary::NodeId"
                                                    ]
                                                  |),
                                                  [
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::set::BTreeSet")
                                                          []
                                                          [
                                                            Ty.path
                                                              "move_bytecode_verifier::loop_summary::NodeId";
                                                            Ty.path "alloc::alloc::Global"
                                                          ],
                                                        "iter",
                                                        []
                                                      |),
                                                      [ body ]
                                                    |)
                                                  ]
                                                |)
                                              ]
                                            |)
                                          |) in
                                        let~ _ :=
                                          M.loop (|
                                            ltac:(M.monadic
                                              (M.match_operator (|
                                                M.alloc (| Value.Tuple [] |),
                                                [
                                                  fun γ =>
                                                    ltac:(M.monadic
                                                      (let γ :=
                                                        M.alloc (|
                                                          M.call_closure (|
                                                            M.get_associated_function (|
                                                              Ty.apply
                                                                (Ty.path "alloc::vec::Vec")
                                                                []
                                                                [
                                                                  Ty.path
                                                                    "move_bytecode_verifier::loop_summary::NodeId";
                                                                  Ty.path "alloc::alloc::Global"
                                                                ],
                                                              "pop",
                                                              []
                                                            |),
                                                            [ frontier ]
                                                          |)
                                                        |) in
                                                      let γ0_0 :=
                                                        M.SubPointer.get_struct_tuple_field (|
                                                          γ,
                                                          "core::option::Option::Some",
                                                          0
                                                        |) in
                                                      let node := M.copy (| γ0_0 |) in
                                                      M.use
                                                        (M.match_operator (|
                                                          M.alloc (|
                                                            M.call_closure (|
                                                              M.get_trait_method (|
                                                                "core::iter::traits::collect::IntoIterator",
                                                                Ty.apply
                                                                  (Ty.path "&")
                                                                  []
                                                                  [
                                                                    Ty.apply
                                                                      (Ty.path "alloc::vec::Vec")
                                                                      []
                                                                      [
                                                                        Ty.path
                                                                          "move_bytecode_verifier::loop_summary::NodeId";
                                                                        Ty.path
                                                                          "alloc::alloc::Global"
                                                                      ]
                                                                  ],
                                                                [],
                                                                "into_iter",
                                                                []
                                                              |),
                                                              [
                                                                M.call_closure (|
                                                                  M.get_associated_function (|
                                                                    Ty.path
                                                                      "move_bytecode_verifier::loop_summary::LoopSummary",
                                                                    "pred_edges",
                                                                    []
                                                                  |),
                                                                  [ summary; M.read (| node |) ]
                                                                |)
                                                              ]
                                                            |)
                                                          |),
                                                          [
                                                            fun γ =>
                                                              ltac:(M.monadic
                                                                (let iter := M.copy (| γ |) in
                                                                M.loop (|
                                                                  ltac:(M.monadic
                                                                    (let~ _ :=
                                                                      M.match_operator (|
                                                                        M.alloc (|
                                                                          M.call_closure (|
                                                                            M.get_trait_method (|
                                                                              "core::iter::traits::iterator::Iterator",
                                                                              Ty.apply
                                                                                (Ty.path
                                                                                  "core::slice::iter::Iter")
                                                                                []
                                                                                [
                                                                                  Ty.path
                                                                                    "move_bytecode_verifier::loop_summary::NodeId"
                                                                                ],
                                                                              [],
                                                                              "next",
                                                                              []
                                                                            |),
                                                                            [ iter ]
                                                                          |)
                                                                        |),
                                                                        [
                                                                          fun γ =>
                                                                            ltac:(M.monadic
                                                                              (let _ :=
                                                                                M.is_struct_tuple (|
                                                                                  γ,
                                                                                  "core::option::Option::None"
                                                                                |) in
                                                                              M.alloc (|
                                                                                M.never_to_any (|
                                                                                  M.read (|
                                                                                    M.break (||)
                                                                                  |)
                                                                                |)
                                                                              |)));
                                                                          fun γ =>
                                                                            ltac:(M.monadic
                                                                              (let γ0_0 :=
                                                                                M.SubPointer.get_struct_tuple_field (|
                                                                                  γ,
                                                                                  "core::option::Option::Some",
                                                                                  0
                                                                                |) in
                                                                              let pred :=
                                                                                M.copy (| γ0_0 |) in
                                                                              let~ pred :=
                                                                                M.alloc (|
                                                                                  M.call_closure (|
                                                                                    M.get_associated_function (|
                                                                                      Ty.path
                                                                                        "move_bytecode_verifier::loop_summary::LoopPartition",
                                                                                      "containing_loop",
                                                                                      []
                                                                                    |),
                                                                                    [
                                                                                      partition;
                                                                                      M.read (|
                                                                                        M.read (|
                                                                                          pred
                                                                                        |)
                                                                                      |)
                                                                                    ]
                                                                                  |)
                                                                                |) in
                                                                              let~ _ :=
                                                                                M.match_operator (|
                                                                                  M.alloc (|
                                                                                    Value.Tuple []
                                                                                  |),
                                                                                  [
                                                                                    fun γ =>
                                                                                      ltac:(M.monadic
                                                                                        (let γ :=
                                                                                          M.use
                                                                                            (M.alloc (|
                                                                                              UnOp.not (|
                                                                                                M.call_closure (|
                                                                                                  M.get_associated_function (|
                                                                                                    Ty.path
                                                                                                      "move_bytecode_verifier::loop_summary::LoopSummary",
                                                                                                    "is_descendant",
                                                                                                    []
                                                                                                  |),
                                                                                                  [
                                                                                                    summary;
                                                                                                    M.read (|
                                                                                                      head
                                                                                                    |);
                                                                                                    M.read (|
                                                                                                      pred
                                                                                                    |)
                                                                                                  ]
                                                                                                |)
                                                                                              |)
                                                                                            |)) in
                                                                                        let _ :=
                                                                                          M.is_constant_or_break_match (|
                                                                                            M.read (|
                                                                                              γ
                                                                                            |),
                                                                                            Value.Bool
                                                                                              true
                                                                                          |) in
                                                                                        M.alloc (|
                                                                                          M.never_to_any (|
                                                                                            M.read (|
                                                                                              M.return_ (|
                                                                                                M.call_closure (|
                                                                                                  M.get_trait_method (|
                                                                                                    "core::ops::function::Fn",
                                                                                                    Ty.function
                                                                                                      [
                                                                                                        Ty.tuple
                                                                                                          [
                                                                                                            Ty.path
                                                                                                              "move_core_types::vm_status::StatusCode";
                                                                                                            Ty.path
                                                                                                              "u16"
                                                                                                          ]
                                                                                                      ]
                                                                                                      (Ty.apply
                                                                                                        (Ty.path
                                                                                                          "core::result::Result")
                                                                                                        []
                                                                                                        [
                                                                                                          Ty.tuple
                                                                                                            [];
                                                                                                          Ty.path
                                                                                                            "move_binary_format::errors::PartialVMError"
                                                                                                        ]),
                                                                                                    [
                                                                                                      Ty.tuple
                                                                                                        [
                                                                                                          Ty.path
                                                                                                            "move_core_types::vm_status::StatusCode";
                                                                                                          Ty.path
                                                                                                            "u16"
                                                                                                        ]
                                                                                                    ],
                                                                                                    "call",
                                                                                                    []
                                                                                                  |),
                                                                                                  [
                                                                                                    err;
                                                                                                    Value.Tuple
                                                                                                      [
                                                                                                        Value.StructTuple
                                                                                                          "move_core_types::vm_status::StatusCode::INVALID_LOOP_SPLIT"
                                                                                                          [];
                                                                                                        M.call_closure (|
                                                                                                          M.get_associated_function (|
                                                                                                            Ty.path
                                                                                                              "move_bytecode_verifier::loop_summary::LoopSummary",
                                                                                                            "block",
                                                                                                            []
                                                                                                          |),
                                                                                                          [
                                                                                                            summary;
                                                                                                            M.read (|
                                                                                                              pred
                                                                                                            |)
                                                                                                          ]
                                                                                                        |)
                                                                                                      ]
                                                                                                  ]
                                                                                                |)
                                                                                              |)
                                                                                            |)
                                                                                          |)
                                                                                        |)));
                                                                                    fun γ =>
                                                                                      ltac:(M.monadic
                                                                                        (M.alloc (|
                                                                                          Value.Tuple
                                                                                            []
                                                                                        |)))
                                                                                  ]
                                                                                |) in
                                                                              let~ body_extended :=
                                                                                M.alloc (|
                                                                                  LogicalOp.and (|
                                                                                    M.call_closure (|
                                                                                      M.get_trait_method (|
                                                                                        "core::cmp::PartialEq",
                                                                                        Ty.path
                                                                                          "move_bytecode_verifier::loop_summary::NodeId",
                                                                                        [
                                                                                          Ty.path
                                                                                            "move_bytecode_verifier::loop_summary::NodeId"
                                                                                        ],
                                                                                        "ne",
                                                                                        []
                                                                                      |),
                                                                                      [ pred; head ]
                                                                                    |),
                                                                                    ltac:(M.monadic
                                                                                      (M.call_closure (|
                                                                                        M.get_associated_function (|
                                                                                          Ty.apply
                                                                                            (Ty.path
                                                                                              "alloc::collections::btree::set::BTreeSet")
                                                                                            []
                                                                                            [
                                                                                              Ty.path
                                                                                                "move_bytecode_verifier::loop_summary::NodeId";
                                                                                              Ty.path
                                                                                                "alloc::alloc::Global"
                                                                                            ],
                                                                                          "insert",
                                                                                          []
                                                                                        |),
                                                                                        [
                                                                                          body;
                                                                                          M.read (|
                                                                                            pred
                                                                                          |)
                                                                                        ]
                                                                                      |)))
                                                                                  |)
                                                                                |) in
                                                                              M.match_operator (|
                                                                                M.alloc (|
                                                                                  Value.Tuple []
                                                                                |),
                                                                                [
                                                                                  fun γ =>
                                                                                    ltac:(M.monadic
                                                                                      (let γ :=
                                                                                        M.use
                                                                                          body_extended in
                                                                                      let _ :=
                                                                                        M.is_constant_or_break_match (|
                                                                                          M.read (|
                                                                                            γ
                                                                                          |),
                                                                                          Value.Bool
                                                                                            true
                                                                                        |) in
                                                                                      let~ _ :=
                                                                                        M.alloc (|
                                                                                          M.call_closure (|
                                                                                            M.get_associated_function (|
                                                                                              Ty.apply
                                                                                                (Ty.path
                                                                                                  "alloc::vec::Vec")
                                                                                                []
                                                                                                [
                                                                                                  Ty.path
                                                                                                    "move_bytecode_verifier::loop_summary::NodeId";
                                                                                                  Ty.path
                                                                                                    "alloc::alloc::Global"
                                                                                                ],
                                                                                              "push",
                                                                                              []
                                                                                            |),
                                                                                            [
                                                                                              frontier;
                                                                                              M.read (|
                                                                                                pred
                                                                                              |)
                                                                                            ]
                                                                                          |)
                                                                                        |) in
                                                                                      M.alloc (|
                                                                                        Value.Tuple
                                                                                          []
                                                                                      |)));
                                                                                  fun γ =>
                                                                                    ltac:(M.monadic
                                                                                      (M.alloc (|
                                                                                        Value.Tuple
                                                                                          []
                                                                                      |)))
                                                                                ]
                                                                              |)))
                                                                        ]
                                                                      |) in
                                                                    M.alloc (| Value.Tuple [] |)))
                                                                |)))
                                                          ]
                                                        |))));
                                                  fun γ =>
                                                    ltac:(M.monadic
                                                      (M.alloc (|
                                                        M.never_to_any (|
                                                          M.read (|
                                                            let~ _ :=
                                                              M.alloc (|
                                                                M.never_to_any (|
                                                                  M.read (| M.break (||) |)
                                                                |)
                                                              |) in
                                                            M.alloc (| Value.Tuple [] |)
                                                          |)
                                                        |)
                                                      |)))
                                                ]
                                              |)))
                                          |) in
                                        let~ depth :=
                                          M.alloc (|
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.path
                                                  "move_bytecode_verifier::loop_summary::LoopPartition",
                                                "collapse_loop",
                                                []
                                              |),
                                              [ partition; M.read (| head |); body ]
                                            |)
                                          |) in
                                        M.match_operator (|
                                          M.alloc (| Value.Tuple [] |),
                                          [
                                            fun γ =>
                                              ltac:(M.monadic
                                                (let γ :=
                                                  M.SubPointer.get_struct_record_field (|
                                                    M.read (| verifier_config |),
                                                    "move_vm_config::verifier::VerifierConfig",
                                                    "max_loop_depth"
                                                  |) in
                                                let γ0_0 :=
                                                  M.SubPointer.get_struct_tuple_field (|
                                                    γ,
                                                    "core::option::Option::Some",
                                                    0
                                                  |) in
                                                let max_depth := M.copy (| γ0_0 |) in
                                                M.match_operator (|
                                                  M.alloc (| Value.Tuple [] |),
                                                  [
                                                    fun γ =>
                                                      ltac:(M.monadic
                                                        (let γ :=
                                                          M.use
                                                            (M.alloc (|
                                                              BinOp.gt (|
                                                                M.rust_cast (M.read (| depth |)),
                                                                M.read (| max_depth |)
                                                              |)
                                                            |)) in
                                                        let _ :=
                                                          M.is_constant_or_break_match (|
                                                            M.read (| γ |),
                                                            Value.Bool true
                                                          |) in
                                                        M.alloc (|
                                                          M.never_to_any (|
                                                            M.read (|
                                                              M.return_ (|
                                                                M.call_closure (|
                                                                  M.get_trait_method (|
                                                                    "core::ops::function::Fn",
                                                                    Ty.function
                                                                      [
                                                                        Ty.tuple
                                                                          [
                                                                            Ty.path
                                                                              "move_core_types::vm_status::StatusCode";
                                                                            Ty.path "u16"
                                                                          ]
                                                                      ]
                                                                      (Ty.apply
                                                                        (Ty.path
                                                                          "core::result::Result")
                                                                        []
                                                                        [
                                                                          Ty.tuple [];
                                                                          Ty.path
                                                                            "move_binary_format::errors::PartialVMError"
                                                                        ]),
                                                                    [
                                                                      Ty.tuple
                                                                        [
                                                                          Ty.path
                                                                            "move_core_types::vm_status::StatusCode";
                                                                          Ty.path "u16"
                                                                        ]
                                                                    ],
                                                                    "call",
                                                                    []
                                                                  |),
                                                                  [
                                                                    err;
                                                                    Value.Tuple
                                                                      [
                                                                        Value.StructTuple
                                                                          "move_core_types::vm_status::StatusCode::LOOP_MAX_DEPTH_REACHED"
                                                                          [];
                                                                        M.call_closure (|
                                                                          M.get_associated_function (|
                                                                            Ty.path
                                                                              "move_bytecode_verifier::loop_summary::LoopSummary",
                                                                            "block",
                                                                            []
                                                                          |),
                                                                          [
                                                                            summary;
                                                                            M.read (| head |)
                                                                          ]
                                                                        |)
                                                                      ]
                                                                  ]
                                                                |)
                                                              |)
                                                            |)
                                                          |)
                                                        |)));
                                                    fun γ =>
                                                      ltac:(M.monadic
                                                        (M.alloc (| Value.Tuple [] |)))
                                                  ]
                                                |)));
                                            fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                                          ]
                                        |)))
                                  ]
                                |) in
                              M.alloc (| Value.Tuple [] |)))
                          |)))
                    ]
                  |)) in
              M.alloc (| Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] |)
            |)))
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Function_verify_reducibility :
    M.IsFunction "move_bytecode_verifier::control_flow::verify_reducibility" verify_reducibility.
End control_flow.
