#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;
  if ((double)nx == x && nx > 1 && nx < 12)
    lng = log((double)factorial(nx - 1));
  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
mov    %eax,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11ae <LnGamma+0x6e>
jp     11ae <LnGamma+0x6e>
cmpl   $0x1,-0x34(%rbp)
jle    11ae <LnGamma+0x6e>
cmpl   $0xc,-0x34(%rbp)
jge    11ae <LnGamma+0x6e>
mov    -0x34(%rbp),%edi
sub    $0x1,%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>:
sub    $0x38,%rsp
movapd %xmm0,%xmm3
cvttsd2si %xmm0,%edi
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm1
lea    -0x2(%rdi),%eax
cmp    $0x9,%eax
ja     117d <LnGamma+0x3d>
ucomisd %xmm3,%xmm1
jne    117d <LnGamma+0x3d>
jp     117d <LnGamma+0x3d>
add    $0xffffffff,%edi
call   1040 <factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
add    $0x38,%rsp
jmp    1060 <log@plt>
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jae    1195 <LnGamma+0x55>
xorpd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
jmp    1252 <LnGamma+0x112>
lea    0xec4(%rip),%rdi
movapd %xmm3,0x10(%rsp)
movapd %xmm1,(%rsp)
call   1050 <error2@plt>
movapd 0x10(%rsp),%xmm2
movapd (%rsp),%xmm1
subsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    11e0 <LnGamma+0xa0>
jp     11e0 <LnGamma+0xa0>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
movsd  0xe2d(%rip),%xmm0
add    $0x38,%rsp
ret
ucomisd %xmm2,%xmm0
jbe    1236 <LnGamma+0xf6>
movsd  0xe12(%rip),%xmm3
xorpd  %xmm1,%xmm1
movapd %xmm3,%xmm0
cs nopw 0x0(%rax,%rax,1)
divsd  %xmm2,%xmm0
addsd  %xmm3,%xmm2
ucomisd %xmm2,%xmm1
ja     1200 <LnGamma+0xc0>
movapd %xmm2,0x10(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    123e <LnGamma+0xfe>
lea    0xe6d(%rip),%rdi
movsd  %xmm0,(%rsp)
call   1050 <error2@plt>
movsd  (%rsp),%xmm0
jmp    123e <LnGamma+0xfe>
movsd  0xdc2(%rip),%xmm0
call   1060 <log@plt>
movsd  %xmm0,(%rsp)
movapd 0x10(%rsp),%xmm3
xorpd  %xmm0,%xmm0
movsd  0xdb6(%rip),%xmm1
ucomisd %xmm3,%xmm1
jbe    12b7 <LnGamma+0x177>
addsd  0xda0(%rip),%xmm3
movsd  0xd90(%rip),%xmm0
addsd  %xmm0,%xmm3
ucomisd %xmm3,%xmm1
jbe    129e <LnGamma+0x15e>
movsd  0xd7e(%rip),%xmm2
movapd %xmm2,%xmm0
cs nopw 0x0(%rax,%rax,1)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm1
ja     1290 <LnGamma+0x150>
movapd %xmm3,0x10(%rsp)
call   1060 <log@plt>
movapd 0x10(%rsp),%xmm3
xorpd  0xd99(%rip),%xmm0
movapd %xmm3,0x10(%rsp)
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movsd  0xd25(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x30(%rsp)
movsd  0xd2b(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x28(%rsp)
movapd %xmm3,%xmm0
call   1060 <log@plt>
movapd %xmm0,%xmm1
mulsd  0x28(%rsp),%xmm1
addsd  (%rsp),%xmm1
movapd 0x10(%rsp),%xmm3
subsd  %xmm3,%xmm1
addsd  0xcff(%rip),%xmm1
movsd  0xcff(%rip),%xmm0
movsd  0x30(%rsp),%xmm2
mulsd  %xmm2,%xmm0
addsd  0xcf5(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xcf1(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xced(%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
%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
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = sitofp i32 %11 to double
%13 = load double, double* %3
%14 = fcmp oeq double %12, %13
br i1 %14, label %15, label %27
15: ; preds = %1
%16 = load i32, i32* %8
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 12
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* %8
%23 = sub nsw i32 %22, 1
%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 = %18, %15, %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, %21
%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 = sitofp i32 %2 to double
%4 = fcmp oeq double %3, %0
%5 = add i32 %2, -2
%6 = icmp ult i32 %5, 10
%7 = and i1 %6, %4
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = add nsw i32 %2, -1
%10 = tail call i64 @factorial(i32 %9)
%11 = sitofp i64 %10 to double
%12 = tail call double @log(double %11)
br label %72
13: ; preds = %1
%14 = fcmp ugt double %0, 0.000000e+00
br i1 %14, label %37, label %15
15: ; preds = %13
%16 = tail call i32 @error2(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%17 = fsub double %3, %0
%18 = fcmp oeq double %17, 0.000000e+00
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = fcmp olt double %0, 0.000000e+00
br i1 %20, label %23, label %33
21: ; preds = %15
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %72
23: ; preds = %19, %23
%24 = phi double [ %26, %23 ], [ 1.000000e+00, %19 ]
%25 = phi double [ %27, %23 ], [ %0, %19 ]
%26 = fdiv double %24, %25
%27 = fadd double %25, 1.000000e+00
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %23, label %29
29: ; preds = %23
%30 = fcmp olt double %26, 0.000000e+00
br i1 %30, label %31, label %33
31: ; preds = %29
%32 = tail call i32 @error2(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %19, %31, %29
%34 = phi double [ %26, %31 ], [ %26, %29 ], [ 1.000000e+00, %19 ]
%35 = phi double [ %27, %31 ], [ %27, %29 ], [ %0, %19 ]
%36 = tail call double @log(double %34)
br label %37
37: ; preds = %33, %13
%38 = phi double [ %35, %33 ], [ %0, %13 ]
%39 = phi double [ %36, %33 ], [ 0.000000e+00, %13 ]
%40 = fcmp olt double %38, 7.000000e+00
br i1 %40, label %41, label %56
41: ; preds = %37
%42 = fadd double %38, -1.000000e+00
%43 = fadd double %42, 1.000000e+00
%44 = fcmp olt double %43, 7.000000e+00
br i1 %44, label %45, label %51
45: ; preds = %41, %45
%46 = phi double [ %49, %45 ], [ %43, %41 ]
%47 = phi double [ %48, %45 ], [ 1.000000e+00, %41 ]
%48 = fmul double %47, %46
%49 = fadd double %46, 1.000000e+00
%50 = fcmp olt double %49, 7.000000e+00
br i1 %50, label %45, label %51
51: ; preds = %45, %41
%52 = phi double [ 1.000000e+00, %41 ], [ %48, %45 ]
%53 = phi double [ %43, %41 ], [ %49, %45 ]
%54 = tail call double @log(double %52)
%55 = fneg double %54
br label %56
56: ; preds = %51, %37
%57 = phi double [ %53, %51 ], [ %38, %37 ]
%58 = phi double [ %55, %51 ], [ 0.000000e+00, %37 ]
%59 = fmul double %57, %57
%60 = fdiv double 1.000000e+00, %59
%61 = fadd double %39, %58
%62 = fadd double %57, -5.000000e-01
%63 = tail call double @log(double %57)
%64 = tail call double @llvm.fmuladd.f64(double %62, double %63, double %61)
%65 = fsub double %64, %57
%66 = fadd double %65, 0x3FED67F1C864BEB7
%67 = tail call double @llvm.fmuladd.f64(double %60, double 0xBF438138138134A5, double 0x3F4A01A01A01A789)
%68 = tail call double @llvm.fmuladd.f64(double %67, double %60, double 0xBF66C16C16C16E17)
%69 = tail call double @llvm.fmuladd.f64(double %68, double %60, double 0x3FB555555555553D)
%70 = fdiv double %69, %57
%71 = fadd double %66, %70
br label %72
72: ; preds = %8, %56, %21
%73 = phi double [ -1.000000e+00, %21 ], [ %12, %8 ], [ %71, %56 ]
ret double %73
}