(module main)

(import result (ok_i32 err_i32 is_ok_i32 is_err_i32 unwrap_ok_i32 unwrap_err_i32 unwrap_or_i32 ok_or_none_i32 ok_u32 err_u32 is_ok_u32 is_err_u32 unwrap_ok_u32 unwrap_err_u32 unwrap_or_u32 ok_or_none_u32 ok_i64 err_i64 is_err_i64 unwrap_err_i64 unwrap_or_i64 ok_or_none_i64 ok_u64 err_u64 is_ok_u64 is_err_u64 unwrap_ok_u64 unwrap_err_u64 unwrap_or_u64 ok_or_none_u64 ok_string err_string is_err_string unwrap_err_string unwrap_or_string ok_or_none_string ok_f64 err_f64 is_err_f64 unwrap_err_f64 unwrap_or_f64 ok_or_none_f64 ok_bool err_bool is_ok_bool is_err_bool unwrap_ok_bool unwrap_err_bool unwrap_or_bool ok_or_none_bool))

(fn i32_ok () -> (result i32 i32)
  (ok_i32 42))

(fn i32_err () -> (result i32 i32)
  (err_i32 5))

(fn i64_ok () -> (result i64 i32)
  (ok_i64 60i64))

(fn i64_err () -> (result i64 i32)
  (err_i64 6))

(fn u32_ok () -> (result u32 i32)
  (ok_u32 42u32))

(fn u32_err () -> (result u32 i32)
  (err_u32 8))

(fn u64_ok () -> (result u64 i32)
  (ok_u64 4294967296u64))

(fn u64_err () -> (result u64 i32)
  (err_u64 9))

(fn string_ok () -> (result string i32)
  (ok_string "value"))

(fn string_err () -> (result string i32)
  (err_string 7))

(fn f64_ok () -> (result f64 i32)
  (ok_f64 12.5))

(fn f64_err () -> (result f64 i32)
  (err_f64 1))

(fn bool_ok () -> (result bool i32)
  (ok_bool true))

(fn bool_false () -> (result bool i32)
  (ok_bool false))

(fn bool_err () -> (result bool i32)
  (err_bool 1))

(fn imported_i32_result_wrappers_ok () -> bool
  (if (is_ok_i32 (i32_ok))
    (if (= (unwrap_ok_i32 (i32_ok)) 42)
      (if (is_err_i32 (i32_err))
        (= (unwrap_err_i32 (i32_err)) 5)
        false)
      false)
    false))

(fn imported_result_error_wrappers_ok () -> bool
  (if (is_err_i64 (i64_err))
    (if (= (unwrap_err_i64 (i64_err)) 6)
      (if (is_err_string (string_err))
        (if (= (unwrap_err_string (string_err)) 7)
          (if (is_err_f64 (f64_err))
            (= (unwrap_err_f64 (f64_err)) 1)
            false)
          false)
        false)
      false)
    false))

(fn imported_unwrap_or_i32_score () -> i32
  (+ (unwrap_or_i32 (i32_ok) 0) (unwrap_or_i32 (i32_err) 5)))

(fn imported_ok_or_none_i32_ok () -> bool
  (match (ok_or_none_i32 (i32_ok))
    ((some payload)
      (= payload 42))
    ((none)
      false)))

(fn imported_ok_or_none_i32_none () -> bool
  (match (ok_or_none_i32 (i32_err))
    ((some payload)
      false)
    ((none)
      true)))

(fn imported_unwrap_or_i64_score () -> i64
  (+ (unwrap_or_i64 (i64_ok) 0i64) (unwrap_or_i64 (i64_err) 5i64)))

(fn imported_u32_result_wrappers_ok () -> bool
  (if (is_ok_u32 (u32_ok))
    (if (= (unwrap_ok_u32 (u32_ok)) 42u32)
      (if (is_err_u32 (u32_err))
        (= (unwrap_err_u32 (u32_err)) 8)
        false)
      false)
    false))

