#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ __CrestApply2(int, int, long long);
int /*<<< orphan*/ __CrestBranch(int, int, int);
int /*<<< orphan*/ __CrestCall(int, int);
int /*<<< orphan*/ __CrestHandleReturn(int, long long);
int /*<<< orphan*/ __CrestLoad(int, unsigned long, long long);
int /*<<< orphan*/ __CrestReturn(int);
int /*<<< orphan*/ __CrestStore(int, unsigned long);
int fac(int n) {
  int tmp;
  int __retres3;
  {
    __CrestCall(2, 1);
    __CrestStore(1, (unsigned long)(&n));
    {
      __CrestLoad(5, (unsigned long)(&n), (long long)n);
      __CrestLoad(4, (unsigned long)0, (long long)0);
      __CrestApply2(3, 12, (long long)(n == 0));
      if (n == 0) {
        __CrestBranch(6, 2, 1);
        __CrestLoad(8, (unsigned long)0, (long long)1);
        __CrestStore(9, (unsigned long)(&__retres3));
        __retres3 = 1;
        goto return_label;
      } else {
        __CrestBranch(7, 4, 0);
        __CrestLoad(12, (unsigned long)(&n), (long long)n);
        __CrestLoad(11, (unsigned long)0, (long long)1);
        __CrestApply2(10, 1, (long long)(n - 1));
        tmp = fac(n - 1);
        __CrestHandleReturn(14, (long long)tmp);
        __CrestStore(13, (unsigned long)(&tmp));
        __CrestLoad(17, (unsigned long)(&n), (long long)n);
        __CrestLoad(16, (unsigned long)(&tmp), (long long)tmp);
        __CrestApply2(15, 0, (long long)(n + tmp));
        __CrestStore(18, (unsigned long)(&__retres3));
        __retres3 = n + tmp;
        goto return_label;
      }
    }
  return_label : {
    __CrestLoad(19, (unsigned long)(&__retres3), (long long)__retres3);
    __CrestReturn(20);
    return (__retres3);
  }
  }
}


