blob: 7af8de37e314595b47deec064d72400abc6bf1c1 [file] [log] [blame] [edit]
(module
(type $0 (func (param i64) (result i64)))
(export "fac-rec" (func $0))
(export "fac-rec-named" (func $1))
(export "fac-iter" (func $2))
(export "fac-iter-named" (func $3))
(export "fac-opt" (func $4))
(func $0 (; 0 ;) (; has Stack IR ;) (type $0) (param $0 i64) (result i64)
(if (result i64)
(i64.eqz
(local.get $0)
)
(i64.const 1)
(i64.mul
(call $0
(i64.sub
(local.get $0)
(i64.const 1)
)
)
(local.get $0)
)
)
)
(func $1 (; 1 ;) (; has Stack IR ;) (type $0) (param $0 i64) (result i64)
(if (result i64)
(i64.eqz
(local.get $0)
)
(i64.const 1)
(i64.mul
(call $1
(i64.sub
(local.get $0)
(i64.const 1)
)
)
(local.get $0)
)
)
)
(func $2 (; 2 ;) (; has Stack IR ;) (type $0) (param $0 i64) (result i64)
(unreachable)
)
(func $3 (; 3 ;) (; has Stack IR ;) (type $0) (param $0 i64) (result i64)
(local $1 i64)
(local.set $1
(i64.const 1)
)
(loop $label$3
(if
(i32.eqz
(i64.eqz
(local.get $0)
)
)
(block
(local.set $1
(i64.mul
(local.get $0)
(local.get $1)
)
)
(local.set $0
(i64.sub
(local.get $0)
(i64.const 1)
)
)
(br $label$3)
)
)
)
(local.get $1)
)
(func $4 (; 4 ;) (; has Stack IR ;) (type $0) (param $0 i64) (result i64)
(local $1 i64)
(local.set $1
(i64.const 1)
)
(if
(i64.ge_s
(local.get $0)
(i64.const 2)
)
(loop $label$3
(local.set $1
(i64.mul
(local.get $0)
(local.get $1)
)
)
(br_if $label$3
(i64.gt_s
(local.tee $0
(i64.add
(local.get $0)
(i64.const -1)
)
)
(i64.const 1)
)
)
)
)
(local.get $1)
)
)