program main
  enum Signal
    variant Red
    variant Yellow
    variant Green
  enum Reading
    variant Missing
    variant Value i32
  struct Point
    field x: i32
    field y: i32
  struct PrimitiveRecord
    field id: i32
    field active: bool
    field label: string
  struct NumericRecord
    field wide: i64
    field ratio: f64
  struct TaggedReading
    field status: Signal
    field reading: Reading
  fn make_point(x: i32, y: i32) -> Point
    construct Point : Point
      field x
        var x : i32
      field y
        var y : i32
  fn make_primitive_record(id: i32, label: string) -> PrimitiveRecord
    construct PrimitiveRecord : PrimitiveRecord
      field id
        var id : i32
      field active
        binary = : bool
          var id : i32
          int 7 : i32
      field label
        var label : string
  fn make_numeric_record(wide: i64, ratio: f64) -> NumericRecord
    construct NumericRecord : NumericRecord
      field wide
        var wide : i64
      field ratio
        var ratio : f64
  fn make_tagged(status: Signal, reading: Reading) -> TaggedReading
    construct TaggedReading : TaggedReading
      field status
        var status : Signal
      field reading
        var reading : Reading
  fn vec_i32_pair(base: i32) -> (vec i32)
    local let values : unit
      call std.vec.i32.empty : (vec i32)
    local let first : unit
      call std.vec.i32.append : (vec i32)
        var values : (vec i32)
        var base : i32
    call std.vec.i32.append : (vec i32)
      var first : (vec i32)
      binary + : i32
        var base : i32
        int 1 : i32
  fn vec_i64_pair(base: i64) -> (vec i64)
    local let values : unit
      call std.vec.i64.empty : (vec i64)
    local let first : unit
      call std.vec.i64.append : (vec i64)
        var values : (vec i64)
        var base : i64
    call std.vec.i64.append : (vec i64)
      var first : (vec i64)
      binary + : i64
        var base : i64
        i64 1 : i64
  fn vec_f64_pair(base: f64) -> (vec f64)
    local let values : unit
      call std.vec.f64.empty : (vec f64)
    local let first : unit
      call std.vec.f64.append : (vec f64)
        var values : (vec f64)
        var base : f64
    call std.vec.f64.append : (vec f64)
      var first : (vec f64)
      binary + : f64
        var base : f64
        float 1 : f64
  fn vec_bool_pair(first: bool, second: bool) -> (vec bool)
    local let values : unit
      call std.vec.bool.empty : (vec bool)
    local let left : unit
      call std.vec.bool.append : (vec bool)
        var values : (vec bool)
        var first : bool
    call std.vec.bool.append : (vec bool)
      var left : (vec bool)
      var second : bool
  fn vec_string_pair(first: string, second: string) -> (vec string)
    local let values : unit
      call std.vec.string.empty : (vec string)
    local let left : unit
      call std.vec.string.append : (vec string)
        var values : (vec string)
        var first : string
    call std.vec.string.append : (vec string)
      var left : (vec string)
      var second : string
  fn swap_string(first: string, second: string) -> string
    local var current : unit
      var first : string
    set current : unit
      var second : string
    var current : string
  fn vec_i32_local_value() -> i32
    local var current : unit
      call vec_i32_pair : (vec i32)
        int 10 : i32
    set current : unit
      call vec_i32_pair : (vec i32)
        int 40 : i32
    call std.vec.i32.index : i32
      var current : (vec i32)
      int 1 : i32
  fn vec_i64_local_value() -> i64
    local var current : unit
      call vec_i64_pair : (vec i64)
        i64 10 : i64
    set current : unit
      call vec_i64_pair : (vec i64)
        i64 40 : i64
    call std.vec.i64.index : i64
      var current : (vec i64)
      int 1 : i32
  fn vec_f64_local_value() -> f64
    local var current : unit
      call vec_f64_pair : (vec f64)
        float 10 : f64
    set current : unit
      call vec_f64_pair : (vec f64)
        float 40 : f64
    call std.vec.f64.index : f64
      var current : (vec f64)
      int 1 : i32
  fn vec_bool_local_value() -> bool
    local var current : unit
      call vec_bool_pair : (vec bool)
        bool true : bool
        bool false : bool
    set current : unit
      call vec_bool_pair : (vec bool)
        bool false : bool
        bool true : bool
    call std.vec.bool.index : bool
      var current : (vec bool)
      int 1 : i32
  fn vec_string_local_value() -> string
    local var current : unit
      call vec_string_pair : (vec string)
        string "oak" : string
        string "elm" : string
    set current : unit
      call vec_string_pair : (vec string)
        string "pine" : string
        string "slovo" : string
    call std.vec.string.index : string
      var current : (vec string)
      int 1 : i32
  fn option_i32_local_value() -> i32
    local var current : unit
      none : (option i32)
    set current : unit
      some : (option i32)
        int 42 : i32
    match : i32
      subject
        var current : (option i32)
      arm some payload
        var payload : i32
      arm none
        int 0 : i32
  fn option_i64_local_value() -> i64
    local var current : unit
      none : (option i64)
    set current : unit
      some : (option i64)
        i64 42000000000 : i64
    match : i64
      subject
        var current : (option i64)
      arm some payload
        var payload : i64
      arm none
        i64 0 : i64
  fn option_f64_local_value() -> f64
    local var current : unit
      none : (option f64)
    set current : unit
      some : (option f64)
        float 42.5 : f64
    match : f64
      subject
        var current : (option f64)
      arm some payload
        var payload : f64
      arm none
        float 0 : f64
  fn option_bool_local_value() -> bool
    local var current : unit
      none : (option bool)
    set current : unit
      some : (option bool)
        bool true : bool
    match : bool
      subject
        var current : (option bool)
      arm some payload
        var payload : bool
      arm none
        bool false : bool
  fn option_string_local_value() -> string
    local var current : unit
      none : (option string)
    set current : unit
      some : (option string)
        string "branch" : string
    match : string
      subject
        var current : (option string)
      arm some payload
        var payload : string
      arm none
        string "fallback" : string
  fn result_i32_local_value() -> i32
    local var current : unit
      err : (result i32 i32)
        int 7 : i32
    set current : unit
      ok : (result i32 i32)
        int 42 : i32
    match : i32
      subject
        var current : (result i32 i32)
      arm ok payload
        var payload : i32
      arm err code
        var code : i32
  fn result_i64_local_value() -> i64
    local var current : unit
      err : (result i64 i32)
        int 7 : i32
    set current : unit
      ok : (result i64 i32)
        i64 42000000000 : i64
    match : i64
      subject
        var current : (result i64 i32)
      arm ok payload
        var payload : i64
      arm err code
        i64 0 : i64
  fn result_f64_local_value() -> f64
    local var current : unit
      err : (result f64 i32)
        int 7 : i32
    set current : unit
      ok : (result f64 i32)
        float 42.5 : f64
    match : f64
      subject
        var current : (result f64 i32)
      arm ok payload
        var payload : f64
      arm err code
        float 0 : f64
  fn result_bool_local_value() -> bool
    local var current : unit
      err : (result bool i32)
        int 7 : i32
    set current : unit
      ok : (result bool i32)
        bool true : bool
    match : bool
      subject
        var current : (result bool i32)
      arm ok payload
        var payload : bool
      arm err code
        bool false : bool
  fn result_string_local_value() -> string
    local var current : unit
      err : (result string i32)
        int 7 : i32
    set current : unit
      ok : (result string i32)
        string "slovo" : string
    match : string
      subject
        var current : (result string i32)
      arm ok payload
        var payload : string
      arm err code
        string "fallback" : string
  fn point_local_sum() -> i32
    local var current : unit
      call make_point : Point
        int 1 : i32
        int 2 : i32
    set current : unit
      call make_point : Point
        int 20 : i32
        int 22 : i32
    binary + : i32
      field-access x : i32
        var current : Point
      field-access y : i32
        var current : Point
  fn primitive_record_local_label() -> string
    local var current : unit
      call make_primitive_record : PrimitiveRecord
        int 3 : i32
        string "alpha" : string
    set current : unit
      call make_primitive_record : PrimitiveRecord
        int 7 : i32
        string "beta" : string
    field-access label : string
      var current : PrimitiveRecord
  fn numeric_record_local_ratio() -> f64
    local var current : unit
      call make_numeric_record : NumericRecord
        i64 10 : i64
        float 1 : f64
    set current : unit
      call make_numeric_record : NumericRecord
        i64 20 : i64
        float 3.5 : f64
    field-access ratio : f64
      var current : NumericRecord
  fn signal_local_code() -> i32
    local var current : unit
      enum-variant Signal.Red #0 : Signal
    set current : unit
      enum-variant Signal.Green #2 : Signal
    match : i32
      subject
        var current : Signal
      arm Signal.Red
        int 1 : i32
      arm Signal.Yellow
        int 2 : i32
      arm Signal.Green
        int 3 : i32
  fn reading_local_code() -> i32
    local var current : unit
      enum-variant Reading.Missing #0 : Reading
    set current : unit
      enum-variant Reading.Value #1 payload : Reading
        int 42 : i32
    match : i32
      subject
        var current : Reading
      arm Reading.Missing
        int 0 : i32
      arm Reading.Value payload
        var payload : i32
  fn tagged_local_code() -> i32
    local var current : unit
      call make_tagged : TaggedReading
        enum-variant Signal.Yellow #1 : Signal
        enum-variant Reading.Missing #0 : Reading
    set current : unit
      call make_tagged : TaggedReading
        enum-variant Signal.Green #2 : Signal
        enum-variant Reading.Value #1 payload : Reading
          int 42 : i32
    match : i32
      subject
        field-access reading : Reading
          var current : TaggedReading
      arm Reading.Missing
        int 0 : i32
      arm Reading.Value payload
        var payload : i32
  fn main() -> i32
    call tagged_local_code : i32
  test "mutable string local set works"
    binary = : bool
      call swap_string : string
        string "oak" : string
        string "slovo" : string
      string "slovo" : string
  test "mutable vec i32 local set works"
    binary = : bool
      call vec_i32_local_value : i32
      int 41 : i32
  test "mutable vec i64 local set works"
    binary = : bool
      call vec_i64_local_value : i64
      i64 41 : i64
  test "mutable vec f64 local set works"
    binary = : bool
      call vec_f64_local_value : f64
      float 41 : f64
  test "mutable vec bool local set works"
    call vec_bool_local_value : bool
  test "mutable vec string local set works"
    binary = : bool
      call vec_string_local_value : string
      string "slovo" : string
  test "mutable option i32 local set works"
    binary = : bool
      call option_i32_local_value : i32
      int 42 : i32
  test "mutable option i64 local set works"
    binary = : bool
      call option_i64_local_value : i64
      i64 42000000000 : i64
  test "mutable option f64 local set works"
    binary = : bool
      call option_f64_local_value : f64
      float 42.5 : f64
  test "mutable option bool local set works"
    call option_bool_local_value : bool
  test "mutable option string local set works"
    binary = : bool
      call option_string_local_value : string
      string "branch" : string
  test "mutable result i32 local set works"
    binary = : bool
      call result_i32_local_value : i32
      int 42 : i32
  test "mutable result i64 local set works"
    binary = : bool
      call result_i64_local_value : i64
      i64 42000000000 : i64
  test "mutable result f64 local set works"
    binary = : bool
      call result_f64_local_value : f64
      float 42.5 : f64
  test "mutable result bool local set works"
    call result_bool_local_value : bool
  test "mutable result string local set works"
    binary = : bool
      call result_string_local_value : string
      string "slovo" : string
  test "mutable plain struct local set works"
    binary = : bool
      call point_local_sum : i32
      int 42 : i32
  test "mutable primitive struct local set works"
    binary = : bool
      call primitive_record_local_label : string
      string "beta" : string
  test "mutable numeric struct local set works"
    binary = : bool
      call numeric_record_local_ratio : f64
      float 3.5 : f64
  test "mutable payloadless enum local set works"
    binary = : bool
      call signal_local_code : i32
      int 3 : i32
  test "mutable payload enum local set works"
    binary = : bool
      call reading_local_code : i32
      int 42 : i32
  test "mutable enum struct local set works"
    binary = : bool
      call tagged_local_code : i32
      int 42 : i32
