program main
  fn narrow(value: i64) -> (result i32 i32)
    call std.num.i64_to_i32_result
      var value
  fn low_ok() -> (result i32 i32)
    call narrow
      i64 -2147483648
  fn high_ok() -> (result i32 i32)
    call narrow
      i64 2147483647
  fn negative_ok() -> (result i32 i32)
    call narrow
      i64 -7
  fn below_low_err() -> (result i32 i32)
    call narrow
      i64 -2147483649
  fn above_high_err() -> (result i32 i32)
    call narrow
      i64 2147483648
  fn main() -> i32
    local let value: (result i32 i32)
      call negative_ok
    if
      std.result.is_ok
        var value
      if
        binary =
          std.result.unwrap_ok
            var value
          int -7
        int 0
        int 1
      std.result.unwrap_err
        var value
  test "i64 low bound narrows to i32"
    local let value: (result i32 i32)
      call low_ok
    if
      std.result.is_ok
        var value
      binary =
        std.result.unwrap_ok
          var value
        int -2147483648
      bool false
  test "i64 high bound narrows to i32"
    local let value: (result i32 i32)
      call high_ok
    if
      std.result.is_ok
        var value
      binary =
        std.result.unwrap_ok
          var value
        int 2147483647
      bool false
  test "negative i64 narrows to i32"
    local let value: (result i32 i32)
      call negative_ok
    if
      std.result.is_ok
        var value
      binary =
        std.result.unwrap_ok
          var value
        int -7
      bool false
  test "below i32 range returns err"
    local let value: (result i32 i32)
      call below_low_err
    if
      std.result.is_err
        var value
      binary =
        std.result.unwrap_err
          var value
        int 1
      bool false
  test "above i32 range returns err"
    local let value: (result i32 i32)
      call above_high_err
    if
      std.result.is_err
        var value
      binary =
        std.result.unwrap_err
          var value
        int 1
      bool false
