program main
  enum Reading
    variant Missing
    variant Value i32
    variant Offset i32
  enum WideReading
    variant Missing
    variant Value i64
  enum RatioReading
    variant Missing
    variant Value f64
  enum FlagReading
    variant Missing
    variant Value bool
  enum LabelReading
    variant Missing
    variant Value string
  struct PayloadRecord
    field reading: Reading
    field wide: WideReading
    field ratio: RatioReading
    field flag: FlagReading
    field label: LabelReading
  fn value(payload: i32) -> Reading
    enum-variant Reading.Value #1 payload : Reading
      var payload : i32
  fn echo_reading(reading: Reading) -> Reading
    var reading : Reading
  fn local_reading(payload: i32) -> Reading
    local let reading : unit
      enum-variant Reading.Value #1 payload : Reading
        var payload : i32
    var reading : Reading
  fn call_reading(payload: i32) -> Reading
    call echo_reading : Reading
      call local_reading : Reading
        var payload : i32
  fn reading_code(reading: Reading) -> i32
    match : i32
      subject
        var reading : Reading
      arm Reading.Missing
        int 0 : i32
      arm Reading.Value payload
        var payload : i32
      arm Reading.Offset payload
        binary + : i32
          var payload : i32
          int 100 : i32
  fn wide_value(payload: i64) -> WideReading
    enum-variant WideReading.Value #1 payload : WideReading
      var payload : i64
  fn echo_wide(reading: WideReading) -> WideReading
    var reading : WideReading
  fn local_wide(payload: i64) -> WideReading
    local let reading : unit
      enum-variant WideReading.Value #1 payload : WideReading
        var payload : i64
    var reading : WideReading
  fn call_wide(payload: i64) -> WideReading
    call echo_wide : WideReading
      call local_wide : WideReading
        var payload : i64
  fn wide_code(reading: WideReading) -> i64
    match : i64
      subject
        var reading : WideReading
      arm WideReading.Missing
        i64 0 : i64
      arm WideReading.Value payload
        var payload : i64
  fn ratio_value(payload: f64) -> RatioReading
    enum-variant RatioReading.Value #1 payload : RatioReading
      var payload : f64
  fn ratio_code(reading: RatioReading) -> f64
    match : f64
      subject
        var reading : RatioReading
      arm RatioReading.Missing
        float 0 : f64
      arm RatioReading.Value payload
        var payload : f64
  fn flag_value(payload: bool) -> FlagReading
    enum-variant FlagReading.Value #1 payload : FlagReading
      var payload : bool
  fn flag_code(reading: FlagReading) -> bool
    match : bool
      subject
        var reading : FlagReading
      arm FlagReading.Missing
        bool false : bool
      arm FlagReading.Value payload
        var payload : bool
  fn label_value(payload: string) -> LabelReading
    enum-variant LabelReading.Value #1 payload : LabelReading
      var payload : string
  fn echo_label(reading: LabelReading) -> LabelReading
    var reading : LabelReading
  fn local_label(payload: string) -> LabelReading
    local let reading : unit
      enum-variant LabelReading.Value #1 payload : LabelReading
        var payload : string
    var reading : LabelReading
  fn call_label(payload: string) -> LabelReading
    call echo_label : LabelReading
      call local_label : LabelReading
        var payload : string
  fn label_text(reading: LabelReading) -> string
    match : string
      subject
        var reading : LabelReading
      arm LabelReading.Missing
        string "" : string
      arm LabelReading.Value payload
        var payload : string
  fn pack_record(reading: Reading, wide: WideReading, ratio: RatioReading, flag: FlagReading, label: LabelReading) -> PayloadRecord
    construct PayloadRecord : PayloadRecord
      field reading
        var reading : Reading
      field wide
        var wide : WideReading
      field ratio
        var ratio : RatioReading
      field flag
        var flag : FlagReading
      field label
        var label : LabelReading
  fn make_record() -> PayloadRecord
    call pack_record : PayloadRecord
      enum-variant Reading.Offset #2 payload : Reading
        int 5 : i32
      enum-variant WideReading.Value #1 payload : WideReading
        i64 4294967296 : i64
      enum-variant RatioReading.Value #1 payload : RatioReading
        float 3.5 : f64
      enum-variant FlagReading.Value #1 payload : FlagReading
        bool true : bool
      enum-variant LabelReading.Value #1 payload : LabelReading
        string "hello" : string
  fn echo_record(record: PayloadRecord) -> PayloadRecord
    var record : PayloadRecord
  fn local_record() -> PayloadRecord
    local let record : unit
      call make_record : PayloadRecord
    call echo_record : PayloadRecord
      var record : PayloadRecord
  fn record_reading_code(record: PayloadRecord) -> i32
    call reading_code : i32
      field-access reading : Reading
        var record : PayloadRecord
  fn record_wide_code(record: PayloadRecord) -> i64
    call wide_code : i64
      field-access wide : WideReading
        var record : PayloadRecord
  fn record_ratio_code(record: PayloadRecord) -> f64
    call ratio_code : f64
      field-access ratio : RatioReading
        var record : PayloadRecord
  fn record_flag_code(record: PayloadRecord) -> bool
    call flag_code : bool
      field-access flag : FlagReading
        var record : PayloadRecord
  fn record_label_text(record: PayloadRecord) -> string
    call label_text : string
      field-access label : LabelReading
        var record : PayloadRecord
  fn main() -> i32
    call record_reading_code : i32
      call local_record : PayloadRecord
  test "i32 enum constructor equality"
    binary = : bool
      enum-variant Reading.Value #1 payload : Reading
        int 7 : i32
      call value : Reading
        int 7 : i32
  test "i32 enum equality compares payload"
    if : bool
      binary = : bool
        enum-variant Reading.Value #1 payload : Reading
          int 7 : i32
        enum-variant Reading.Value #1 payload : Reading
          int 8 : i32
      bool false : bool
      bool true : bool
  test "i32 enum payloadless equality"
    binary = : bool
      enum-variant Reading.Missing #0 : Reading
      call echo_reading : Reading
        enum-variant Reading.Missing #0 : Reading
  test "i32 enum local return call flow"
    binary = : bool
      call call_reading : Reading
        int 9 : i32
      enum-variant Reading.Value #1 payload : Reading
        int 9 : i32
  test "i64 enum constructor equality"
    binary = : bool
      enum-variant WideReading.Value #1 payload : WideReading
        i64 4294967296 : i64
      call wide_value : WideReading
        i64 4294967296 : i64
  test "i64 enum local return call flow"
    binary = : bool
      call call_wide : WideReading
        i64 4294967297 : i64
      enum-variant WideReading.Value #1 payload : WideReading
        i64 4294967297 : i64
  test "f64 enum constructor equality"
    binary = : bool
      enum-variant RatioReading.Value #1 payload : RatioReading
        float 3.5 : f64
      call ratio_value : RatioReading
        float 3.5 : f64
  test "f64 enum equality compares payload"
    if : bool
      binary = : bool
        enum-variant RatioReading.Value #1 payload : RatioReading
          float 3.5 : f64
        enum-variant RatioReading.Value #1 payload : RatioReading
          float 4.5 : f64
      bool false : bool
      bool true : bool
  test "bool enum constructor equality"
    binary = : bool
      enum-variant FlagReading.Value #1 payload : FlagReading
        bool true : bool
      call flag_value : FlagReading
        bool true : bool
  test "bool enum match value"
    call flag_code : bool
      enum-variant FlagReading.Value #1 payload : FlagReading
        bool true : bool
  test "string enum constructor equality"
    binary = : bool
      enum-variant LabelReading.Value #1 payload : LabelReading
        string "hello" : string
      call label_value : LabelReading
        string "hello" : string
  test "string enum equality compares payload"
    if : bool
      binary = : bool
        enum-variant LabelReading.Value #1 payload : LabelReading
          string "left" : string
        enum-variant LabelReading.Value #1 payload : LabelReading
          string "right" : string
      bool false : bool
      bool true : bool
  test "string enum local return call flow"
    binary = : bool
      call call_label : LabelReading
        string "hello" : string
      enum-variant LabelReading.Value #1 payload : LabelReading
        string "hello" : string
  test "struct field enum i32 flow"
    binary = : bool
      call record_reading_code : i32
        call local_record : PayloadRecord
      int 105 : i32
  test "struct field enum i64 flow"
    binary = : bool
      call record_wide_code : i64
        call local_record : PayloadRecord
      i64 4294967296 : i64
  test "struct field enum f64 flow"
    binary = : bool
      call record_ratio_code : f64
        call local_record : PayloadRecord
      float 3.5 : f64
  test "struct field enum bool flow"
    call record_flag_code : bool
      call local_record : PayloadRecord
  test "struct field enum string flow"
    binary = : bool
      call record_label_text : string
        call local_record : PayloadRecord
      string "hello" : string
