; Two things at once:
;  (1) `loop` used as a sub-expression in argument position — the
;      (loop ...) result of `gcd` is passed straight into another
;      call (`app print (app + (app gcd 48 18) (app gcd 1071 462)))`),
;      not used as a whole fn body. Expected stdout: 27 (gcd(48,18)=6
;      plus gcd(1071,462)=21).
;  (2) Euclid's algorithm is a textbook real iterative algorithm an
;      LLM author reaches for `loop`/`recur` to write; single-binder
;      pair? no — two binders (a, b), recur swaps/reduces.
(module loop_recur_4_gcd_value_pos
  (fn gcd
    (doc "Euclidean gcd via loop/recur. Two binders a,b; recur in the tail of the else branch.")
    (type (fn-type (params (own (con Int)) (own (con Int))) (ret (own (con Int)))))
    (params x y)
    (body
      (loop (a (con Int) x) (b (con Int) y)
        (if (app eq b 0)
            a
            (recur b (app % a b))))))
  (fn main
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body
      (app print (app + (app gcd 48 18) (app gcd 1071 462))))))
