#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 */
float error_and_exit(char *);
float gammaln(int);
float factorial_ln(int n) {
  static float a[101];
  if (n < 0)
    return error_and_exit("Negative factorial in routine factorial_ln");
  if (n <= 1)
    return 0.0;
  if (n <= 100)
    return a[n] ? a[n] : (a[n] = gammaln(n + 1.0));
  else
    return gammaln(n + 1.0);
}


x86 assembly (clang, -O0):
<factorial_ln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    114b <factorial_ln+0x2b>
lea    0xecc(%rip),%rdi
call   1040 <error_and_exit@plt>
movss  %xmm0,-0x4(%rbp)
jmp    120a <factorial_ln+0xea>
cmpl   $0x1,-0x8(%rbp)
jg     1162 <factorial_ln+0x42>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    120a <factorial_ln+0xea>
cmpl   $0x64,-0x8(%rbp)
jg     11eb <factorial_ln+0xcb>
movslq -0x8(%rbp),%rcx
lea    0x2ec9(%rip),%rax
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1193 <factorial_ln+0x73>
jp     1193 <factorial_ln+0x73>
jmp    11ad <factorial_ln+0x8d>
movslq -0x8(%rbp),%rcx
lea    0x2ea2(%rip),%rax
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    11dc <factorial_ln+0xbc>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe46(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <gammaln@plt>
movslq -0x8(%rbp),%rcx
lea    0x2e6e(%rip),%rax
movss  %xmm0,(%rax,%rcx,4)
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    120a <factorial_ln+0xea>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe08(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <gammaln@plt>
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial_ln>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
js     1164 <factorial_ln+0x44>
xorps  %xmm0,%xmm0
cmp    $0x2,%edi
jb     115c <factorial_ln+0x3c>
cmp    $0x64,%edi
ja     1177 <factorial_ln+0x57>
mov    %edi,%ebx
lea    0x2f02(%rip),%r14
movss  (%r14,%rbx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    115c <factorial_ln+0x3c>
jp     115c <factorial_ln+0x3c>
add    $0x1,%edi
call   1030 <gammaln@plt>
movss  %xmm0,(%r14,%rbx,4)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe95(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <error_and_exit@plt>
add    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <gammaln@plt>

LLVM IR (-O0):
@factorial_ln.a = internal global [101 x float] zeroinitializer
@.str = [43 x i8] c"Negative factorial in routine factorial_ln\00"
define float @factorial_ln(i32 %0) {
%2 = alloca float
%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 float @error_and_exit(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store float %7, float* %2
br label %43
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %8
store float 0.000000e+00, float* %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 float], [101 x float]* @factorial_ln.a, i64 0, i64 %17
%19 = load float, float* %18
%20 = fcmp une float %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 float], [101 x float]* @factorial_ln.a, i64 0, i64 %23
%25 = load float, float* %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 float @gammaln(i32 %30)
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [101 x float], [101 x float]* @factorial_ln.a, i64 0, i64 %33
store float %31, float* %34
br label %35
35: ; preds = %26, %21
%36 = phi float [ %25, %21 ], [ %31, %26 ]
store float %36, float* %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 float @gammaln(i32 %41)
store float %42, float* %2
br label %43
43: ; preds = %37, %35, %11, %6
%44 = load float, float* %2
ret float %44
}

LLVM IR (-O2):
@factorial_ln.a = internal unnamed_addr global [101 x float] zeroinitializer
@.str = [43 x i8] c"Negative factorial in routine factorial_ln\00"
define float @factorial_ln(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call float @error_and_exit(i8* getelementptr inbounds ([43 x i8], [43 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 float], [101 x float]* @factorial_ln.a, i64 0, i64 %10
%12 = load float, float* %11
%13 = fcmp une float %12, 0.000000e+00
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = add i32 %0, 1
%16 = tail call float @gammaln(i32 %15)
store float %16, float* %11
br label %20
17: ; preds = %7
%18 = add i32 %0, 1
%19 = tail call float @gammaln(i32 %18)
br label %20
20: ; preds = %14, %9, %5, %17, %3
%21 = phi float [ %4, %3 ], [ %19, %17 ], [ 0.000000e+00, %5 ], [ %16, %14 ], [ %12, %9 ]
ret float %21
}