program main
  enum Status
    variant Ready
    variant Blocked
  struct Pair
    field left: i32
    field right: i32
  struct CompositeRecord
    field ints: (vec i32)
    field wides: (vec i64)
    field ratios: (vec f64)
    field flags: (vec bool)
    field labels: (vec string)
    field maybe_count: (option i32)
    field maybe_wide: (option i64)
    field maybe_ratio: (option f64)
    field maybe_flag: (option bool)
    field maybe_label: (option string)
    field count_result: (result i32 i32)
    field wide_result: (result i64 i32)
    field ratio_result: (result f64 i32)
    field flag_result: (result bool i32)
    field label_result: (result string i32)
    field pair: Pair
    field status: Status
  fn make_pair(left: i32, right: i32) -> Pair
    construct Pair
      field left
        var left
      field right
        var right
  fn vec_i32_pair(base: i32) -> (vec i32)
    local let values: (vec i32)
      call std.vec.i32.empty
    local let first: (vec i32)
      call std.vec.i32.append
        var values
        var base
    call std.vec.i32.append
      var first
      binary +
        var base
        int 1
  fn vec_i64_pair(base: i64) -> (vec i64)
    local let values: (vec i64)
      call std.vec.i64.empty
    local let first: (vec i64)
      call std.vec.i64.append
        var values
        var base
    call std.vec.i64.append
      var first
      binary +
        var base
        i64 1
  fn vec_f64_pair(base: f64) -> (vec f64)
    local let values: (vec f64)
      call std.vec.f64.empty
    local let first: (vec f64)
      call std.vec.f64.append
        var values
        var base
    call std.vec.f64.append
      var first
      binary +
        var base
        float 1
  fn vec_bool_pair(first: bool, second: bool) -> (vec bool)
    local let values: (vec bool)
      call std.vec.bool.empty
    local let left: (vec bool)
      call std.vec.bool.append
        var values
        var first
    call std.vec.bool.append
      var left
      var second
  fn vec_string_pair(first: string, second: string) -> (vec string)
    local let values: (vec string)
      call std.vec.string.empty
    local let left: (vec string)
      call std.vec.string.append
        var values
        var first
    call std.vec.string.append
      var left
      var second
  fn make_record() -> CompositeRecord
    construct CompositeRecord
      field ints
        call vec_i32_pair
          int 10
      field wides
        call vec_i64_pair
          i64 100
      field ratios
        call vec_f64_pair
          float 3.5
      field flags
        call vec_bool_pair
          bool false
          bool true
      field labels
        call vec_string_pair
          string "oak"
          string "elm"
      field maybe_count
        some i32
          int 7
      field maybe_wide
        some i64
          i64 7000000000
      field maybe_ratio
        some f64
          float 7.5
      field maybe_flag
        some bool
          bool true
      field maybe_label
        some string
          string "alpha"
      field count_result
        ok i32 i32
          int 9
      field wide_result
        ok i64 i32
          i64 9000000000
      field ratio_result
        ok f64 i32
          float 9.25
      field flag_result
        ok bool i32
          bool true
      field label_result
        ok string i32
          string "beta"
      field pair
        call make_pair
          int 20
          int 22
      field status
        enum-variant Status.Ready
  fn echo_record(record: CompositeRecord) -> CompositeRecord
    var record
  fn local_record() -> CompositeRecord
    local let record: CompositeRecord
      call make_record
    call echo_record
      var record
  fn ints_second(record: CompositeRecord) -> i32
    call std.vec.i32.index
      field-access ints
        var record
      int 1
  fn wides_second(record: CompositeRecord) -> i64
    call std.vec.i64.index
      field-access wides
        var record
      int 1
  fn ratios_second(record: CompositeRecord) -> f64
    call std.vec.f64.index
      field-access ratios
        var record
      int 1
  fn flags_second(record: CompositeRecord) -> bool
    call std.vec.bool.index
      field-access flags
        var record
      int 1
  fn labels_second(record: CompositeRecord) -> string
    call std.vec.string.index
      field-access labels
        var record
      int 1
  fn maybe_count_value(record: CompositeRecord) -> i32
    match
      subject
        field-access maybe_count
          var record
      arm some payload
        var payload
      arm none
        int 0
  fn maybe_wide_value(record: CompositeRecord) -> i64
    match
      subject
        field-access maybe_wide
          var record
      arm some payload
        var payload
      arm none
        i64 0
  fn maybe_ratio_value(record: CompositeRecord) -> f64
    match
      subject
        field-access maybe_ratio
          var record
      arm some payload
        var payload
      arm none
        float 0
  fn maybe_flag_value(record: CompositeRecord) -> bool
    match
      subject
        field-access maybe_flag
          var record
      arm some payload
        var payload
      arm none
        bool false
  fn maybe_label_value(record: CompositeRecord) -> string
    match
      subject
        field-access maybe_label
          var record
      arm some payload
        var payload
      arm none
        string "missing"
  fn count_result_value(record: CompositeRecord) -> i32
    match
      subject
        field-access count_result
          var record
      arm ok payload
        var payload
      arm err code
        var code
  fn wide_result_value(record: CompositeRecord) -> i64
    match
      subject
        field-access wide_result
          var record
      arm ok payload
        var payload
      arm err code
        i64 0
  fn ratio_result_value(record: CompositeRecord) -> f64
    match
      subject
        field-access ratio_result
          var record
      arm ok payload
        var payload
      arm err code
        float 0
  fn flag_result_value(record: CompositeRecord) -> bool
    match
      subject
        field-access flag_result
          var record
      arm ok payload
        var payload
      arm err code
        bool false
  fn label_result_value(record: CompositeRecord) -> string
    match
      subject
        field-access label_result
          var record
      arm ok payload
        var payload
      arm err code
        string "missing"
  fn pair_total(record: CompositeRecord) -> i32
    binary +
      field-access left
        field-access pair
          var record
      field-access right
        field-access pair
          var record
  fn is_ready(record: CompositeRecord) -> bool
    binary =
      field-access status
        var record
      enum-variant Status.Ready
  fn main() -> i32
    call pair_total
      call local_record
  test "struct vec i32 field access"
    binary =
      call ints_second
        call make_record
      int 11
  test "struct vec i64 field access"
    binary =
      call wides_second
        call make_record
      i64 101
  test "struct vec f64 field access"
    binary =
      call ratios_second
        call make_record
      float 4.5
  test "struct vec bool field access"
    call flags_second
      call make_record
  test "struct vec string field access"
    binary =
      call labels_second
        call make_record
      string "elm"
  test "struct option i32 field access"
    binary =
      call maybe_count_value
        call make_record
      int 7
  test "struct option i64 field access"
    binary =
      call maybe_wide_value
        call make_record
      i64 7000000000
  test "struct option f64 field access"
    binary =
      call maybe_ratio_value
        call make_record
      float 7.5
  test "struct option bool field access"
    call maybe_flag_value
      call make_record
  test "struct option string field access"
    binary =
      call maybe_label_value
        call make_record
      string "alpha"
  test "struct result i32 field access"
    binary =
      call count_result_value
        call make_record
      int 9
  test "struct result i64 field access"
    binary =
      call wide_result_value
        call make_record
      i64 9000000000
  test "struct result f64 field access"
    binary =
      call ratio_result_value
        call make_record
      float 9.25
  test "struct result bool field access"
    call flag_result_value
      call make_record
  test "struct result string field access"
    binary =
      call label_result_value
        call make_record
      string "beta"
  test "nested struct field access"
    binary =
      call pair_total
        call make_record
      int 42
  test "nested struct local param return call flow"
    binary =
      call pair_total
        call local_record
      int 42
  test "direct enum struct field equality"
    call is_ready
      call make_record
