#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*/ printf(char *, 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 >= 0 && nx <= 11)
    lng = log((double)factorial(nx - 1));
  else {
    if (x <= 0) {
      printf("LnGamma(%.6f) not implemented", x);
      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    11be <LnGamma+0x6e>
jp     11be <LnGamma+0x6e>
cmpl   $0x0,-0x34(%rbp)
jl     11be <LnGamma+0x6e>
cmpl   $0xb,-0x34(%rbp)
jg     11be <LnGamma+0x6e>
mov    -0x34(%rbp),%edi
sub    $0x1,%edi
call   1040 <factorial@plt>
cvtsi2sd %rax,%xmm0
call   1070 <log@plt>
movsd  %xmm0,-0x30(%rbp)
jmp    13ed <LnGamma+0x29d>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     128a <LnGamma+0x13a>
movsd  -0x10(%rbp),%xmm0
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
cvttsd2si -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
subsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    121c <LnGamma+0xcc>
jp     121c <LnGamma+0xcc>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
movsd  0xe2e(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13f7 <LnGamma+0x2a7>
movsd  0xddc(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1261 <LnGamma+0x111>
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdae(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1229 <LnGamma+0xd9>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    127b <LnGamma+0x12b>
lea    0xe02(%rip),%rdi
call   1060 <error2@plt>
movsd  -0x20(%rbp),%xmm0
call   1070 <log@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xd76(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1328 <LnGamma+0x1d8>
movsd  0xd5b(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xd49(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xd38(%rip),%xmm1
addsd  -0x28(%rbp),%xmm1
movsd  %xmm1,-0x28(%rbp)
movsd  0xd2e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12f8 <LnGamma+0x1a8>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12c0 <LnGamma+0x170>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1070 <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  0xcc6(%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  0xcd9(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <log@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xc9c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xc7b(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xc77(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xc52(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xc35(%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
cmp    $0xb,%edi
ja     118a <LnGamma+0x3a>
ucomisd %xmm3,%xmm1
jne    118a <LnGamma+0x3a>
jp     118a <LnGamma+0x3a>
add    $0xffffffff,%edi
call   1040 <factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
add    $0x38,%rsp
jmp    1070 <log@plt>
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jae    11a2 <LnGamma+0x52>
xorpd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
jmp    1262 <LnGamma+0x112>
lea    0xeb7(%rip),%rdi
movapd %xmm3,%xmm0
movapd %xmm3,0x10(%rsp)
movapd %xmm1,(%rsp)
call   1050 <printf@plt>
movapd 0x10(%rsp),%xmm2
movapd (%rsp),%xmm1
subsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    11f1 <LnGamma+0xa1>
jp     11f1 <LnGamma+0xa1>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
movsd  0xe1c(%rip),%xmm0
add    $0x38,%rsp
ret
ucomisd %xmm2,%xmm0
jbe    1246 <LnGamma+0xf6>
movsd  0xe01(%rip),%xmm3
xorpd  %xmm1,%xmm1
movapd %xmm3,%xmm0
nopw   0x0(%rax,%rax,1)
divsd  %xmm2,%xmm0
addsd  %xmm3,%xmm2
ucomisd %xmm2,%xmm1
ja     1210 <LnGamma+0xc0>
movapd %xmm2,0x10(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    124e <LnGamma+0xfe>
lea    0xe5b(%rip),%rdi
movsd  %xmm0,(%rsp)
call   1060 <error2@plt>
movsd  (%rsp),%xmm0
jmp    124e <LnGamma+0xfe>
movsd  0xdb2(%rip),%xmm0
call   1070 <log@plt>
movsd  %xmm0,(%rsp)
movapd 0x10(%rsp),%xmm3
xorpd  %xmm0,%xmm0
movsd  0xda6(%rip),%xmm1
ucomisd %xmm3,%xmm1
jbe    12c7 <LnGamma+0x177>
addsd  0xd90(%rip),%xmm3
movsd  0xd80(%rip),%xmm0
addsd  %xmm0,%xmm3
ucomisd %xmm3,%xmm1
jbe    12ae <LnGamma+0x15e>
movsd  0xd6e(%rip),%xmm2
movapd %xmm2,%xmm0
cs nopw 0x0(%rax,%rax,1)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm1
ja     12a0 <LnGamma+0x150>
movapd %xmm3,0x10(%rsp)
call   1070 <log@plt>
movapd 0x10(%rsp),%xmm3
xorpd  0xd89(%rip),%xmm0
movapd %xmm3,0x10(%rsp)
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movsd  0xd15(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x30(%rsp)
movsd  0xd1b(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x28(%rsp)
movapd %xmm3,%xmm0
call   1070 <log@plt>
movapd %xmm0,%xmm1
mulsd  0x28(%rsp),%xmm1
addsd  (%rsp),%xmm1
movapd 0x10(%rsp),%xmm3
subsd  %xmm3,%xmm1
addsd  0xcef(%rip),%xmm1
movsd  0xcef(%rip),%xmm0
movsd  0x30(%rsp),%xmm2
mulsd  %xmm2,%xmm0
addsd  0xce5(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xce1(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xcdd(%rip),%xmm0
divsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"LnGamma(%.6f) not implemented\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 sge i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i32, i32* %8
%20 = icmp sle i32 %19, 11
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 %104
27: ; preds = %18, %15, %1
%28 = load double, double* %3
%29 = fcmp ole double %28, 0.000000e+00
br i1 %29, label %30, label %60
30: ; preds = %27
%31 = load double, double* %3
%32 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %31)
%33 = load double, double* %3
%34 = fptosi double %33 to i32
%35 = sitofp i32 %34 to double
%36 = load double, double* %3
%37 = fsub double %35, %36
%38 = fcmp oeq double %37, 0.000000e+00
br i1 %38, label %39, label %41
39: ; preds = %30
%40 = 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 %106
41: ; preds = %30
store double 1.000000e+00, double* %5
br label %42
42: ; preds = %49, %41
%43 = load double, double* %3
%44 = fcmp olt double %43, 0.000000e+00
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load double, double* %3
%47 = load double, double* %5
%48 = fdiv double %47, %46
store double %48, double* %5
br label %49
49: ; preds = %45
%50 = load double, double* %3
%51 = fadd double %50, 1.000000e+00
store double %51, double* %3
br label %42
52: ; preds = %42
%53 = load double, double* %5
%54 = fcmp olt double %53, 0.000000e+00
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @error2(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
%58 = load double, double* %5
%59 = call double @log(double %58)
store double %59, double* %5
br label %60
60: ; preds = %57, %27
%61 = load double, double* %3
%62 = fcmp olt double %61, 7.000000e+00
br i1 %62, label %63, label %79
63: ; preds = %60
store double 1.000000e+00, double* %4
%64 = load double, double* %3
%65 = fsub double %64, 1.000000e+00
store double %65, double* %6
br label %66
66: ; preds = %70, %63
%67 = load double, double* %6
%68 = fadd double %67, 1.000000e+00
store double %68, double* %6
%69 = fcmp olt double %68, 7.000000e+00
br i1 %69, label %70, label %74
70: ; preds = %66
%71 = load double, double* %6
%72 = load double, double* %4
%73 = fmul double %72, %71
store double %73, double* %4
br label %66
74: ; preds = %66
%75 = load double, double* %6
store double %75, double* %3
%76 = load double, double* %4
%77 = call double @log(double %76)
%78 = fneg double %77
store double %78, double* %4
br label %79
79: ; preds = %74, %60
%80 = load double, double* %3
%81 = load double, double* %3
%82 = fmul double %80, %81
%83 = fdiv double 1.000000e+00, %82
store double %83, double* %6
%84 = load double, double* %5
%85 = load double, double* %4
%86 = fadd double %84, %85
%87 = load double, double* %3
%88 = fsub double %87, 5.000000e-01
%89 = load double, double* %3
%90 = call double @log(double %89)
%91 = call double @llvm.fmuladd.f64(double %88, double %90, double %86)
%92 = load double, double* %3
%93 = fsub double %91, %92
%94 = fadd double %93, 0x3FED67F1C864BEB7
%95 = load double, double* %6
%96 = call double @llvm.fmuladd.f64(double 0xBF438138138134A5, double %95, double 0x3F4A01A01A01A789)
%97 = load double, double* %6
%98 = call double @llvm.fmuladd.f64(double %96, double %97, double 0xBF66C16C16C16E17)
%99 = load double, double* %6
%100 = call double @llvm.fmuladd.f64(double %98, double %99, double 0x3FB555555555553D)
%101 = load double, double* %3
%102 = fdiv double %100, %101
%103 = fadd double %94, %102
store double %103, double* %7
br label %104
104: ; preds = %79, %21
%105 = load double, double* %7
store double %105, double* %2
br label %106
106: ; preds = %104, %39
%107 = load double, double* %2
ret double %107
}

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