(module main)

(fn maybe_value ((value i32)) -> (option i32)
  (some i32 value))

(fn maybe_empty () -> (option i32)
  (none i32))

(fn maybe_wide_value ((value i64)) -> (option i64)
  (some i64 value))

(fn maybe_wide_empty () -> (option i64)
  (none i64))

(fn maybe_float_value ((value f64)) -> (option f64)
  (some f64 value))

(fn maybe_float_empty () -> (option f64)
  (none f64))

(fn maybe_flag_value ((value bool)) -> (option bool)
  (some bool value))

(fn maybe_flag_empty () -> (option bool)
  (none bool))

(fn maybe_string_value ((value string)) -> (option string)
  (some string value))

(fn maybe_string_empty () -> (option string)
  (none string))

(fn option_score ((value (option i32))) -> i32
  (if (is_some value)
    1
    0))

(fn option_empty_score ((value (option i32))) -> i32
  (if (is_none value)
    1
    0))

(fn option_wide_score ((value (option i64))) -> i32
  (if (is_some value)
    1
    0))

(fn option_wide_empty_score ((value (option i64))) -> i32
  (if (is_none value)
    1
    0))

(fn option_float_score ((value (option f64))) -> i32
  (if (is_some value)
    1
    0))

(fn option_float_empty_score ((value (option f64))) -> i32
  (if (is_none value)
    1
    0))

(fn option_flag_score ((value (option bool))) -> i32
  (if (is_some value)
    1
    0))

(fn option_flag_empty_score ((value (option bool))) -> i32
  (if (is_none value)
    1
    0))

(fn option_string_score ((value (option string))) -> i32
  (if (is_some value)
    1
    0))

(fn option_string_empty_score ((value (option string))) -> i32
  (if (is_none value)
    1
    0))

(fn result_ok_value ((value i32)) -> (result i32 i32)
  (ok i32 i32 value))

(fn result_err_value ((code i32)) -> (result i32 i32)
  (err i32 i32 code))

(fn result_success_score ((value (result i32 i32))) -> i32
  (if (is_ok value)
    1
    0))

(fn result_failure_score ((value (result i32 i32))) -> i32
  (if (is_err value)
    1
    0))

(fn option_local_flow () -> i32
  (let value (option i32) (maybe_value 42))
  (option_score value))

(fn option_wide_local_flow () -> i32
  (let value (option i64) (maybe_wide_value 2147483648i64))
  (option_wide_score value))

(fn option_float_local_flow () -> i32
  (let value (option f64) (maybe_float_value 42.5))
  (option_float_score value))

(fn option_flag_local_flow () -> i32
  (let value (option bool) (maybe_flag_value true))
  (option_flag_score value))

(fn option_string_local_flow () -> i32
  (let value (option string) (maybe_string_value "slovo"))
  (option_string_score value))

(fn result_local_flow () -> i32
  (let value (result i32 i32) (result_err_value 7))
  (result_failure_score value))

(test "option local value flow"
  (= (option_local_flow) 1))

(test "option call observation"
  (= (option_empty_score (maybe_empty)) 1))

(test "option i64 local value flow"
  (= (option_wide_local_flow) 1))

(test "option i64 call observation"
  (= (option_wide_empty_score (maybe_wide_empty)) 1))

(test "option f64 local value flow"
  (= (option_float_local_flow) 1))

(test "option f64 call observation"
  (= (option_float_empty_score (maybe_float_empty)) 1))

(test "option bool local value flow"
  (= (option_flag_local_flow) 1))

(test "option bool call observation"
  (= (option_flag_empty_score (maybe_flag_empty)) 1))

(test "option string local value flow"
  (= (option_string_local_flow) 1))

(test "option string call observation"
  (= (option_string_empty_score (maybe_string_empty)) 1))

(test "result call observation"
  (= (result_success_score (result_ok_value 42)) 1))

(test "result local value flow"
  (= (result_local_flow) 1))

(fn main () -> i32
  0)
