//! > Test loop.

//! > test_runner_name
test_generated_function

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

//! > function_name
foo

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

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


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::felt252
blk0 (root):
Statements:
  (v3: core::RangeCheck, v4: core::gas::GasBuiltin, v5: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[51-95]{5, }(v0, v1)
End:
  Match(match_enum(v5) {
    PanicResult::Ok(v6) => blk1,
    PanicResult::Err(v7) => blk2,
  })

blk1:
Statements:
  (v8: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v4)
  (v9: core::felt252, v10: ()) <- struct_destructure(v6)
  (v11: (core::felt252,)) <- struct_construct(v9)
  (v12: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v11)
End:
  Return(v3, v8, v12)

blk2:
Statements:
  (v13: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v7)
End:
  Return(v3, v4, v13)


Generated loop lowering for source location:
      while x != 0 {
 _____^
|         x = x - 1;
|     }
|_____^

Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252, v2: @core::felt252) <- snapshot(v0)
  (v3: core::felt252) <- 0
  (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) <- 1
  (v9: core::felt252) <- core::Felt252Sub::sub(v1, v8)
  (v11: core::felt252, v10: ()) <- test::foo[51-95](v9)
End:
  Return(v11, v10)

blk2:
Statements:
  (v13: ()) <- struct_construct()
End:
  Return(v1, v13)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v3, v4) => blk1,
    Option::None(v5, v6) => blk4,
  })

blk1:
Statements:
End:
  Match(match core::felt252_is_zero(v2) {
    IsZeroResult::Zero => blk2,
    IsZeroResult::NonZero(v7) => blk3,
  })

blk2:
Statements:
  (v8: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v4)
  (v9: ()) <- struct_construct()
  (v10: (core::felt252, ())) <- struct_construct(v2, v9)
  (v11: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Ok(v10)
End:
  Return(v3, v8, v11)

blk3:
Statements:
  (v12: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v4)
  (v13: core::felt252) <- 1
  (v14: core::felt252) <- core::felt252_sub(v2, v13)
  (v15: core::RangeCheck, v16: core::gas::GasBuiltin, v17: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[51-95](v3, v12, v14)
End:
  Return(v15, v16, v17)

blk4:
Statements:
  (v18: (core::panics::Panic, core::array::Array::<core::felt252>)) <- core::panic_with_const_felt252::<375233589013918064796019>()
  (v19: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Err(v18)
End:
  Return(v5, v6, v19)


Final lowering of specialized call "test::foo[51-95]{5, }":
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v2, v3) => blk1,
    Option::None(v4, v5) => blk2,
  })

blk1:
Statements:
  (v6: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v3)
  (v7: core::felt252) <- 4
  (v8: core::RangeCheck, v9: core::gas::GasBuiltin, v10: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[51-95](v2, v6, v7)
End:
  Return(v8, v9, v10)

blk2:
Statements:
  (v11: (core::panics::Panic, core::array::Array::<core::felt252>)) <- core::panic_with_const_felt252::<375233589013918064796019>()
  (v12: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Err(v11)
End:
  Return(v4, v5, v12)

//! > ==========================================================================

//! > Test while-let.

//! > test_runner_name
test_generated_function

//! > function_code
fn foo(ref arr: Array<felt252>, mut x: felt252) -> felt252 {
    while let true = (x != 0) {
        x = x - 1;
        break;
    }
    x
}

//! > function_name
foo

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters: v0: core::array::Array::<core::felt252>, v1: core::felt252
blk0 (root):
Statements:
  (v3: core::felt252, v2: ()) <- test::foo[61-133](v1)
End:
  Return(v0, v3)


Final lowering:
Parameters: v0: core::array::Array::<core::felt252>, v1: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::felt252_is_zero(v1) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v2) => blk2,
  })

blk1:
Statements:
End:
  Return(v0, v1)

blk2:
Statements:
  (v3: core::felt252) <- 1
  (v4: core::felt252) <- core::felt252_sub(v1, v3)
End:
  Return(v0, v4)


Generated loop lowering for source location:
      while let true = (x != 0) {
 _____^
| ...
|     }
|_____^

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

blk1:
Statements:
End:
  Goto(blk3, {})

blk2:
Statements:
  (v9: core::felt252) <- 1
  (v10: core::felt252) <- core::Felt252Sub::sub(v1, v9)
  (v11: ()) <- struct_construct()
End:
  Return(v10, v11)

blk3:
Statements:
  (v12: ()) <- struct_construct()
End:
  Return(v1, v12)


Final lowering:
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v1) => blk2,
  })

blk1:
Statements:
End:
  Return(v0)

blk2:
Statements:
  (v2: core::felt252) <- 1
  (v3: core::felt252) <- core::felt252_sub(v0, v2)
End:
  Return(v3)

//! > ==========================================================================

//! > Test while-let extern enum.

//! > test_runner_name
test_generated_function

