#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*/ DBUG_ENTER(char *);
int /*<<< orphan*/ DBUG_PRINT(char *, char *);
int /*<<< orphan*/ DBUG_RETURN(int);
int factorial(int value) {
  DBUG_ENTER("factorial");
  DBUG_PRINT("find", ("find %d factorial", value));
  if (value > 1) {
    value *= factorial(value - 1);
  }
  DBUG_PRINT("result", ("result is %d", value));
  DBUG_RETURN(value);
}


x86 assembly (clang, -O0):
<factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    0xebb(%rip),%rdi
call   1050 <DBUG_ENTER@plt>
movslq -0x8(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1030 <DBUG_PRINT@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1183 <factorial+0x43>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <factorial@plt>
imul   -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1030 <DBUG_PRINT@plt>
mov    -0x8(%rbp),%edi
call   1060 <DBUG_RETURN@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xeb3(%rip),%rdi
call   1050 <DBUG_ENTER@plt>
movslq %ebx,%r14
lea    0xeae(%rip),%rdi
mov    %r14,%rsi
call   1030 <DBUG_PRINT@plt>
cmp    $0x2,%r14d
jl     1176 <factorial+0x36>
add    $0xffffffff,%ebx
mov    %ebx,%edi
call   1040 <factorial@plt>
xor    %ebx,%ebx
movslq %ebx,%rbx
lea    0xe8f(%rip),%rdi
mov    %rbx,%rsi
call   1030 <DBUG_PRINT@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <DBUG_RETURN@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"factorial\00"
@.str.1 = [5 x i8] c"find\00"
@.str.2 = [18 x i8] c"find %d factorial\00"
@.str.3 = [7 x i8] c"result\00"
@.str.4 = [13 x i8] c"result is %d\00"
define i32 @factorial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i32 @DBUG_ENTER(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* %3
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i8*
%8 = call i32 @DBUG_PRINT(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 1
%14 = call i32 @factorial(i32 %13)
%15 = load i32, i32* %3
%16 = mul nsw i32 %15, %14
store i32 %16, i32* %3
br label %17
17: ; preds = %11, %1
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
%21 = call i32 @DBUG_PRINT(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %3
%23 = call i32 @DBUG_RETURN(i32 %22)
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [10 x i8] c"factorial\00"
@.str.1 = [5 x i8] c"find\00"
@.str.3 = [7 x i8] c"result\00"
define i32 @factorial(i32 %0) {
%2 = tail call i32 @DBUG_ENTER(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = sext i32 %0 to i64
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @DBUG_PRINT(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = add nsw i32 %0, -1
%9 = tail call i32 @factorial(i32 %8)
br label %10
10: ; preds = %7, %1
%11 = phi i32 [ 0, %7 ], [ %0, %1 ]
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @DBUG_PRINT(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = tail call i32 @DBUG_RETURN(i32 %11)
ret i32 undef
}