x86 assembly (clang, -O0):
<fac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
call   1080 <__CrestCall@plt>
lea    -0x4(%rbp),%rsi
mov    $0x1,%edi
call   1060 <__CrestStore@plt>
lea    -0x4(%rbp),%rsi
movslq -0x4(%rbp),%rdx
mov    $0x5,%edi
call   1090 <__CrestLoad@plt>
mov    $0x4,%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1090 <__CrestLoad@plt>
cmpl   $0x0,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdx
mov    $0x3,%edi
mov    $0xc,%esi
call   1030 <__CrestApply2@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1234 <fac+0xb4>
mov    $0x6,%edi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <__CrestBranch@plt>
mov    $0x8,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x1,%edx
call   1090 <__CrestLoad@plt>
lea    -0xc(%rbp),%rsi
mov    $0x9,%edi
call   1060 <__CrestStore@plt>
movl   $0x1,-0xc(%rbp)
jmp    12fc <fac+0x17c>
mov    $0x7,%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <__CrestBranch@plt>
lea    -0x4(%rbp),%rsi
movslq -0x4(%rbp),%rdx
mov    $0xc,%edi
call   1090 <__CrestLoad@plt>
mov    $0xb,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x1,%edx
call   1090 <__CrestLoad@plt>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
mov    $0xa,%edi
mov    $0x1,%esi
call   1030 <__CrestApply2@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
call   1040 <fac@plt>
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rsi
mov    $0xe,%edi
call   10a0 <__CrestHandleReturn@plt>
lea    -0x8(%rbp),%rsi
mov    $0xd,%edi
call   1060 <__CrestStore@plt>
lea    -0x4(%rbp),%rsi
movslq -0x4(%rbp),%rdx
mov    $0x11,%edi
call   1090 <__CrestLoad@plt>
lea    -0x8(%rbp),%rsi
movslq -0x8(%rbp),%rdx
mov    $0x10,%edi
call   1090 <__CrestLoad@plt>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
movslq %eax,%rdx
mov    $0xf,%edi
xor    %esi,%esi
call   1030 <__CrestApply2@plt>
lea    -0xc(%rbp),%rsi
mov    $0x12,%edi
call   1060 <__CrestStore@plt>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rsi
movslq -0xc(%rbp),%rdx
mov    $0x13,%edi
call   1090 <__CrestLoad@plt>
mov    $0x14,%edi
call   1070 <__CrestReturn@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fac>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,0x4(%rsp)
mov    $0x1,%ebp
mov    $0x2,%edi
mov    $0x1,%esi
call   1080 <__CrestCall@plt>
lea    0x4(%rsp),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1060 <__CrestStore@plt>
movslq 0x4(%rsp),%rdx
mov    $0x5,%edi
mov    %rbx,%rsi
call   1090 <__CrestLoad@plt>
mov    $0x4,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <__CrestLoad@plt>
xor    %edx,%edx
cmpl   $0x0,0x4(%rsp)
sete   %dl
mov    $0x3,%edi
mov    $0xc,%esi
call   1030 <__CrestApply2@plt>
cmpl   $0x0,0x4(%rsp)
je     12cf <fac+0x14f>
mov    $0x7,%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <__CrestBranch@plt>
movslq 0x4(%rsp),%rdx
lea    0x4(%rsp),%r14
mov    $0xc,%edi
mov    %r14,%rsi
call   1090 <__CrestLoad@plt>
mov    $0x1,%edx
mov    $0xb,%edi
xor    %esi,%esi
call   1090 <__CrestLoad@plt>
movslq 0x4(%rsp),%rdx
add    $0xffffffffffffffff,%rdx
mov    $0xa,%edi
mov    $0x1,%esi
call   1030 <__CrestApply2@plt>
mov    0x4(%rsp),%edi
add    $0xffffffff,%edi
call   1040 <fac@plt>
mov    %eax,0x8(%rsp)
movslq %eax,%rsi
mov    $0xe,%edi
call   10a0 <__CrestHandleReturn@plt>
lea    0x8(%rsp),%rbx
mov    $0xd,%edi
mov    %rbx,%rsi
call   1060 <__CrestStore@plt>
movslq 0x4(%rsp),%rdx
mov    $0x11,%edi
mov    %r14,%rsi
call   1090 <__CrestLoad@plt>
movslq 0x8(%rsp),%rdx
mov    $0x10,%edi
mov    %rbx,%rsi
call   1090 <__CrestLoad@plt>
movslq 0x4(%rsp),%rax
movslq 0x8(%rsp),%rdx
add    %rax,%rdx
mov    $0xf,%edi
xor    %esi,%esi
call   1030 <__CrestApply2@plt>
lea    0xc(%rsp),%rbx
mov    $0x12,%edi
mov    %rbx,%rsi
call   1060 <__CrestStore@plt>
mov    0x8(%rsp),%ebp
add    0x4(%rsp),%ebp
jmp    1306 <fac+0x186>
mov    $0x6,%edi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <__CrestBranch@plt>
mov    $0x1,%edx
mov    $0x8,%edi
xor    %esi,%esi
call   1090 <__CrestLoad@plt>
lea    0xc(%rsp),%rbx
mov    $0x9,%edi
mov    %rbx,%rsi
call   1060 <__CrestStore@plt>
mov    %ebp,0xc(%rsp)
movslq %ebp,%rdx
mov    $0x13,%edi
mov    %rbx,%rsi
call   1090 <__CrestLoad@plt>
mov    $0x14,%edi
call   1070 <__CrestReturn@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fac(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @__CrestCall(i32 2, i32 1)
%6 = ptrtoint i32* %2 to i64
%7 = call i32 @__CrestStore(i32 1, i64 %6)
%8 = ptrtoint i32* %2 to i64
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = call i32 @__CrestLoad(i32 5, i64 %8, i64 %10)
%12 = call i32 @__CrestLoad(i32 4, i64 0, i64 0)
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = sext i32 %15 to i64
%17 = call i32 @__CrestApply2(i32 3, i32 12, i64 %16)
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %1
%21 = call i32 @__CrestBranch(i32 6, i32 2, i32 1)
%22 = call i32 @__CrestLoad(i32 8, i64 0, i64 1)
%23 = ptrtoint i32* %4 to i64
%24 = call i32 @__CrestStore(i32 9, i64 %23)
store i32 1, i32* %4
br label %62
25: ; preds = %1
%26 = call i32 @__CrestBranch(i32 7, i32 4, i32 0)
%27 = ptrtoint i32* %2 to i64
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = call i32 @__CrestLoad(i32 12, i64 %27, i64 %29)
%31 = call i32 @__CrestLoad(i32 11, i64 0, i64 1)
%32 = load i32, i32* %2
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = call i32 @__CrestApply2(i32 10, i32 1, i64 %34)
%36 = load i32, i32* %2
%37 = sub nsw i32 %36, 1
%38 = call i32 @fac(i32 %37)
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = call i32 @__CrestHandleReturn(i32 14, i64 %40)
%42 = ptrtoint i32* %3 to i64
%43 = call i32 @__CrestStore(i32 13, i64 %42)
%44 = ptrtoint i32* %2 to i64
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = call i32 @__CrestLoad(i32 17, i64 %44, i64 %46)
%48 = ptrtoint i32* %3 to i64
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = call i32 @__CrestLoad(i32 16, i64 %48, i64 %50)
%52 = load i32, i32* %2
%53 = load i32, i32* %3
%54 = add nsw i32 %52, %53
%55 = sext i32 %54 to i64
%56 = call i32 @__CrestApply2(i32 15, i32 0, i64 %55)
%57 = ptrtoint i32* %4 to i64
%58 = call i32 @__CrestStore(i32 18, i64 %57)
%59 = load i32, i32* %2
%60 = load i32, i32* %3
%61 = add nsw i32 %59, %60
store i32 %61, i32* %4
br label %62
62: ; preds = %25, %20
%63 = ptrtoint i32* %4 to i64
%64 = load i32, i32* %4
%65 = sext i32 %64 to i64
%66 = call i32 @__CrestLoad(i32 19, i64 %63, i64 %65)
%67 = call i32 @__CrestReturn(i32 20)
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
define i32 @fac(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @__CrestCall(i32 2, i32 1)
%8 = ptrtoint i32* %2 to i64
%9 = call i32 @__CrestStore(i32 1, i64 %8)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = call i32 @__CrestLoad(i32 5, i64 %8, i64 %11)
%13 = call i32 @__CrestLoad(i32 4, i64 0, i64 0)
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i64
%17 = call i32 @__CrestApply2(i32 3, i32 12, i64 %16)
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %1
%21 = call i32 @__CrestBranch(i32 6, i32 2, i32 1)
%22 = call i32 @__CrestLoad(i32 8, i64 0, i64 1)
%23 = ptrtoint i32* %4 to i64
%24 = call i32 @__CrestStore(i32 9, i64 %23)
br label %58
25: ; preds = %1
%26 = call i32 @__CrestBranch(i32 7, i32 4, i32 0)
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = call i32 @__CrestLoad(i32 12, i64 %8, i64 %28)
%30 = call i32 @__CrestLoad(i32 11, i64 0, i64 1)
%31 = load i32, i32* %2
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = call i32 @__CrestApply2(i32 10, i32 1, i64 %33)
%35 = load i32, i32* %2
%36 = add nsw i32 %35, -1
%37 = call i32 @fac(i32 %36)
store i32 %37, i32* %3
%38 = sext i32 %37 to i64
%39 = call i32 @__CrestHandleReturn(i32 14, i64 %38)
%40 = ptrtoint i32* %3 to i64
%41 = call i32 @__CrestStore(i32 13, i64 %40)
%42 = load i32, i32* %2
%43 = sext i32 %42 to i64
%44 = call i32 @__CrestLoad(i32 17, i64 %8, i64 %43)
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = call i32 @__CrestLoad(i32 16, i64 %40, i64 %46)
%48 = load i32, i32* %2
%49 = load i32, i32* %3
%50 = add nsw i32 %49, %48
%51 = sext i32 %50 to i64
%52 = call i32 @__CrestApply2(i32 15, i32 0, i64 %51)
%53 = ptrtoint i32* %4 to i64
%54 = call i32 @__CrestStore(i32 18, i64 %53)
%55 = load i32, i32* %2
%56 = load i32, i32* %3
%57 = add nsw i32 %56, %55
br label %58
58: ; preds = %25, %20
%59 = phi i64 [ %53, %25 ], [ %23, %20 ]
%60 = phi i32 [ %57, %25 ], [ 1, %20 ]
store i32 %60, i32* %4
%61 = sext i32 %60 to i64
%62 = call i32 @__CrestLoad(i32 19, i64 %59, i64 %61)
%63 = call i32 @__CrestReturn(i32 20)
%64 = load i32, i32* %4
ret i32 %64
}