use strict;
use warnings;
use Wasm
  -api => 0,
  -wat => q{
    (module
      (func $gcd (param i32 i32) (result i32)
        (local i32)
        block  ;; label = @1
          block  ;; label = @2
            local.get 0
            br_if 0 (;@2;)
            local.get 1
            local.set 2
            br 1 (;@1;)
          end
          loop  ;; label = @2
            local.get 1
            local.get 0
            local.tee 2
            i32.rem_u
            local.set 0
            local.get 2
            local.set 1
            local.get 0
            br_if 0 (;@2;)
          end
        end
        local.get 2
      )
      (export "gcd" (func $gcd))
    )
  },
;

print "gcd(6,27) = ", gcd(6,27), "\n";
