#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 DBL_MAX;
double exp(int /*<<< orphan*/);
scalar_t__ floor(double);
int /*<<< orphan*/ lda_lgamma(double);
double lda_gamma(double x) {
  if (x < 0.001)
    return 1.0 / (x * (1.0 + 0.577215664901532860606512090 * x));
  if (x < 12.0) {
    static const double p[] = {
        -1.71618513886549492533811E+0, 2.47656508055759199108314E+1,
        -3.79804256470945635097577E+2, 6.29331155312818442661052E+2,
        8.66966202790413211295064E+2,  -3.14512729688483675254357E+4,
        -3.61444134186911729807069E+4, 6.64561438202405440627855E+4};
    static const double q[] = {
        -3.08402300119738975254353E+1, 3.15350626979604161529144E+2,
        -1.01515636749021914166146E+3, -3.10777167157231109440444E+3,
        2.25381184209801510330112E+4,  4.75584627752788110767815E+3,
        -1.34659959864969306392456E+5, -1.15132259675553483497211E+5};
    double den, num, result, z;
    double y = x;
    int i, n = 0;
    int arg_was_less_than_one = (y < 1.0);
    if (arg_was_less_than_one)
      y += 1.0;
    else {
      n = (int)floor(y) - 1;
      y -= n;
    }
    num = 0.0;
    den = 1.0;
    z = y - 1;
    for (i = 0; i < 8; i++) {
      num = (num + p[i]) * z;
      den = den * z + q[i];
    }
    result = num / den + 1.0;
    if (arg_was_less_than_one)
      result /= (y - 1.0);
    else
      for (i = 0; i < n; i++, y++)
        result *= y;
    return result;
  }
  if (x > 171.624)
    return 2 * DBL_MAX;
  return exp(lda_lgamma(x));
}


