#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 ln_gamma(double x) {
  double f, z;
  assert(x > 0.0);
  if (x < 7.0) {
    f = 1.0;
    z = x;
    while (z < 7.0) {
      f *= z;
      z += 1.0;
    }
    x = z;
    f = -log(f);
  } else {
    f = 0.0;
  }
  z = 1.0 / (x * x);
  return f + (x - 0.5) * log(x) - x + 0.918938533204673 +
         (((-0.000595238095238 * z + 0.000793650793651) * z -
           0.002777777777778) *
              z +
          0.083333333333333) /
             x;
}


x86 assembly (clang, -O0):
<ln_gamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  0xeb2(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11de <ln_gamma+0xbe>
movsd  0xea7(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe88(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11a9 <ln_gamma+0x89>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe6e(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1170 <ln_gamma+0x50>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11e6 <ln_gamma+0xc6>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movsd  0xe10(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe20(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x28(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  0xde3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xdc2(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xdbe(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd99(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd7c(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  -0x8(%rbp),%xmm1
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ln_gamma>:
sub    $0x38,%rsp
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm1,%xmm1
xor    %edi,%edi
ucomisd %xmm1,%xmm0
seta   %dil
call   1030 <assert@plt>
movsd  0x8(%rsp),%xmm3
movsd  0xeb5(%rip),%xmm1
ucomisd %xmm3,%xmm1
jbe    1189 <ln_gamma+0x69>
movsd  0xeaf(%rip),%xmm2
movapd %xmm2,%xmm0
nopl   (%rax)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm1
ja     1160 <ln_gamma+0x40>
movsd  %xmm3,0x8(%rsp)
call   1040 <log@plt>
movsd  0x8(%rsp),%xmm3
xorpd  0xeb9(%rip),%xmm0
jmp    118d <ln_gamma+0x6d>
xorpd  %xmm0,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  %xmm3,0x8(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movsd  0xe5f(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0xe55(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
call   1040 <log@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  0x8(%rsp),%xmm3
subsd  %xmm3,%xmm0
addsd  0xe2c(%rip),%xmm0
movsd  0xe2c(%rip),%xmm1
movsd  0x18(%rsp),%xmm2
mulsd  %xmm2,%xmm1
addsd  0xe22(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  0xe1e(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  0xe1a(%rip),%xmm1
divsd  %xmm3,%xmm1
addsd  %xmm1,%xmm0
add    $0x38,%rsp
ret

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

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