#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*/ assert(int);
double log(double);
double LnGamma(double alpha) {
  double x, f, z, result;
  x = alpha;
  f = 0.0;
  if (x < 7.0) {
    f = 1.0;
    z = alpha - 1.0;
    while ((z = z + 1.0) < 7.0) {
      f *= z;
    }
    x = z;
    assert(f != 0.0);
    f = -log(f);
  }
  z = 1 / (x * x);
  result =
      f + (x - 0.5) * log(x) - x + .918938533204673 +
      (((-.000595238095238 * z + .000793650793651) * z - .002777777777778) * z +
       .083333333333333) /
          x;
  return result;
}


x86 assembly (clang, -O0):
<LnGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb9(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11fb <LnGamma+0xdb>
movsd  0xeae(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe9c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe8b(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
movsd  %xmm1,-0x20(%rbp)
movsd  0xe71(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ad <LnGamma+0x8d>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1175 <LnGamma+0x55>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setne  %al
setp   %cl
or     %cl,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xdfb(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe0b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xdce(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xdad(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xda9(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd84(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd67(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LnGamma>:
sub    $0x38,%rsp
movapd %xmm0,%xmm2
movsd  0xed0(%rip),%xmm0
ucomisd %xmm2,%xmm0
jbe    11ab <LnGamma+0x8b>
addsd  0xeca(%rip),%xmm2
movsd  0xeca(%rip),%xmm3
addsd  %xmm3,%xmm2
ucomisd %xmm2,%xmm0
jbe    116e <LnGamma+0x4e>
movsd  0xeb8(%rip),%xmm1
movapd %xmm1,%xmm3
nopl   0x0(%rax)
mulsd  %xmm2,%xmm3
addsd  %xmm1,%xmm2
ucomisd %xmm2,%xmm0
ja     1160 <LnGamma+0x40>
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
xorpd  %xmm0,%xmm0
cmpneqsd %xmm3,%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1030 <assert@plt>
movsd  0x8(%rsp),%xmm0
call   1040 <log@plt>
movsd  0x10(%rsp),%xmm2
xorpd  0xea7(%rip),%xmm0
jmp    11af <LnGamma+0x8f>
xorpd  %xmm0,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
movsd  0xe45(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xe3b(%rip),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x18(%rsp)
movapd %xmm2,%xmm0
call   1040 <log@plt>
mulsd  0x18(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm3
subsd  %xmm3,%xmm0
addsd  0xe12(%rip),%xmm0
movsd  0xe12(%rip),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm1
addsd  0xe08(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  0xe04(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  0xe00(%rip),%xmm1
divsd  %xmm3,%xmm1
addsd  %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @LnGamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %2
%7 = load double, double* %2
store double %7, double* %3
store double 0.000000e+00, double* %4
%8 = load double, double* %3
%9 = fcmp olt double %8, 7.000000e+00
br i1 %9, label %10, label %30
10: ; preds = %1
store double 1.000000e+00, double* %4
%11 = load double, double* %2
%12 = fsub double %11, 1.000000e+00
store double %12, double* %5
br label %13
13: ; preds = %17, %10
%14 = load double, double* %5
%15 = fadd double %14, 1.000000e+00
store double %15, double* %5
%16 = fcmp olt double %15, 7.000000e+00
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load double, double* %5
%19 = load double, double* %4
%20 = fmul double %19, %18
store double %20, double* %4
br label %13
21: ; preds = %13
%22 = load double, double* %5
store double %22, double* %3
%23 = load double, double* %4
%24 = fcmp une double %23, 0.000000e+00
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load double, double* %4
%28 = call double @log(double %27)
%29 = fneg double %28
store double %29, double* %4
br label %30
30: ; preds = %21, %1
%31 = load double, double* %3
%32 = load double, double* %3
%33 = fmul double %31, %32
%34 = fdiv double 1.000000e+00, %33
store double %34, double* %5
%35 = load double, double* %4
%36 = load double, double* %3
%37 = fsub double %36, 5.000000e-01
%38 = load double, double* %3
%39 = call double @log(double %38)
%40 = call double @llvm.fmuladd.f64(double %37, double %39, double %35)
%41 = load double, double* %3
%42 = fsub double %40, %41
%43 = fadd double %42, 0x3FED67F1C864BEB7
%44 = load double, double* %5
%45 = call double @llvm.fmuladd.f64(double 0xBF438138138134A5, double %44, double 0x3F4A01A01A01A789)
%46 = load double, double* %5
%47 = call double @llvm.fmuladd.f64(double %45, double %46, double 0xBF66C16C16C16E17)
%48 = load double, double* %5
%49 = call double @llvm.fmuladd.f64(double %47, double %48, double 0x3FB555555555553D)
%50 = load double, double* %3
%51 = fdiv double %49, %50
%52 = fadd double %43, %51
store double %52, double* %6
%53 = load double, double* %6
ret double %53
}

LLVM IR (-O2):
define double @LnGamma(double %0) {
%2 = fcmp olt double %0, 7.000000e+00
br i1 %2, label %3, label %21
3: ; preds = %1
%4 = fadd double %0, -1.000000e+00
%5 = fadd double %4, 1.000000e+00
%6 = fcmp olt double %5, 7.000000e+00
br i1 %6, label %7, label %13
7: ; preds = %3, %7
%8 = phi double [ %11, %7 ], [ %5, %3 ]
%9 = phi double [ %10, %7 ], [ 1.000000e+00, %3 ]
%10 = fmul double %9, %8
%11 = fadd double %8, 1.000000e+00
%12 = fcmp olt double %11, 7.000000e+00
br i1 %12, label %7, label %13
13: ; preds = %7, %3
%14 = phi double [ 1.000000e+00, %3 ], [ %10, %7 ]
%15 = phi double [ %5, %3 ], [ %11, %7 ]
%16 = fcmp une double %14, 0.000000e+00
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call double @log(double %14)
%20 = fneg double %19
br label %21
21: ; preds = %13, %1
%22 = phi double [ %20, %13 ], [ 0.000000e+00, %1 ]
%23 = phi double [ %15, %13 ], [ %0, %1 ]
%24 = fmul double %23, %23
%25 = fdiv double 1.000000e+00, %24
%26 = fadd double %23, -5.000000e-01
%27 = tail call double @log(double %23)
%28 = tail call double @llvm.fmuladd.f64(double %26, double %27, double %22)
%29 = fsub double %28, %23
%30 = fadd double %29, 0x3FED67F1C864BEB7
%31 = tail call double @llvm.fmuladd.f64(double %25, double 0xBF438138138134A5, double 0x3F4A01A01A01A789)
%32 = tail call double @llvm.fmuladd.f64(double %31, double %25, double 0xBF66C16C16C16E17)
%33 = tail call double @llvm.fmuladd.f64(double %32, double %25, double 0x3FB555555555553D)
%34 = fdiv double %33, %23
%35 = fadd double %30, %34
ret double %35
}