#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 INT_MAX;
long long factorial(int);
int /*<<< orphan*/ printf(char *, int, long long);
void test1() {
  int i = 0;
  for (i = 1; i < INT_MAX; i++) {
    long long r = factorial(i);
    if (r > 0)
      printf("factorial(%d)=%lld\n", i, r);
    else
      break;
  }
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ea8(%rip),%rcx
cmp    (%rcx),%eax
jge    118f <test1+0x6f>
mov    -0x4(%rbp),%edi
call   1030 <factorial@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    1177 <test1+0x57>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
jmp    117c <test1+0x5c>
jmp    118f <test1+0x6f>
jmp    1181 <test1+0x61>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1136 <test1+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %r15
push   %r14
push   %rbx
mov    0x2ebc(%rip),%r15
cmpl   $0x2,(%r15)
jl     1161 <test1+0x41>
mov    $0x1,%ebx
lea    0xec2(%rip),%r14
xchg   %ax,%ax
mov    %ebx,%edi
call   1030 <factorial@plt>
test   %rax,%rax
jle    1161 <test1+0x41>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    (%r15),%ebx
jl     1140 <test1+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
@.str = [20 x i8] c"factorial(%d)=%lld\0A\00"
define void @test1() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
store i32 1, i32* %1
br label %3
3: ; preds = %18, %0
%4 = load i32, i32* %1
%5 = load i32, i32* @INT_MAX
%6 = icmp slt i32 %4, %5
br i1 %6, label %7, label %21
7: ; preds = %3
%8 = load i32, i32* %1
%9 = call i64 @factorial(i32 %8)
store i64 %9, i64* %2
%10 = load i64, i64* %2
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* %1
%14 = load i64, i64* %2
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %13, i64 %14)
br label %17
16: ; preds = %7
br label %21
17: ; preds = %12
br label %18
18: ; preds = %17
%19 = load i32, i32* %1
%20 = add nsw i32 %19, 1
store i32 %20, i32* %1
br label %3
21: ; preds = %16, %3
ret void
}

LLVM IR (-O2):
@INT_MAX = global i32 0
@.str = [20 x i8] c"factorial(%d)=%lld\0A\00"
define void @test1() {
%1 = load i32, i32* @INT_MAX
%2 = icmp sgt i32 %1, 1
br i1 %2, label %3, label %12
3: ; preds = %0, %7
%4 = phi i32 [ %9, %7 ], [ 1, %0 ]
%5 = tail call i64 @factorial(i32 %4)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4, i64 %5)
%9 = add nuw nsw i32 %4, 1
%10 = load i32, i32* @INT_MAX
%11 = icmp slt i32 %9, %10
br i1 %11, label %3, label %12
12: ; preds = %7, %3, %0
ret void
}