#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*/ phint(int);
int /*<<< orphan*/ uputs(int, char *);
int fact(int n) {
  int r;
  phint(n);
  uputs(0x00400000, "\n");
  if (n <= 1)
    r = 1;
  else
    r = n * fact(n - 1);
  phint(n);
  uputs(0x00400000, "\n");
  return r;
}


x86 assembly (clang, -O0):
<fact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <phint@plt>
mov    $0x400000,%edi
lea    0xeb1(%rip),%rsi
call   1030 <uputs@plt>
cmpl   $0x1,-0x4(%rbp)
jg     116a <fact+0x3a>
movl   $0x1,-0x8(%rbp)
jmp    1186 <fact+0x56>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
call   1050 <fact@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <phint@plt>
mov    $0x400000,%edi
lea    0xe66(%rip),%rsi
call   1030 <uputs@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fact>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1040 <phint@plt>
lea    0xebf(%rip),%rsi
mov    $0x400000,%edi
call   1030 <uputs@plt>
mov    $0x1,%ebp
cmp    $0x2,%ebx
jl     1162 <fact+0x32>
lea    -0x1(%rbx),%edi
call   1050 <fact@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
mov    %ebx,%edi
call   1040 <phint@plt>
lea    0xe90(%rip),%rsi
mov    $0x400000,%edi
call   1030 <uputs@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @fact(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @phint(i32 %4)
%6 = call i32 @uputs(i32 4194304, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1, i32* %3
br label %16
10: ; preds = %1
%11 = load i32, i32* %2
%12 = load i32, i32* %2
%13 = sub nsw i32 %12, 1
%14 = call i32 @fact(i32 %13)
%15 = mul nsw i32 %11, %14
store i32 %15, i32* %3
br label %16
16: ; preds = %10, %9
%17 = load i32, i32* %2
%18 = call i32 @phint(i32 %17)
%19 = call i32 @uputs(i32 4194304, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @fact(i32 %0) {
%2 = tail call i32 @phint(i32 %0)
%3 = tail call i32 @uputs(i32 4194304, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp slt i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = add nsw i32 %0, -1
%7 = tail call i32 @fact(i32 %6)
%8 = mul nsw i32 %7, %0
br label %9
9: ; preds = %1, %5
%10 = phi i32 [ %8, %5 ], [ 1, %1 ]
%11 = tail call i32 @phint(i32 %0)
%12 = tail call i32 @uputs(i32 4194304, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret i32 %10
}