//! > Test loop.

//! > test_runner_name
test_generated_function

//! > function
fn foo(y: felt252) -> felt252 {
    let mut x = 5;
    while x != 0 {
        x = x - 1;
    };
    x
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- 5u
  (v3: core::felt252, v2: ()) <- test::foo[expr12](v1)
End:
  Return(v3)


Final lowering:
Parameters: v12: core::RangeCheck, v13: core::gas::GasBuiltin, v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- 5u
  (v14: core::RangeCheck, v15: core::gas::GasBuiltin, v4: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[expr12](v12, v13, v1)
End:
  Match(match_enum(v4) {
    PanicResult::Ok(v5) => blk1,
    PanicResult::Err(v8) => blk2,
  })

blk1:
Statements:
  (v6: core::felt252, v7: ()) <- struct_destructure(v5)
  (v9: (core::felt252,)) <- struct_construct(v6)
  (v10: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v9)
End:
  Return(v14, v15, v10)

blk2:
Statements:
  (v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v8)
End:
  Return(v14, v15, v11)


Generated lowering for source location:
    while x != 0 {
    ^************^

Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252, v2: @core::felt252) <- snapshot(v0)
  (v3: core::felt252) <- 0u
  (v4: core::felt252, v5: @core::felt252) <- snapshot(v3)
  (v6: core::bool) <- core::Felt252PartialEq::ne(v2, v5)
End:
  Match(match_enum(v6) {
    bool::False(v12) => blk2,
    bool::True(v7) => blk1,
  })

blk1:
Statements:
  (v8: core::felt252) <- 1u
  (v9: core::felt252) <- core::Felt252Sub::sub(v1, v8)
  (v11: core::felt252, v10: ()) <- test::foo[expr12](v9)
End:
  Goto(blk3, {v11 -> v14, v10 -> v13})

blk2:
Statements:
  (v15: ()) <- struct_construct()
End:
  Goto(blk3, {v1 -> v14, v15 -> v13})

blk3:
Statements:
End:
  Return(v14, v13)


Final lowering:
Parameters: v50: core::RangeCheck, v51: core::gas::GasBuiltin, v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v50, v51) {
    Option::Some(v52, v53) => blk1,
    Option::None(v54, v55) => blk7,
  })

blk1:
Statements:
  (v1: core::felt252, v2: @core::felt252) <- snapshot(v0)
  (v16: core::felt252) <- desnap(v2)
  (v17: core::felt252, v18: @core::felt252) <- snapshot(v16)
  (v25: core::felt252) <- desnap(v18)
End:
  Match(match core::felt252_is_zero(v25) {
    IsZeroResult::Zero => blk2,
    IsZeroResult::NonZero(v28) => blk3,
  })

blk2:
Statements:
  (v15: ()) <- struct_construct()
End:
  Goto(blk5, {v52 -> v66, v53 -> v67, v1 -> v14, v15 -> v13})

blk3:
Statements:
  (v8: core::felt252) <- 1u
  (v24: core::felt252) <- core::felt252_sub(v1, v8)
  (v74: core::RangeCheck, v75: core::gas::GasBuiltin, v43: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[expr12](v52, v53, v24)
End:
  Match(match_enum(v43) {
    PanicResult::Ok(v44) => blk4,
    PanicResult::Err(v47) => blk6,
  })

blk4:
Statements:
  (v45: core::felt252, v46: ()) <- struct_destructure(v44)
End:
  Goto(blk5, {v74 -> v66, v75 -> v67, v45 -> v14, v46 -> v13})

blk5:
Statements:
  (v41: (core::felt252, ())) <- struct_construct(v14, v13)
  (v42: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Ok(v41)
End:
  Return(v66, v67, v42)

blk6:
Statements:
  (v49: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Err(v47)
End:
  Return(v74, v75, v49)

blk7:
Statements:
  (v36: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v37: core::felt252) <- 375233589013918064796019u
  (v39: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v36, v37)
  (v38: core::panics::Panic) <- struct_construct()
  (v40: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v38, v39)
  (v48: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Err(v40)
End:
  Return(v54, v55, v48)
