#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);
scalar_t__ factorial(int);
double log(double);
double LnGamma(double x) {
  double f = 0, fneg = 0, z, tmp1, tmp2;
  int nx = (int)x - 1;
  if ((double)nx == x && nx > 0 && nx < 10)
    return log((double)factorial(nx));
  assert(x > 0);
  if (x < 7) {
    f = 1;
    z = x - 1;
    while (++z < 7)
      f *= z;
    x = z;
    f = -log(f);
  }
  z = 1 / (x * x);
  tmp1 = fneg + f + (x - 0.5) * log(x) - x + .918938533204673;
  tmp2 =
      (((-.000595238095238 * z + .000793650793651) * z - .002777777777778) * z +
       .083333333333333);
  return tmp1 + (tmp2 / x);
}


x86 assembly (clang, -O0):
<LnGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cvtsi2sdl -0x3c(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    119e <LnGamma+0x6e>
jp     119e <LnGamma+0x6e>
cmpl   $0x0,-0x3c(%rbp)
jle    119e <LnGamma+0x6e>
cmpl   $0xa,-0x3c(%rbp)
jge    119e <LnGamma+0x6e>
mov    -0x3c(%rbp),%edi
call   1030 <factorial@plt>
cvtsi2sd %rax,%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    132e <LnGamma+0x1fe>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  0xe41(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1255 <LnGamma+0x125>
movsd  0xe36(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe24(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe13(%rip),%xmm1
addsd  -0x28(%rbp),%xmm1
movsd  %xmm1,-0x28(%rbp)
movsd  0xdf9(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1225 <LnGamma+0xf5>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11ed <LnGamma+0xbd>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <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  0xda1(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdac(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xd6f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xd49(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd45(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd20(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd03(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
divsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LnGamma>:
sub    $0x28,%rsp
cvttsd2si %xmm0,%eax
lea    -0x1(%rax),%edi
cvtsi2sd %edi,%xmm1
ucomisd %xmm0,%xmm1
jne    1167 <LnGamma+0x37>
jp     1167 <LnGamma+0x37>
cmp    $0x2,%eax
jl     1167 <LnGamma+0x37>
cmp    $0xa,%eax
jg     1167 <LnGamma+0x37>
call   1030 <factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
add    $0x28,%rsp
jmp    1050 <log@plt>
xorpd  %xmm1,%xmm1
xor    %edi,%edi
ucomisd %xmm1,%xmm0
seta   %dil
movsd  %xmm0,0x8(%rsp)
call   1040 <assert@plt>
movsd  0x8(%rsp),%xmm3
movsd  0xe72(%rip),%xmm1
ucomisd %xmm3,%xmm1
jbe    11e9 <LnGamma+0xb9>
addsd  0xe6c(%rip),%xmm3
movsd  0xe6c(%rip),%xmm0
addsd  %xmm0,%xmm3
ucomisd %xmm3,%xmm1
jbe    11ce <LnGamma+0x9e>
movsd  0xe5a(%rip),%xmm2
movapd %xmm2,%xmm0
nopw   0x0(%rax,%rax,1)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm1
ja     11c0 <LnGamma+0x90>
movsd  %xmm3,0x8(%rsp)
call   1050 <log@plt>
movsd  0x8(%rsp),%xmm3
xorpd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
jmp    11ed <LnGamma+0xbd>
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movsd  0xe07(%rip),%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,0x20(%rsp)
movsd  0xdfd(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%rsp)
movapd %xmm3,%xmm0
call   1050 <log@plt>
mulsd  0x18(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm3
subsd  %xmm3,%xmm0
addsd  0xdd4(%rip),%xmm0
movsd  0xdd4(%rip),%xmm1
movsd  0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm1
addsd  0xdca(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  0xdc6(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  0xdc2(%rip),%xmm1
divsd  %xmm3,%xmm1
addsd  %xmm1,%xmm0
add    $0x28,%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
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store double %0, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
%10 = load double, double* %3
%11 = fptosi double %10 to i32
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = sitofp i32 %13 to double
%15 = load double, double* %3
%16 = fcmp oeq double %14, %15
br i1 %16, label %17, label %28
17: ; preds = %1
%18 = load i32, i32* %9
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* %9
%25 = call i64 @factorial(i32 %24)
%26 = sitofp i64 %25 to double
%27 = call double @log(double %26)
store double %27, double* %2
br label %78
28: ; preds = %20, %17, %1
%29 = load double, double* %3
%30 = fcmp ogt double %29, 0.000000e+00
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load double, double* %3
%34 = fcmp olt double %33, 7.000000e+00
br i1 %34, label %35, label %51
35: ; preds = %28
store double 1.000000e+00, double* %4
%36 = load double, double* %3
%37 = fsub double %36, 1.000000e+00
store double %37, double* %6
br label %38
38: ; preds = %42, %35
%39 = load double, double* %6
%40 = fadd double %39, 1.000000e+00
store double %40, double* %6
%41 = fcmp olt double %40, 7.000000e+00
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load double, double* %6
%44 = load double, double* %4
%45 = fmul double %44, %43
store double %45, double* %4
br label %38
46: ; preds = %38
%47 = load double, double* %6
store double %47, double* %3
%48 = load double, double* %4
%49 = call double @log(double %48)
%50 = fneg double %49
store double %50, double* %4
br label %51
51: ; preds = %46, %28
%52 = load double, double* %3
%53 = load double, double* %3
%54 = fmul double %52, %53
%55 = fdiv double 1.000000e+00, %54
store double %55, double* %6
%56 = load double, double* %5
%57 = load double, double* %4
%58 = fadd double %56, %57
%59 = load double, double* %3
%60 = fsub double %59, 5.000000e-01
%61 = load double, double* %3
%62 = call double @log(double %61)
%63 = call double @llvm.fmuladd.f64(double %60, double %62, double %58)
%64 = load double, double* %3
%65 = fsub double %63, %64
%66 = fadd double %65, 0x3FED67F1C864BEB7
store double %66, double* %7
%67 = load double, double* %6
%68 = call double @llvm.fmuladd.f64(double 0xBF438138138134A5, double %67, double 0x3F4A01A01A01A789)
%69 = load double, double* %6
%70 = call double @llvm.fmuladd.f64(double %68, double %69, double 0xBF66C16C16C16E17)
%71 = load double, double* %6
%72 = call double @llvm.fmuladd.f64(double %70, double %71, double 0x3FB555555555553D)
store double %72, double* %8
%73 = load double, double* %7
%74 = load double, double* %8
%75 = load double, double* %3
%76 = fdiv double %74, %75
%77 = fadd double %73, %76
store double %77, double* %2
br label %78
78: ; preds = %51, %23
%79 = load double, double* %2
ret double %79
}

LLVM IR (-O2):
define double @LnGamma(double %0) {
%2 = fptosi double %0 to i32
%3 = add nsw i32 %2, -1
%4 = sitofp i32 %3 to double
%5 = fcmp oeq double %4, %0
%6 = icmp sgt i32 %2, 1
%7 = select i1 %5, i1 %6, i1 false
%8 = icmp slt i32 %2, 11
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = tail call i64 @factorial(i32 %3)
%12 = sitofp i64 %11 to double
%13 = tail call double @log(double %12)
br label %49
14: ; preds = %1
%15 = fcmp ogt double %0, 0.000000e+00
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = fcmp olt double %0, 7.000000e+00
br i1 %18, label %19, label %34
19: ; preds = %14
%20 = fadd double %0, -1.000000e+00
%21 = fadd double %20, 1.000000e+00
%22 = fcmp olt double %21, 7.000000e+00
br i1 %22, label %23, label %29
23: ; preds = %19, %23
%24 = phi double [ %27, %23 ], [ %21, %19 ]
%25 = phi double [ %26, %23 ], [ 1.000000e+00, %19 ]
%26 = fmul double %25, %24
%27 = fadd double %24, 1.000000e+00
%28 = fcmp olt double %27, 7.000000e+00
br i1 %28, label %23, label %29
29: ; preds = %23, %19
%30 = phi double [ 1.000000e+00, %19 ], [ %26, %23 ]
%31 = phi double [ %21, %19 ], [ %27, %23 ]
%32 = tail call double @log(double %30)
%33 = fsub double 0.000000e+00, %32
br label %34
34: ; preds = %29, %14
%35 = phi double [ %33, %29 ], [ 0.000000e+00, %14 ]
%36 = phi double [ %31, %29 ], [ %0, %14 ]
%37 = fmul double %36, %36
%38 = fdiv double 1.000000e+00, %37
%39 = fadd double %36, -5.000000e-01
%40 = tail call double @log(double %36)
%41 = tail call double @llvm.fmuladd.f64(double %39, double %40, double %35)
%42 = fsub double %41, %36
%43 = fadd double %42, 0x3FED67F1C864BEB7
%44 = tail call double @llvm.fmuladd.f64(double %38, double 0xBF438138138134A5, double 0x3F4A01A01A01A789)
%45 = tail call double @llvm.fmuladd.f64(double %44, double %38, double 0xBF66C16C16C16E17)
%46 = tail call double @llvm.fmuladd.f64(double %45, double %38, double 0x3FB555555555553D)
%47 = fdiv double %46, %36
%48 = fadd double %43, %47
br label %49
49: ; preds = %34, %10
%50 = phi double [ %13, %10 ], [ %48, %34 ]
ret double %50
}