//! > function_code
fn foo() -> felt252 {
    let mut y = 0;
    while let MyEnum::A(x) = a() {
        y = y + x
    }
    y = y + 1;
    return y;
}

//! > function_name
foo

//! > module_code
enum MyEnum {
    A: felt252,
    B,
    C,
}
extern fn a() -> MyEnum nopanic;

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 0
  (v2: core::felt252, v1: ()) <- test::foo[41-100](v0)
  (v3: core::felt252) <- 1
  (v4: core::felt252) <- core::Felt252Add::add(v2, v3)
End:
  Return(v4)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
  (v2: core::RangeCheck, v3: core::gas::GasBuiltin, v4: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[41-100]{0, }(v0, v1)
End:
  Match(match_enum(v4) {
    PanicResult::Ok(v5) => blk1,
    PanicResult::Err(v6) => blk2,
  })

blk1:
Statements:
  (v7: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v3)
  (v8: core::felt252, v9: ()) <- struct_destructure(v5)
  (v10: core::felt252) <- 1
  (v11: core::felt252) <- core::felt252_add(v8, v10)
  (v12: (core::felt252,)) <- struct_construct(v11)
  (v13: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v12)
End:
  Return(v2, v7, v13)

blk2:
Statements:
  (v14: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v6)
End:
  Return(v2, v3, v14)


Generated loop lowering for source location:
      while let MyEnum::A(x) = a() {
 _____^
|         y = y + x
|     }
|_____^

Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match test::a() {
    MyEnum::A(v1) => blk1,
    MyEnum::B => blk2,
    MyEnum::C => blk3,
  })

blk1:
Statements:
  (v4: core::felt252) <- core::Felt252Add::add(v0, v1)
  (v6: core::felt252, v5: ()) <- test::foo[41-100](v4)
End:
  Return(v6, v5)

blk2:
Statements:
  (v2: ()) <- struct_construct()
End:
  Goto(blk4, {})

blk3:
Statements:
  (v3: ()) <- struct_construct()
End:
  Goto(blk4, {})

blk4:
Statements:
End:
  Goto(blk5, {})

blk5:
Statements:
  (v7: ()) <- struct_construct()
End:
  Return(v0, v7)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v3, v4) => blk1,
    Option::None(v5, v6) => blk6,
  })

blk1:
Statements:
End:
  Match(match test::a() {
    MyEnum::A(v7) => blk2,
    MyEnum::B => blk3,
    MyEnum::C => blk4,
  })

blk2:
Statements:
  (v8: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v4)
  (v9: core::felt252) <- core::felt252_add(v2, v7)
  (v10: core::RangeCheck, v11: core::gas::GasBuiltin, v12: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[41-100](v3, v8, v9)
End:
  Return(v10, v11, v12)

blk3:
Statements:
  (v13: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v4)
End:
  Goto(blk5, {v13 -> v14})

blk4:
Statements:
  (v15: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v4)
End:
  Goto(blk5, {v15 -> v14})

blk5:
Statements:
  (v16: ()) <- struct_construct()
  (v17: (core::felt252, ())) <- struct_construct(v2, v16)
  (v18: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Ok(v17)
End:
  Return(v3, v14, v18)

blk6:
Statements:
  (v19: (core::panics::Panic, core::array::Array::<core::felt252>)) <- core::panic_with_const_felt252::<375233589013918064796019>()
  (v20: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Err(v19)
End:
  Return(v5, v6, v20)


Final lowering of specialized call "test::foo[41-100]{0, }":
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v2, v3) => blk1,
    Option::None(v4, v5) => blk6,
  })

blk1:
Statements:
  (v6: core::felt252) <- 0
End:
  Match(match test::a() {
    MyEnum::A(v7) => blk2,
    MyEnum::B => blk3,
    MyEnum::C => blk4,
  })

blk2:
Statements:
  (v8: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v3)
  (v9: core::RangeCheck, v10: core::gas::GasBuiltin, v11: core::panics::PanicResult::<(core::felt252, ())>) <- test::foo[41-100](v2, v8, v7)
End:
  Return(v9, v10, v11)

blk3:
Statements:
  (v12: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v3)
End:
  Goto(blk5, {v12 -> v13})

blk4:
Statements:
  (v14: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v3)
End:
  Goto(blk5, {v14 -> v13})

blk5:
Statements:
  (v15: ()) <- struct_construct()
  (v16: (core::felt252, ())) <- struct_construct(v6, v15)
  (v17: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Ok(v16)
End:
  Return(v2, v13, v17)

blk6:
Statements:
  (v18: (core::panics::Panic, core::array::Array::<core::felt252>)) <- core::panic_with_const_felt252::<375233589013918064796019>()
  (v19: core::panics::PanicResult::<(core::felt252, ())>) <- PanicResult::Err(v18)
End:
  Return(v4, v5, v19)
