#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*/ Exit(char *);
double gammln(int);
double factln(int n) {
  static double a[101];
  if (n < 0) {
    Exit("Err: negative factorial in routine FACTLN");
  }
  if (n <= 1)
    return 0.0;
  if (n <= 100)
    return a[n] ? a[n] : (a[n] = gammln(n + 1.0));
  else
    return gammln(n + 1.0);
}


x86 assembly (clang, -O0):
<factln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1141 <factln+0x21>
lea    0xecc(%rip),%rdi
call   1030 <Exit@plt>
cmpl   $0x1,-0xc(%rbp)
jg     1158 <factln+0x38>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1201 <factln+0xe1>
cmpl   $0x64,-0xc(%rbp)
jg     11e2 <factln+0xc2>
movslq -0xc(%rbp),%rcx
lea    0x2ed3(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118a <factln+0x6a>
jp     118a <factln+0x6a>
jmp    11a4 <factln+0x84>
movslq -0xc(%rbp),%rcx
lea    0x2eab(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11d3 <factln+0xb3>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe4f(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <gammln@plt>
movslq -0xc(%rbp),%rcx
lea    0x2e77(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1201 <factln+0xe1>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe11(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <gammln@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factln>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
js     1161 <factln+0x41>
xorpd  %xmm0,%xmm0
cmp    $0x2,%edi
jb     1171 <factln+0x51>
cmp    $0x64,%edi
ja     1179 <factln+0x59>
mov    %edi,%ebx
lea    0x2f01(%rip),%r14
movsd  (%r14,%rbx,8),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1171 <factln+0x51>
jp     1171 <factln+0x51>
add    $0x1,%edi
call   1040 <gammln@plt>
movsd  %xmm0,(%r14,%rbx,8)
jmp    1171 <factln+0x51>
lea    0xe98(%rip),%rdi
call   1030 <Exit@plt>
xorpd  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <gammln@plt>

LLVM IR (-O0):
@factln.a = internal global [101 x double] zeroinitializer
@.str = [42 x i8] c"Err: negative factorial in routine FACTLN\00"
define double @factln(i32 %0) {
%2 = alloca double
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @Exit(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* %3
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %8
store double 0.000000e+00, double* %2
br label %43
12: ; preds = %8
%13 = load i32, i32* %3
%14 = icmp sle i32 %13, 100
br i1 %14, label %15, label %37
15: ; preds = %12
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [101 x double], [101 x double]* @factln.a, i64 0, i64 %17
%19 = load double, double* %18
%20 = fcmp une double %19, 0.000000e+00
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [101 x double], [101 x double]* @factln.a, i64 0, i64 %23
%25 = load double, double* %24
br label %35
26: ; preds = %15
%27 = load i32, i32* %3
%28 = sitofp i32 %27 to double
%29 = fadd double %28, 1.000000e+00
%30 = fptosi double %29 to i32
%31 = call double @gammln(i32 %30)
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [101 x double], [101 x double]* @factln.a, i64 0, i64 %33
store double %31, double* %34
br label %35
35: ; preds = %26, %21
%36 = phi double [ %25, %21 ], [ %31, %26 ]
store double %36, double* %2
br label %43
37: ; preds = %12
%38 = load i32, i32* %3
%39 = sitofp i32 %38 to double
%40 = fadd double %39, 1.000000e+00
%41 = fptosi double %40 to i32
%42 = call double @gammln(i32 %41)
store double %42, double* %2
br label %43
43: ; preds = %37, %35, %11
%44 = load double, double* %2
ret double %44
}

LLVM IR (-O2):
@factln.a = internal unnamed_addr global [101 x double] zeroinitializer
@.str = [42 x i8] c"Err: negative factorial in routine FACTLN\00"
define double @factln(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @Exit(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %20
5: ; preds = %1
%6 = icmp ult i32 %0, 2
br i1 %6, label %20, label %7
7: ; preds = %5
%8 = icmp ult i32 %0, 101
br i1 %8, label %9, label %17
9: ; preds = %7
%10 = zext i32 %0 to i64
%11 = getelementptr inbounds [101 x double], [101 x double]* @factln.a, i64 0, i64 %10
%12 = load double, double* %11
%13 = fcmp une double %12, 0.000000e+00
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = add i32 %0, 1
%16 = tail call double @gammln(i32 %15)
store double %16, double* %11
br label %20
17: ; preds = %7
%18 = add i32 %0, 1
%19 = tail call double @gammln(i32 %18)
br label %20
20: ; preds = %3, %14, %9, %5, %17
%21 = phi double [ %19, %17 ], [ 0.000000e+00, %5 ], [ %16, %14 ], [ %12, %9 ], [ 0.000000e+00, %3 ]
ret double %21
}