#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*/ error2(char *);
double log(double);
int /*<<< orphan*/ puts(char *);
double LnGamma(double x) {
  double f = 0, fneg = 0, z;
  if (x <= 0) {
    error2("lnGamma not implemented for x<0");
    if ((int)x - x == 0) {
      puts("lnGamma undefined");
      return (-1);
    }
    for (fneg = 1; x < 0; x++)
      fneg /= x;
    if (fneg < 0)
      error2("strange!! check lngamma");
    fneg = log(fneg);
  }
  if (x < 7) {
    f = 1;
    z = x - 1;
    while (++z < 7)
      f *= z;
    x = z;
    f = -log(f);
  }
  z = 1 / (x * x);
  return fneg + f + (x - 0.5) * log(x) - x + .918938533204673 +
         (((-.000595238095238 * z + .000793650793651) * z - .002777777777778) *
              z +
          .083333333333333) /
             x;
}


x86 assembly (clang, -O0):
<LnGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1214 <LnGamma+0xe4>
lea    0xee6(%rip),%rdi
call   1040 <error2@plt>
cvttsd2si -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
subsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a6 <LnGamma+0x76>
jp     11a6 <LnGamma+0x76>
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
movsd  0xea4(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1377 <LnGamma+0x247>
movsd  0xe52(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11eb <LnGamma+0xbb>
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe24(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11b3 <LnGamma+0x83>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1205 <LnGamma+0xd5>
lea    0xe7a(%rip),%rdi
call   1040 <error2@plt>
movsd  -0x20(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xdec(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    12b2 <LnGamma+0x182>
movsd  0xdd1(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdbf(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xdae(%rip),%xmm1
addsd  -0x28(%rbp),%xmm1
movsd  %xmm1,-0x28(%rbp)
movsd  0xda4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1282 <LnGamma+0x152>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    124a <LnGamma+0x11a>
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  0xd3c(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xd4f(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xd12(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xcf1(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xced(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xcc8(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xcab(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LnGamma>:
sub    $0x38,%rsp
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jae    1151 <LnGamma+0x21>
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
jmp    1205 <LnGamma+0xd5>
lea    0xf08(%rip),%rdi
movapd %xmm3,0x10(%rsp)
call   1040 <error2@plt>
movapd 0x10(%rsp),%xmm2
cvttpd2dq %xmm2,%xmm0
cvtdq2pd %xmm0,%xmm1
subsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    119a <LnGamma+0x6a>
jp     119a <LnGamma+0x6a>
lea    0xef8(%rip),%rdi
call   1030 <puts@plt>
movsd  0xe73(%rip),%xmm0
add    $0x38,%rsp
ret
ucomisd %xmm2,%xmm0
jbe    11e8 <LnGamma+0xb8>
movsd  0xe58(%rip),%xmm3
xorpd  %xmm1,%xmm1
movapd %xmm3,%xmm0
divsd  %xmm2,%xmm0
addsd  %xmm3,%xmm2
ucomisd %xmm2,%xmm1
ja     11b0 <LnGamma+0x80>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm2,0x10(%rsp)
jbe    11f0 <LnGamma+0xc0>
lea    0xebd(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1040 <error2@plt>
movsd  0x8(%rsp),%xmm0
jmp    11f0 <LnGamma+0xc0>
movsd  0xe10(%rip),%xmm0
call   1050 <log@plt>
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm3
xorpd  %xmm0,%xmm0
movsd  0xe03(%rip),%xmm1
ucomisd %xmm3,%xmm1
jbe    1267 <LnGamma+0x137>
addsd  0xded(%rip),%xmm3
movsd  0xddd(%rip),%xmm0
addsd  %xmm0,%xmm3
ucomisd %xmm3,%xmm1
jbe    124e <LnGamma+0x11e>
movsd  0xdcb(%rip),%xmm2
movapd %xmm2,%xmm0
nopl   0x0(%rax)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm1
ja     1240 <LnGamma+0x110>
movapd %xmm3,0x10(%rsp)
call   1050 <log@plt>
movapd 0x10(%rsp),%xmm3
xorpd  0xde9(%rip),%xmm0
movapd %xmm3,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movsd  0xd73(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x30(%rsp)
movsd  0xd79(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x28(%rsp)
movapd %xmm3,%xmm0
call   1050 <log@plt>
movapd %xmm0,%xmm1
mulsd  0x28(%rsp),%xmm1
addsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm3
subsd  %xmm3,%xmm1
addsd  0xd4c(%rip),%xmm1
movsd  0xd4c(%rip),%xmm0
movsd  0x30(%rsp),%xmm2
mulsd  %xmm2,%xmm0
addsd  0xd42(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xd3e(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xd3a(%rip),%xmm0
divsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"lnGamma not implemented for x<0\00"
@.str.1 = [18 x i8] c"lnGamma undefined\00"
@.str.2 = [24 x i8] c"strange!! check lngamma\00"
define double @LnGamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
%7 = load double, double* %3
%8 = fcmp ole double %7, 0.000000e+00
br i1 %8, label %9, label %38
9: ; preds = %1
%10 = call i32 @error2(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%11 = load double, double* %3
%12 = fptosi double %11 to i32
%13 = sitofp i32 %12 to double
%14 = load double, double* %3
%15 = fsub double %13, %14
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store double -1.000000e+00, double* %2
br label %82
19: ; preds = %9
store double 1.000000e+00, double* %5
br label %20
20: ; preds = %27, %19
%21 = load double, double* %3
%22 = fcmp olt double %21, 0.000000e+00
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load double, double* %3
%25 = load double, double* %5
%26 = fdiv double %25, %24
store double %26, double* %5
br label %27
27: ; preds = %23
%28 = load double, double* %3
%29 = fadd double %28, 1.000000e+00
store double %29, double* %3
br label %20
30: ; preds = %20
%31 = load double, double* %5
%32 = fcmp olt double %31, 0.000000e+00
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @error2(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = load double, double* %5
%37 = call double @log(double %36)
store double %37, double* %5
br label %38
38: ; preds = %35, %1
%39 = load double, double* %3
%40 = fcmp olt double %39, 7.000000e+00
br i1 %40, label %41, label %57
41: ; preds = %38
store double 1.000000e+00, double* %4
%42 = load double, double* %3
%43 = fsub double %42, 1.000000e+00
store double %43, double* %6
br label %44
44: ; preds = %48, %41
%45 = load double, double* %6
%46 = fadd double %45, 1.000000e+00
store double %46, double* %6
%47 = fcmp olt double %46, 7.000000e+00
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load double, double* %6
%50 = load double, double* %4
%51 = fmul double %50, %49
store double %51, double* %4
br label %44
52: ; preds = %44
%53 = load double, double* %6
store double %53, double* %3
%54 = load double, double* %4
%55 = call double @log(double %54)
%56 = fneg double %55
store double %56, double* %4
br label %57
57: ; preds = %52, %38
%58 = load double, double* %3
%59 = load double, double* %3
%60 = fmul double %58, %59
%61 = fdiv double 1.000000e+00, %60
store double %61, double* %6
%62 = load double, double* %5
%63 = load double, double* %4
%64 = fadd double %62, %63
%65 = load double, double* %3
%66 = fsub double %65, 5.000000e-01
%67 = load double, double* %3
%68 = call double @log(double %67)
%69 = call double @llvm.fmuladd.f64(double %66, double %68, double %64)
%70 = load double, double* %3
%71 = fsub double %69, %70
%72 = fadd double %71, 0x3FED67F1C864BEB7
%73 = load double, double* %6
%74 = call double @llvm.fmuladd.f64(double 0xBF438138138134A5, double %73, double 0x3F4A01A01A01A789)
%75 = load double, double* %6
%76 = call double @llvm.fmuladd.f64(double %74, double %75, double 0xBF66C16C16C16E17)
%77 = load double, double* %6
%78 = call double @llvm.fmuladd.f64(double %76, double %77, double 0x3FB555555555553D)
%79 = load double, double* %3
%80 = fdiv double %78, %79
%81 = fadd double %72, %80
store double %81, double* %2
br label %82
82: ; preds = %57, %17
%83 = load double, double* %2
ret double %83
}

LLVM IR (-O2):
@.str = [32 x i8] c"lnGamma not implemented for x<0\00"
@.str.1 = [18 x i8] c"lnGamma undefined\00"
@.str.2 = [24 x i8] c"strange!! check lngamma\00"
define double @LnGamma(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %27, label %3
3: ; preds = %1
%4 = tail call i32 @error2(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%5 = fptosi double %0 to i32
%6 = sitofp i32 %5 to double
%7 = fsub double %6, %0
%8 = fcmp oeq double %7, 0.000000e+00
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = fcmp olt double %0, 0.000000e+00
br i1 %10, label %13, label %23
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %62
13: ; preds = %9, %13
%14 = phi double [ %16, %13 ], [ 1.000000e+00, %9 ]
%15 = phi double [ %17, %13 ], [ %0, %9 ]
%16 = fdiv double %14, %15
%17 = fadd double %15, 1.000000e+00
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %13, label %19
19: ; preds = %13
%20 = fcmp olt double %16, 0.000000e+00
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = tail call i32 @error2(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %9, %21, %19
%24 = phi double [ %16, %21 ], [ %16, %19 ], [ 1.000000e+00, %9 ]
%25 = phi double [ %17, %21 ], [ %17, %19 ], [ %0, %9 ]
%26 = tail call double @log(double %24)
br label %27
27: ; preds = %23, %1
%28 = phi double [ %25, %23 ], [ %0, %1 ]
%29 = phi double [ %26, %23 ], [ 0.000000e+00, %1 ]
%30 = fcmp olt double %28, 7.000000e+00
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = fadd double %28, -1.000000e+00
%33 = fadd double %32, 1.000000e+00
%34 = fcmp olt double %33, 7.000000e+00
br i1 %34, label %35, label %41
35: ; preds = %31, %35
%36 = phi double [ %39, %35 ], [ %33, %31 ]
%37 = phi double [ %38, %35 ], [ 1.000000e+00, %31 ]
%38 = fmul double %37, %36
%39 = fadd double %36, 1.000000e+00
%40 = fcmp olt double %39, 7.000000e+00
br i1 %40, label %35, label %41
41: ; preds = %35, %31
%42 = phi double [ 1.000000e+00, %31 ], [ %38, %35 ]
%43 = phi double [ %33, %31 ], [ %39, %35 ]
%44 = tail call double @log(double %42)
%45 = fneg double %44
br label %46
46: ; preds = %41, %27
%47 = phi double [ %43, %41 ], [ %28, %27 ]
%48 = phi double [ %45, %41 ], [ 0.000000e+00, %27 ]
%49 = fmul double %47, %47
%50 = fdiv double 1.000000e+00, %49
%51 = fadd double %29, %48
%52 = fadd double %47, -5.000000e-01
%53 = tail call double @log(double %47)
%54 = tail call double @llvm.fmuladd.f64(double %52, double %53, double %51)
%55 = fsub double %54, %47
%56 = fadd double %55, 0x3FED67F1C864BEB7
%57 = tail call double @llvm.fmuladd.f64(double %50, double 0xBF438138138134A5, double 0x3F4A01A01A01A789)
%58 = tail call double @llvm.fmuladd.f64(double %57, double %50, double 0xBF66C16C16C16E17)
%59 = tail call double @llvm.fmuladd.f64(double %58, double %50, double 0x3FB555555555553D)
%60 = fdiv double %59, %47
%61 = fadd double %56, %60
br label %62
62: ; preds = %46, %11
%63 = phi double [ -1.000000e+00, %11 ], [ %61, %46 ]
ret double %63
}