(fn imported_unwrap_or_u32_score () -> u32
  (+ (unwrap_or_u32 (u32_ok) 0u32) (unwrap_or_u32 (u32_err) 5u32)))

(fn imported_ok_or_none_u32_ok () -> bool
  (match (ok_or_none_u32 (u32_ok))
    ((some payload)
      (= payload 42u32))
    ((none)
      false)))

(fn imported_ok_or_none_u32_none () -> bool
  (match (ok_or_none_u32 (u32_err))
    ((some payload)
      false)
    ((none)
      true)))

(fn imported_ok_or_none_i64_ok () -> bool
  (match (ok_or_none_i64 (i64_ok))
    ((some payload)
      (= payload 60i64))
    ((none)
      false)))

(fn imported_ok_or_none_i64_none () -> bool
  (match (ok_or_none_i64 (i64_err))
    ((some payload)
      false)
    ((none)
      true)))

(fn imported_u64_result_wrappers_ok () -> bool
  (if (is_ok_u64 (u64_ok))
    (if (= (unwrap_ok_u64 (u64_ok)) 4294967296u64)
      (if (is_err_u64 (u64_err))
        (= (unwrap_err_u64 (u64_err)) 9)
        false)
      false)
    false))

(fn imported_unwrap_or_u64_score () -> u64
  (+ (unwrap_or_u64 (u64_ok) 0u64) (unwrap_or_u64 (u64_err) 5u64)))

(fn imported_ok_or_none_u64_ok () -> bool
  (match (ok_or_none_u64 (u64_ok))
    ((some payload)
      (= payload 4294967296u64))
    ((none)
      false)))

(fn imported_ok_or_none_u64_none () -> bool
  (match (ok_or_none_u64 (u64_err))
    ((some payload)
      false)
    ((none)
      true)))

(fn imported_unwrap_or_string_ok () -> bool
  (if (= (unwrap_or_string (string_ok) "fallback") "value")
    (= (unwrap_or_string (string_err) "fallback") "fallback")
    false))

(fn imported_ok_or_none_string_ok () -> bool
  (match (ok_or_none_string (string_ok))
    ((some payload)
      (= payload "value"))
    ((none)
      false)))

(fn imported_ok_or_none_string_none () -> bool
  (match (ok_or_none_string (string_err))
    ((some payload)
      false)
    ((none)
      true)))

(fn imported_unwrap_or_f64_score () -> f64
  (+ (unwrap_or_f64 (f64_ok) 0.0) (unwrap_or_f64 (f64_err) 2.5)))

(fn imported_ok_or_none_f64_ok () -> bool
  (match (ok_or_none_f64 (f64_ok))
    ((some payload)
      (= payload 12.5))
    ((none)
      false)))

(fn imported_ok_or_none_f64_none () -> bool
  (match (ok_or_none_f64 (f64_err))
    ((some payload)
      false)
    ((none)
      true)))

(fn imported_bool_result_helpers_ok () -> bool
  (if (is_ok_bool (bool_ok))
    (if (unwrap_ok_bool (bool_ok))
      (if (is_err_bool (bool_err))
        (if (= (unwrap_err_bool (bool_err)) 1)
          (if (unwrap_or_bool (bool_false) true)
            false
            (unwrap_or_bool (bool_err) true))
          false)
        false)
      false)
    false))

(fn imported_ok_or_none_bool_ok () -> bool
  (match (ok_or_none_bool (bool_ok))
    ((some payload)
      payload)
    ((none)
      false)))

(fn imported_ok_or_none_bool_none () -> bool
  (match (ok_or_none_bool (bool_err))
    ((some payload)
      false)
    ((none)
      true)))