x86 assembly (clang, -O0):
<lda_gamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xebb(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    118c <lda_gamma+0x5c>
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  0xebe(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xeaa(%rip),%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe9a(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1382 <lda_gamma+0x252>
movsd  0xe74(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    133b <lda_gamma+0x20b>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
movsd  0xe60(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     11e9 <lda_gamma+0xb9>
movsd  0xe3e(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    120c <lda_gamma+0xdc>
movsd  -0x38(%rbp),%xmm0
call   1050 <floor@plt>
sub    $0x1,%eax
mov    %eax,-0x40(%rbp)
cvtsi2sdl -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdfc(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xdea(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x8,-0x3c(%rbp)
jge    129c <lda_gamma+0x16c>
movsd  -0x20(%rbp),%xmm0
movslq -0x3c(%rbp),%rcx
lea    0xdd8(%rip),%rax
addsd  (%rax,%rcx,8),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movslq -0x3c(%rbp),%rcx
lea    0xdf4(%rip),%rax
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    123e <lda_gamma+0x10e>
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xd6a(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     12e5 <lda_gamma+0x1b5>
movsd  -0x38(%rbp),%xmm1
movsd  0xd4a(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    132c <lda_gamma+0x1fc>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1327 <lda_gamma+0x1f7>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsd  0xd00(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12ec <lda_gamma+0x1bc>
jmp    132c <lda_gamma+0x1fc>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1382 <lda_gamma+0x252>
movsd  -0x10(%rbp),%xmm0
movsd  0xcc8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    136c <lda_gamma+0x23c>
mov    0x2c87(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1382 <lda_gamma+0x252>
movsd  -0x10(%rbp),%xmm0
call   1040 <lda_lgamma@plt>
mov    %eax,%edi
call   1030 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lda_gamma>:
push   %rax
movapd %xmm0,%xmm2
movsd  0xec3(%rip),%xmm0
ucomisd %xmm2,%xmm0
jbe    1165 <lda_gamma+0x35>
movsd  0xf5d(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xec1(%rip),%xmm0
addsd  %xmm0,%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
pop    %rax
ret
movsd  0xe9b(%rip),%xmm0
ucomisd %xmm2,%xmm0
jbe    1191 <lda_gamma+0x61>
movsd  0xe9d(%rip),%xmm4
ucomisd %xmm2,%xmm4
jbe    11b6 <lda_gamma+0x86>
movsd  0xe8f(%rip),%xmm1
addsd  %xmm2,%xmm1
xor    %eax,%eax
jmp    11e3 <lda_gamma+0xb3>
ucomisd 0xe77(%rip),%xmm2
jbe    12c3 <lda_gamma+0x193>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
jmp    134d <lda_gamma+0x21d>
movapd %xmm2,%xmm0
movsd  %xmm2,(%rsp)
call   1050 <floor@plt>
movsd  (%rsp),%xmm2
movsd  0xe47(%rip),%xmm4
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
ucomisd %xmm2,%xmm4
movsd  0xe31(%rip),%xmm2
addsd  %xmm1,%xmm2
movsd  0xe2d(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xe29(%rip),%xmm3
addsd  %xmm2,%xmm3
addsd  0xe25(%rip),%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm3
addsd  0xe1d(%rip),%xmm3
addsd  0xe1d(%rip),%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm3
addsd  0xe15(%rip),%xmm3
addsd  0xe15(%rip),%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm3
addsd  0xe0d(%rip),%xmm3
addsd  0xe0d(%rip),%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm3
addsd  0xe05(%rip),%xmm3
addsd  0xe05(%rip),%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm3
addsd  0xdfd(%rip),%xmm3
addsd  0xdfd(%rip),%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm3
addsd  0xdf5(%rip),%xmm3
addsd  0xdf5(%rip),%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm3
addsd  0xded(%rip),%xmm3
divsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
jbe    12d4 <lda_gamma+0x1a4>
divsd  %xmm2,%xmm0
pop    %rax
ret
movapd %xmm2,%xmm0
call   1040 <lda_lgamma@plt>
mov    %eax,%edi
pop    %rax
jmp    1030 <exp@plt>
test   %eax,%eax
jle    134d <lda_gamma+0x21d>
lea    -0x1(%rax),%edx
mov    %eax,%ecx
and    $0x7,%ecx
cmp    $0x7,%edx
jb     1335 <lda_gamma+0x205>
and    $0xfffffff8,%eax
nopl   0x0(%rax,%rax,1)
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
add    $0xfffffff8,%eax
jne    12f0 <lda_gamma+0x1c0>
test   %ecx,%ecx
je     134d <lda_gamma+0x21d>
nopl   0x0(%rax)
mulsd  %xmm1,%xmm0
addsd  %xmm4,%xmm1
add    $0xffffffff,%ecx
jne    1340 <lda_gamma+0x210>
pop    %rax
ret

LLVM IR (-O0):
@lda_gamma.p = internal constant [8 x double] [double 0xBFFB757E8C54EFB2, double 0x4038C401B0F21AC9, double 0xC077BCDE3C0884ED, double 0x4083AAA634C1B39D, double 0x408B17BAC8875108, double 0xC0DEB6D178525524, double 0xC0E1A60D3AB9D5C5, double 0x40F039824D1673DA]
@lda_gamma.q = internal constant [8 x double] [double 0xC03ED71950668BAB, double 0x4073B59C2B0927EC, double 0xC08FB9403D994531, double 0xC0A8478B18894CA8, double 0x40D602879435973A, double 0x40B293D8A5A4E197, double 0xC100701FADCDAF5E, double 0xC0FC1BC427A18D9D]
@DBL_MAX = global i32 0
define double @lda_gamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store double %0, double* %3
%12 = load double, double* %3
%13 = fcmp olt double %12, 1.000000e-03
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = load double, double* %3
%16 = load double, double* %3
%17 = call double @llvm.fmuladd.f64(double 0x3FE2788CFC6FB619, double %16, double 1.000000e+00)
%18 = fmul double %15, %17
%19 = fdiv double 1.000000e+00, %18
store double %19, double* %2
br label %107
20: ; preds = %1
%21 = load double, double* %3
%22 = fcmp olt double %21, 1.200000e+01
br i1 %22, label %23, label %96
23: ; preds = %20
%24 = load double, double* %3
store double %24, double* %8
store i32 0, i32* %10
%25 = load double, double* %8
%26 = fcmp olt double %25, 1.000000e+00
%27 = zext i1 %26 to i32
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load double, double* %8
%32 = fadd double %31, 1.000000e+00
store double %32, double* %8
br label %42
33: ; preds = %23
%34 = load double, double* %8
%35 = call i64 @floor(double %34)
%36 = trunc i64 %35 to i32
%37 = sub nsw i32 %36, 1
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = sitofp i32 %38 to double
%40 = load double, double* %8
%41 = fsub double %40, %39
store double %41, double* %8
br label %42
42: ; preds = %33, %30
store double 0.000000e+00, double* %5
store double 1.000000e+00, double* %4
%43 = load double, double* %8
%44 = fsub double %43, 1.000000e+00
store double %44, double* %7
store i32 0, i32* %9
br label %45
45: ; preds = %64, %42
%46 = load i32, i32* %9
%47 = icmp slt i32 %46, 8
br i1 %47, label %48, label %67
48: ; preds = %45
%49 = load double, double* %5
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [8 x double], [8 x double]* @lda_gamma.p, i64 0, i64 %51
%53 = load double, double* %52
%54 = fadd double %49, %53
%55 = load double, double* %7
%56 = fmul double %54, %55
store double %56, double* %5
%57 = load double, double* %4
%58 = load double, double* %7
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [8 x double], [8 x double]* @lda_gamma.q, i64 0, i64 %60
%62 = load double, double* %61
%63 = call double @llvm.fmuladd.f64(double %57, double %58, double %62)
store double %63, double* %4
br label %64
64: ; preds = %48
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %45
67: ; preds = %45
%68 = load double, double* %5
%69 = load double, double* %4
%70 = fdiv double %68, %69
%71 = fadd double %70, 1.000000e+00
store double %71, double* %6
%72 = load i32, i32* %11
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %79
74: ; preds = %67
%75 = load double, double* %8
%76 = fsub double %75, 1.000000e+00
%77 = load double, double* %6
%78 = fdiv double %77, %76
store double %78, double* %6
br label %94
79: ; preds = %67
store i32 0, i32* %9
br label %80
80: ; preds = %88, %79
%81 = load i32, i32* %9
%82 = load i32, i32* %10
%83 = icmp slt i32 %81, %82
br i1 %83, label %84, label %93
84: ; preds = %80
%85 = load double, double* %8
%86 = load double, double* %6
%87 = fmul double %86, %85
store double %87, double* %6
br label %88
88: ; preds = %84
%89 = load i32, i32* %9
%90 = add nsw i32 %89, 1
store i32 %90, i32* %9
%91 = load double, double* %8
%92 = fadd double %91, 1.000000e+00
store double %92, double* %8
br label %80
93: ; preds = %80
br label %94
94: ; preds = %93, %74
%95 = load double, double* %6
store double %95, double* %2
br label %107
96: ; preds = %20
%97 = load double, double* %3
%98 = fcmp ogt double %97, 1.716240e+02
br i1 %98, label %99, label %103
99: ; preds = %96
%100 = load i32, i32* @DBL_MAX
%101 = mul nsw i32 2, %100
%102 = sitofp i32 %101 to double
store double %102, double* %2
br label %107
103: ; preds = %96
%104 = load double, double* %3
%105 = call i32 @lda_lgamma(double %104)
%106 = call double @exp(i32 %105)
store double %106, double* %2
br label %107
107: ; preds = %103, %99, %94, %14
%108 = load double, double* %2
ret double %108
}

LLVM IR (-O2):
@DBL_MAX = global i32 0
define double @lda_gamma(double %0) {
%2 = fcmp olt double %0, 1.000000e-03
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = tail call double @llvm.fmuladd.f64(double %0, double 0x3FE2788CFC6FB619, double 1.000000e+00)
%5 = fmul double %4, %0
%6 = fdiv double 1.000000e+00, %5
br label %102
7: ; preds = %1
%8 = fcmp olt double %0, 1.200000e+01
br i1 %8, label %9, label %80
9: ; preds = %7
%10 = fcmp olt double %0, 1.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = fadd double %0, 1.000000e+00
br label %19
13: ; preds = %9
%14 = tail call i64 @floor(double %0)
%15 = trunc i64 %14 to i32
%16 = add nsw i32 %15, -1
%17 = sitofp i32 %16 to double
%18 = fsub double %0, %17
br label %19
19: ; preds = %13, %11
%20 = phi double [ %12, %11 ], [ %18, %13 ]
%21 = phi i32 [ 0, %11 ], [ %16, %13 ]
%22 = fadd double %20, -1.000000e+00
%23 = fmul double %22, 0xBFFB757E8C54EFB2
%24 = fadd double %22, 0xC03ED71950668BAB
%25 = fadd double %23, 0x4038C401B0F21AC9
%26 = fmul double %22, %25
%27 = tail call double @llvm.fmuladd.f64(double %24, double %22, double 0x4073B59C2B0927EC)
%28 = fadd double %26, 0xC077BCDE3C0884ED
%29 = fmul double %22, %28
%30 = tail call double @llvm.fmuladd.f64(double %27, double %22, double 0xC08FB9403D994531)
%31 = fadd double %29, 0x4083AAA634C1B39D
%32 = fmul double %22, %31
%33 = tail call double @llvm.fmuladd.f64(double %30, double %22, double 0xC0A8478B18894CA8)
%34 = fadd double %32, 0x408B17BAC8875108
%35 = fmul double %22, %34
%36 = tail call double @llvm.fmuladd.f64(double %33, double %22, double 0x40D602879435973A)
%37 = fadd double %35, 0xC0DEB6D178525524
%38 = fmul double %22, %37
%39 = tail call double @llvm.fmuladd.f64(double %36, double %22, double 0x40B293D8A5A4E197)
%40 = fadd double %38, 0xC0E1A60D3AB9D5C5
%41 = fmul double %22, %40
%42 = tail call double @llvm.fmuladd.f64(double %39, double %22, double 0xC100701FADCDAF5E)
%43 = fadd double %41, 0x40F039824D1673DA
%44 = fmul double %22, %43
%45 = tail call double @llvm.fmuladd.f64(double %42, double %22, double 0xC0FC1BC427A18D9D)
%46 = fdiv double %44, %45
%47 = fadd double %46, 1.000000e+00
br i1 %10, label %56, label %48
48: ; preds = %19
%49 = icmp sgt i32 %21, 0
br i1 %49, label %50, label %102
50: ; preds = %48
%51 = add i32 %21, -1
%52 = and i32 %21, 7
%53 = icmp ult i32 %51, 7
br i1 %53, label %89, label %54
54: ; preds = %50
%55 = and i32 %21, -8
br label %58
56: ; preds = %19
%57 = fdiv double %47, %22
br label %102
58: ; preds = %58, %54
%59 = phi double [ %20, %54 ], [ %77, %58 ]
%60 = phi double [ %47, %54 ], [ %76, %58 ]
%61 = phi i32 [ 0, %54 ], [ %78, %58 ]
%62 = fmul double %60, %59
%63 = fadd double %59, 1.000000e+00
%64 = fmul double %62, %63
%65 = fadd double %63, 1.000000e+00
%66 = fmul double %64, %65
%67 = fadd double %65, 1.000000e+00
%68 = fmul double %66, %67
%69 = fadd double %67, 1.000000e+00
%70 = fmul double %68, %69
%71 = fadd double %69, 1.000000e+00
%72 = fmul double %70, %71
%73 = fadd double %71, 1.000000e+00
%74 = fmul double %72, %73
%75 = fadd double %73, 1.000000e+00
%76 = fmul double %74, %75
%77 = fadd double %75, 1.000000e+00
%78 = add i32 %61, 8
%79 = icmp eq i32 %78, %55
br i1 %79, label %89, label %58
80: ; preds = %7
%81 = fcmp ogt double %0, 1.716240e+02
br i1 %81, label %82, label %86
82: ; preds = %80
%83 = load i32, i32* @DBL_MAX
%84 = shl nsw i32 %83, 1
%85 = sitofp i32 %84 to double
br label %102
86: ; preds = %80
%87 = tail call i32 @lda_lgamma(double %0)
%88 = tail call double @exp(i32 %87)
br label %102
89: ; preds = %58, %50
%90 = phi double [ undef, %50 ], [ %76, %58 ]
%91 = phi double [ %20, %50 ], [ %77, %58 ]
%92 = phi double [ %47, %50 ], [ %76, %58 ]
%93 = icmp eq i32 %52, 0
br i1 %93, label %102, label %94
94: ; preds = %89, %94
%95 = phi double [ %99, %94 ], [ %91, %89 ]
%96 = phi double [ %98, %94 ], [ %92, %89 ]
%97 = phi i32 [ %100, %94 ], [ 0, %89 ]
%98 = fmul double %96, %95
%99 = fadd double %95, 1.000000e+00
%100 = add i32 %97, 1
%101 = icmp eq i32 %100, %52
br i1 %101, label %102, label %94
102: ; preds = %89, %94, %48, %56, %86, %82, %3
%103 = phi double [ %6, %3 ], [ %85, %82 ], [ %88, %86 ], [ %57, %56 ], [ %47, %48 ], [ %90, %89 ], [ %98, %94 ]
ret double %103
}