#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*/ printf(char *, int);
double factorial(int n) {
  double fact = 1, i;
  if (n > 100)
    printf("factorial(%d) may be too large\n", n);
  for (i = 2; i <= n; i++)
    fact *= i;
  return (fact);
}


x86 assembly (clang, -O0):
<factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  0xedd(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x64,-0x4(%rbp)
jle    1141 <factorial+0x31>
mov    -0x4(%rbp),%esi
lea    0xed4(%rip),%rdi
call   1030 <printf@plt>
movsd  0xebf(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x4(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1188 <factorial+0x78>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe87(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    114e <factorial+0x3e>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial>:
push   %rbx
mov    %edi,%ebx
cmp    $0x65,%edi
jl     1128 <factorial+0x18>
lea    0xef1(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    1137 <factorial+0x27>
cmp    $0x2,%ebx
jge    1137 <factorial+0x27>
movsd  0xecb(%rip),%xmm0
jmp    115e <factorial+0x4e>
cvtsi2sd %ebx,%xmm1
movsd  0xebd(%rip),%xmm2
movsd  0xebd(%rip),%xmm3
movapd %xmm2,%xmm0
nop
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm1
jae    1150 <factorial+0x40>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"factorial(%d) may be too large\0A\00"
define double @factorial(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
store i32 %0, i32* %2
store double 1.000000e+00, double* %3
%5 = load i32, i32* %2
%6 = icmp sgt i32 %5, 100
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %7, %1
store double 2.000000e+00, double* %4
br label %11
11: ; preds = %20, %10
%12 = load double, double* %4
%13 = load i32, i32* %2
%14 = sitofp i32 %13 to double
%15 = fcmp ole double %12, %14
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load double, double* %4
%18 = load double, double* %3
%19 = fmul double %18, %17
store double %19, double* %3
br label %20
20: ; preds = %16
%21 = load double, double* %4
%22 = fadd double %21, 1.000000e+00
store double %22, double* %4
br label %11
23: ; preds = %11
%24 = load double, double* %3
ret double %24
}

LLVM IR (-O2):
@.str = [32 x i8] c"factorial(%d) may be too large\0A\00"
define double @factorial(i32 %0) {
%2 = icmp sgt i32 %0, 100
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %7
5: ; preds = %1
%6 = icmp slt i32 %0, 2
br i1 %6, label %15, label %7
7: ; preds = %3, %5
%8 = sitofp i32 %0 to double
br label %9
9: ; preds = %7, %9
%10 = phi double [ %13, %9 ], [ 2.000000e+00, %7 ]
%11 = phi double [ %12, %9 ], [ 1.000000e+00, %7 ]
%12 = fmul double %11, %10
%13 = fadd double %10, 1.000000e+00
%14 = fcmp ugt double %13, %8
br i1 %14, label %15, label %9
15: ; preds = %9, %5
%16 = phi double [ 1.000000e+00, %5 ], [ %12, %9 ]
ret double %16
}