(module main)

(fn empty_values () -> (vec i64)
  (std.vec.i64.empty))

(fn pair ((base i64)) -> (vec i64)
  (let values (vec i64) (std.vec.i64.empty))
  (let first (vec i64) (std.vec.i64.append values base))
  (std.vec.i64.append first (+ base 1i64)))

(fn echo ((values (vec i64))) -> (vec i64)
  values)

(fn length ((values (vec i64))) -> i32
  (std.vec.i64.len values))

(fn at ((values (vec i64)) (i i32)) -> i64
  (std.vec.i64.index values i))

(fn call_return_value () -> i64
  (at (echo (pair 2147483648i64)) 1))

(fn original_len_after_append () -> i32
  (let values (vec i64) (std.vec.i64.empty))
  (let appended (vec i64) (std.vec.i64.append values 1i64))
  (std.vec.i64.len values))

(test "vec i64 empty length"
  (= (std.vec.i64.len (empty_values)) 0))

(test "vec i64 append length"
  (= (length (pair 40i64)) 2))

(test "vec i64 index"
  (= (at (pair 40i64) 1) 41i64))

(test "vec i64 append is immutable"
  (= (original_len_after_append) 0))

(test "vec i64 equality"
  (= (pair 5i64) (std.vec.i64.append (std.vec.i64.append (std.vec.i64.empty) 5i64) 6i64)))

(fn main () -> i32
  (std.io.print_i64 (call_return_value))
  0)
