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


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,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11ae <LnGamma+0x6e>
jp     11ae <LnGamma+0x6e>
cmpl   $0x0,-0x34(%rbp)
jle    11ae <LnGamma+0x6e>
cmpl   $0xa,-0x34(%rbp)
jge    11ae <LnGamma+0x6e>
mov    -0x34(%rbp),%edi
call   1040 <factorial@plt>
cvtsi2sd %rax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x30(%rbp)
jmp    13d8 <LnGamma+0x298>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1275 <LnGamma+0x135>
lea    0xe85(%rip),%rdi
call   1050 <error2@plt>
cvttsd2si -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
subsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1207 <LnGamma+0xc7>
jp     1207 <LnGamma+0xc7>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
movsd  0xe43(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13e2 <LnGamma+0x2a2>
movsd  0xdf1(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    124c <LnGamma+0x10c>
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdc3(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1214 <LnGamma+0xd4>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1266 <LnGamma+0x126>
lea    0xe19(%rip),%rdi
call   1050 <error2@plt>
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xd8b(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1313 <LnGamma+0x1d3>
movsd  0xd70(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xd5e(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xd4d(%rip),%xmm1
addsd  -0x28(%rbp),%xmm1
movsd  %xmm1,-0x28(%rbp)
movsd  0xd43(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12e3 <LnGamma+0x1a3>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12ab <LnGamma+0x16b>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <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  0xcdb(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xcee(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xcb1(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xc90(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xc8c(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xc67(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xc4a(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LnGamma>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm3
cvttsd2si %xmm0,%ebx
lea    -0x1(%rbx),%edi
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
ucomisd %xmm3,%xmm0
jne    1180 <LnGamma+0x40>
jp     1180 <LnGamma+0x40>
cmp    $0x2,%ebx
jl     1180 <LnGamma+0x40>
cmp    $0xa,%ebx
jg     1180 <LnGamma+0x40>
call   1040 <factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
add    $0x20,%rsp
pop    %rbx
jmp    1060 <log@plt>
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jae    1199 <LnGamma+0x59>
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
jmp    1253 <LnGamma+0x113>
lea    0xec0(%rip),%rdi
movsd  %xmm3,(%rsp)
call   1050 <error2@plt>
movsd  (%rsp),%xmm2
cvtsi2sd %ebx,%xmm1
subsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    11dc <LnGamma+0x9c>
jp     11dc <LnGamma+0x9c>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
movsd  0xe31(%rip),%xmm0
jmp    135a <LnGamma+0x21a>
ucomisd %xmm2,%xmm0
jbe    1237 <LnGamma+0xf7>
movsd  0xe16(%rip),%xmm3
xorpd  %xmm1,%xmm1
movapd %xmm3,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
divsd  %xmm2,%xmm0
addsd  %xmm3,%xmm2
ucomisd %xmm2,%xmm1
ja     1200 <LnGamma+0xc0>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movsd  %xmm2,(%rsp)
jbe    123f <LnGamma+0xff>
lea    0xe6e(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1050 <error2@plt>
movsd  0x8(%rsp),%xmm0
jmp    123f <LnGamma+0xff>
movsd  0xdc1(%rip),%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm3
xorpd  %xmm0,%xmm0
movsd  0xdb5(%rip),%xmm1
ucomisd %xmm3,%xmm1
jbe    12b5 <LnGamma+0x175>
addsd  0xd9f(%rip),%xmm3
movsd  0xd8f(%rip),%xmm0
addsd  %xmm0,%xmm3
ucomisd %xmm3,%xmm1
jbe    129e <LnGamma+0x15e>
movsd  0xd7d(%rip),%xmm2
movapd %xmm2,%xmm0
nopw   0x0(%rax,%rax,1)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm1
ja     1290 <LnGamma+0x150>
movsd  %xmm3,(%rsp)
call   1060 <log@plt>
movsd  (%rsp),%xmm3
xorpd  0xd9b(%rip),%xmm0
movsd  %xmm3,(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movsd  0xd26(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0xd2c(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
call   1060 <log@plt>
movapd %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
addsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm3
subsd  %xmm3,%xmm1
addsd  0xd00(%rip),%xmm1
movsd  0xd00(%rip),%xmm0
movsd  0x18(%rsp),%xmm2
mulsd  %xmm2,%xmm0
addsd  0xcf6(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xcf2(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xcee(%rip),%xmm0
divsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
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
%7 = alloca double
%8 = alloca i32
store double %0, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
%9 = load double, double* %3
%10 = fptosi double %9 to i32
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = sitofp i32 %12 to double
%14 = load double, double* %3
%15 = fcmp oeq double %13, %14
br i1 %15, label %16, label %27
16: ; preds = %1
%17 = load i32, i32* %8
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 10
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %8
%24 = call i64 @factorial(i32 %23)
%25 = sitofp i64 %24 to double
%26 = call double @log(double %25)
store double %26, double* %7
br label %103
27: ; preds = %19, %16, %1
%28 = load double, double* %3
%29 = fcmp ole double %28, 0.000000e+00
br i1 %29, label %30, label %59
30: ; preds = %27
%31 = call i32 @error2(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%32 = load double, double* %3
%33 = fptosi double %32 to i32
%34 = sitofp i32 %33 to double
%35 = load double, double* %3
%36 = fsub double %34, %35
%37 = fcmp oeq double %36, 0.000000e+00
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = 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 %105
40: ; preds = %30
store double 1.000000e+00, double* %5
br label %41
41: ; preds = %48, %40
%42 = load double, double* %3
%43 = fcmp olt double %42, 0.000000e+00
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = load double, double* %3
%46 = load double, double* %5
%47 = fdiv double %46, %45
store double %47, double* %5
br label %48
48: ; preds = %44
%49 = load double, double* %3
%50 = fadd double %49, 1.000000e+00
store double %50, double* %3
br label %41
51: ; preds = %41
%52 = load double, double* %5
%53 = fcmp olt double %52, 0.000000e+00
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @error2(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %56
56: ; preds = %54, %51
%57 = load double, double* %5
%58 = call double @log(double %57)
store double %58, double* %5
br label %59
59: ; preds = %56, %27
%60 = load double, double* %3
%61 = fcmp olt double %60, 7.000000e+00
br i1 %61, label %62, label %78
62: ; preds = %59
store double 1.000000e+00, double* %4
%63 = load double, double* %3
%64 = fsub double %63, 1.000000e+00
store double %64, double* %6
br label %65
65: ; preds = %69, %62
%66 = load double, double* %6
%67 = fadd double %66, 1.000000e+00
store double %67, double* %6
%68 = fcmp olt double %67, 7.000000e+00
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = load double, double* %6
%71 = load double, double* %4
%72 = fmul double %71, %70
store double %72, double* %4
br label %65
73: ; preds = %65
%74 = load double, double* %6
store double %74, double* %3
%75 = load double, double* %4
%76 = call double @log(double %75)
%77 = fneg double %76
store double %77, double* %4
br label %78
78: ; preds = %73, %59
%79 = load double, double* %3
%80 = load double, double* %3
%81 = fmul double %79, %80
%82 = fdiv double 1.000000e+00, %81
store double %82, double* %6
%83 = load double, double* %5
%84 = load double, double* %4
%85 = fadd double %83, %84
%86 = load double, double* %3
%87 = fsub double %86, 5.000000e-01
%88 = load double, double* %3
%89 = call double @log(double %88)
%90 = call double @llvm.fmuladd.f64(double %87, double %89, double %85)
%91 = load double, double* %3
%92 = fsub double %90, %91
%93 = fadd double %92, 0x3FED67F1C864BEB7
%94 = load double, double* %6
%95 = call double @llvm.fmuladd.f64(double 0xBF438138138134A5, double %94, double 0x3F4A01A01A01A789)
%96 = load double, double* %6
%97 = call double @llvm.fmuladd.f64(double %95, double %96, double 0xBF66C16C16C16E17)
%98 = load double, double* %6
%99 = call double @llvm.fmuladd.f64(double %97, double %98, double 0x3FB555555555553D)
%100 = load double, double* %3
%101 = fdiv double %99, %100
%102 = fadd double %93, %101
store double %102, double* %7
br label %103
103: ; preds = %78, %22
%104 = load double, double* %7
store double %104, double* %2
br label %105
105: ; preds = %103, %38
%106 = load double, double* %2
ret double %106
}

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 = 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 %74
14: ; preds = %1
%15 = fcmp ugt double %0, 0.000000e+00
br i1 %15, label %39, label %16
16: ; preds = %14
%17 = tail call i32 @error2(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%18 = sitofp i32 %2 to double
%19 = fsub double %18, %0
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = fcmp olt double %0, 0.000000e+00
br i1 %22, label %25, label %35
23: ; preds = %16
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %74
25: ; preds = %21, %25
%26 = phi double [ %28, %25 ], [ 1.000000e+00, %21 ]
%27 = phi double [ %29, %25 ], [ %0, %21 ]
%28 = fdiv double %26, %27
%29 = fadd double %27, 1.000000e+00
%30 = fcmp olt double %29, 0.000000e+00
br i1 %30, label %25, label %31
31: ; preds = %25
%32 = fcmp olt double %28, 0.000000e+00
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = tail call i32 @error2(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %21, %33, %31
%36 = phi double [ %28, %33 ], [ %28, %31 ], [ 1.000000e+00, %21 ]
%37 = phi double [ %29, %33 ], [ %29, %31 ], [ %0, %21 ]
%38 = tail call double @log(double %36)
br label %39
39: ; preds = %35, %14
%40 = phi double [ %37, %35 ], [ %0, %14 ]
%41 = phi double [ %38, %35 ], [ 0.000000e+00, %14 ]
%42 = fcmp olt double %40, 7.000000e+00
br i1 %42, label %43, label %58
43: ; preds = %39
%44 = fadd double %40, -1.000000e+00
%45 = fadd double %44, 1.000000e+00
%46 = fcmp olt double %45, 7.000000e+00
br i1 %46, label %47, label %53
47: ; preds = %43, %47
%48 = phi double [ %51, %47 ], [ %45, %43 ]
%49 = phi double [ %50, %47 ], [ 1.000000e+00, %43 ]
%50 = fmul double %49, %48
%51 = fadd double %48, 1.000000e+00
%52 = fcmp olt double %51, 7.000000e+00
br i1 %52, label %47, label %53
53: ; preds = %47, %43
%54 = phi double [ 1.000000e+00, %43 ], [ %50, %47 ]
%55 = phi double [ %45, %43 ], [ %51, %47 ]
%56 = tail call double @log(double %54)
%57 = fneg double %56
br label %58
58: ; preds = %53, %39
%59 = phi double [ %55, %53 ], [ %40, %39 ]
%60 = phi double [ %57, %53 ], [ 0.000000e+00, %39 ]
%61 = fmul double %59, %59
%62 = fdiv double 1.000000e+00, %61
%63 = fadd double %41, %60
%64 = fadd double %59, -5.000000e-01
%65 = tail call double @log(double %59)
%66 = tail call double @llvm.fmuladd.f64(double %64, double %65, double %63)
%67 = fsub double %66, %59
%68 = fadd double %67, 0x3FED67F1C864BEB7
%69 = tail call double @llvm.fmuladd.f64(double %62, double 0xBF438138138134A5, double 0x3F4A01A01A01A789)
%70 = tail call double @llvm.fmuladd.f64(double %69, double %62, double 0xBF66C16C16C16E17)
%71 = tail call double @llvm.fmuladd.f64(double %70, double %62, double 0x3FB555555555553D)
%72 = fdiv double %71, %59
%73 = fadd double %68, %72
br label %74
74: ; preds = %10, %58, %23
%75 = phi double [ -1.000000e+00, %23 ], [ %13, %10 ], [ %73, %58 ]
ret double %75
}