(fn imported_result_helpers_ok () -> bool
  (if (imported_i32_result_wrappers_ok)
    (if (imported_u32_result_wrappers_ok)
      (if (imported_result_error_wrappers_ok)
        (if (= (imported_unwrap_or_i32_score) 47)
          (if (imported_ok_or_none_i32_ok)
            (if (imported_ok_or_none_i32_none)
              (if (= (imported_unwrap_or_u32_score) 47u32)
                (if (imported_ok_or_none_u32_ok)
                  (if (imported_ok_or_none_u32_none)
                    (if (= (imported_unwrap_or_i64_score) 65i64)
                      (if (imported_ok_or_none_i64_ok)
                        (if (imported_ok_or_none_i64_none)
                          (if (imported_u64_result_wrappers_ok)
                            (if (= (imported_unwrap_or_u64_score) 4294967301u64)
                              (if (imported_ok_or_none_u64_ok)
                                (if (imported_ok_or_none_u64_none)
                                  (if (imported_unwrap_or_string_ok)
                                    (if (imported_ok_or_none_string_ok)
                                      (if (imported_ok_or_none_string_none)
                                        (if (= (imported_unwrap_or_f64_score) 15.0)
                                          (if (imported_ok_or_none_f64_ok)
                                            (if (imported_ok_or_none_f64_none)
                                              (if (imported_bool_result_helpers_ok)
                                                (if (imported_ok_or_none_bool_ok)
                                                  (imported_ok_or_none_bool_none)
                                                  false)
                                                false)
                                              false)
                                            false)
                                          false)
                                        false)
                                      false)
                                    false)
                                  false)
                                false)
                              false)
                            false)
                          false)
                        false)
                      false)
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn main () -> i32
  (if (imported_result_helpers_ok)
    42
    1))

(test "explicit local result i32 wrappers"
  (imported_i32_result_wrappers_ok))

(test "explicit local result err wrappers"
  (imported_result_error_wrappers_ok))

(test "explicit local result unwrap_or i32"
  (= (imported_unwrap_or_i32_score) 47))

(test "explicit local result ok_or_none i32 ok"
  (imported_ok_or_none_i32_ok))

(test "explicit local result ok_or_none i32 none"
  (imported_ok_or_none_i32_none))

(test "explicit local result u32 wrappers"
  (imported_u32_result_wrappers_ok))

(test "explicit local result unwrap_or u32"
  (= (imported_unwrap_or_u32_score) 47u32))

(test "explicit local result ok_or_none u32 ok"
  (imported_ok_or_none_u32_ok))

(test "explicit local result ok_or_none u32 none"
  (imported_ok_or_none_u32_none))

(test "explicit local result unwrap_or i64"
  (= (imported_unwrap_or_i64_score) 65i64))

(test "explicit local result ok_or_none i64 ok"
  (imported_ok_or_none_i64_ok))

(test "explicit local result ok_or_none i64 none"
  (imported_ok_or_none_i64_none))

(test "explicit local result u64 wrappers"
  (imported_u64_result_wrappers_ok))

(test "explicit local result unwrap_or u64"
  (= (imported_unwrap_or_u64_score) 4294967301u64))

(test "explicit local result ok_or_none u64 ok"
  (imported_ok_or_none_u64_ok))

(test "explicit local result ok_or_none u64 none"
  (imported_ok_or_none_u64_none))

(test "explicit local result unwrap_or string"
  (imported_unwrap_or_string_ok))

(test "explicit local result ok_or_none string ok"
  (imported_ok_or_none_string_ok))

(test "explicit local result ok_or_none string none"
  (imported_ok_or_none_string_none))

(test "explicit local result unwrap_or f64"
  (= (imported_unwrap_or_f64_score) 15.0))

(test "explicit local result ok_or_none f64 ok"
  (imported_ok_or_none_f64_ok))

(test "explicit local result ok_or_none f64 none"
  (imported_ok_or_none_f64_none))

(test "explicit local result bool helpers"
  (imported_bool_result_helpers_ok))

(test "explicit local result ok_or_none bool ok"
  (imported_ok_or_none_bool_ok))

(test "explicit local result ok_or_none bool none"
  (imported_ok_or_none_bool_none))

(test "explicit local result helpers all"
  (= (main) 42))
