#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 */
double log(double);
double loggamma(double x) {
  double v, w;
  if (x == 1.0 || x == 2.0)
    return 0.0;
  v = 1;
  while (x < 8) {
    v *= x;
    x++;
  }
  w = 1 / (x * x);
  return (((((((((-3617.0 / 510.0) / (16 * 15)) * w +
                ((7.0 / 6.0) / (14 * 13))) *
                   w +
               ((-691.0 / 2730.0) / (12 * 11))) *
                  w +
              ((5.0 / 66.0) / (10 * 9))) *
                 w +
             ((-1.0 / 30.0) / (8 * 7))) *
                w +
            ((1.0 / 42.0) / (6 * 5))) *
               w +
           ((-1.0 / 30.0) / (4 * 3))) *
              w +
          ((1.0 / 6.0) / (2 * 1))) /
             x +
         0.5 * 1.83787706640934548 - log(v) - x + (x - 0.5) * log(x);
}


x86 assembly (clang, -O0):
<loggamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    113f <loggamma+0x2f>
jp     113f <loggamma+0x2f>
jmp    115c <loggamma+0x4c>
movsd  -0x10(%rbp),%xmm0
movsd  0xebc(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1169 <loggamma+0x59>
jp     1169 <loggamma+0x59>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d5 <loggamma+0x1c5>
movsd  0xe8f(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe92(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11af <loggamma+0x9f>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe60(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1176 <loggamma+0x66>
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xe3f(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe81(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe7d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe58(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe3b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe1e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe01(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xde4(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdc7(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  0xdae(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xd70(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movsd  -0x30(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loggamma>:
sub    $0x18,%rsp
ucomisd 0xee4(%rip),%xmm0
jne    1120 <loggamma+0x10>
jnp    1170 <loggamma+0x60>
movapd %xmm0,%xmm4
ucomisd 0xedc(%rip),%xmm0
jne    1130 <loggamma+0x20>
jnp    1170 <loggamma+0x60>
movsd  0xec8(%rip),%xmm1
movsd  0xed0(%rip),%xmm2
ucomisd %xmm4,%xmm2
jbe    1179 <loggamma+0x69>
movsd  0xeb2(%rip),%xmm3
movapd %xmm3,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mulsd  %xmm4,%xmm0
addsd  %xmm3,%xmm4
ucomisd %xmm4,%xmm2
ja     1160 <loggamma+0x50>
jmp    117d <loggamma+0x6d>
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
ret
movapd %xmm1,%xmm0
movsd  %xmm4,0x8(%rsp)
movapd %xmm4,%xmm2
mulsd  %xmm4,%xmm2
divsd  %xmm2,%xmm1
movsd  0xe81(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe7d(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe79(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe75(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe71(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe6d(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe69(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe65(%rip),%xmm2
divsd  %xmm4,%xmm2
addsd  0xe61(%rip),%xmm2
movsd  %xmm2,(%rsp)
call   1030 <log@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xe3f(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1030 <log@plt>
mulsd  0x10(%rsp),%xmm0
addsd  (%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @loggamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
%6 = load double, double* %3
%7 = fcmp oeq double %6, 1.000000e+00
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load double, double* %3
%10 = fcmp oeq double %9, 2.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %8, %1
store double 0.000000e+00, double* %2
br label %54
12: ; preds = %8
store double 1.000000e+00, double* %4
br label %13
13: ; preds = %16, %12
%14 = load double, double* %3
%15 = fcmp olt double %14, 8.000000e+00
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load double, double* %3
%18 = load double, double* %4
%19 = fmul double %18, %17
store double %19, double* %4
%20 = load double, double* %3
%21 = fadd double %20, 1.000000e+00
store double %21, double* %3
br label %13
22: ; preds = %13
%23 = load double, double* %3
%24 = load double, double* %3
%25 = fmul double %23, %24
%26 = fdiv double 1.000000e+00, %25
store double %26, double* %5
%27 = load double, double* %5
%28 = call double @llvm.fmuladd.f64(double 0xBF9E4286CB0F5397, double %27, double 0x3F7A41A41A41A41B)
%29 = load double, double* %5
%30 = call double @llvm.fmuladd.f64(double %28, double %29, double 0xBF5F6AB0D9993C7C)
%31 = load double, double* %5
%32 = call double @llvm.fmuladd.f64(double %30, double %31, double 0x3F4B951E2B18FF24)
%33 = load double, double* %5
%34 = call double @llvm.fmuladd.f64(double %32, double %33, double 0xBF43813813813813)
%35 = load double, double* %5
%36 = call double @llvm.fmuladd.f64(double %34, double %35, double 0x3F4A01A01A01A01A)
%37 = load double, double* %5
%38 = call double @llvm.fmuladd.f64(double %36, double %37, double 0xBF66C16C16C16C17)
%39 = load double, double* %5
%40 = call double @llvm.fmuladd.f64(double %38, double %39, double 0x3FB5555555555555)
%41 = load double, double* %3
%42 = fdiv double %40, %41
%43 = fadd double %42, 0x3FED67F1C864BEB5
%44 = load double, double* %4
%45 = call double @log(double %44)
%46 = fsub double %43, %45
%47 = load double, double* %3
%48 = fsub double %46, %47
%49 = load double, double* %3
%50 = fsub double %49, 5.000000e-01
%51 = load double, double* %3
%52 = call double @log(double %51)
%53 = call double @llvm.fmuladd.f64(double %50, double %52, double %48)
store double %53, double* %2
br label %54
54: ; preds = %22, %11
%55 = load double, double* %2
ret double %55
}

LLVM IR (-O2):
define double @loggamma(double %0) {
%2 = fcmp oeq double %0, 1.000000e+00
%3 = fcmp oeq double %0, 2.000000e+00
%4 = or i1 %2, %3
br i1 %4, label %33, label %5
5: ; preds = %1
%6 = fcmp olt double %0, 8.000000e+00
br i1 %6, label %7, label %13
7: ; preds = %5, %7
%8 = phi double [ %10, %7 ], [ 1.000000e+00, %5 ]
%9 = phi double [ %11, %7 ], [ %0, %5 ]
%10 = fmul double %9, %8
%11 = fadd double %9, 1.000000e+00
%12 = fcmp olt double %11, 8.000000e+00
br i1 %12, label %7, label %13
13: ; preds = %7, %5
%14 = phi double [ %0, %5 ], [ %11, %7 ]
%15 = phi double [ 1.000000e+00, %5 ], [ %10, %7 ]
%16 = fmul double %14, %14
%17 = fdiv double 1.000000e+00, %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double 0xBF9E4286CB0F5397, double 0x3F7A41A41A41A41B)
%19 = tail call double @llvm.fmuladd.f64(double %18, double %17, double 0xBF5F6AB0D9993C7C)
%20 = tail call double @llvm.fmuladd.f64(double %19, double %17, double 0x3F4B951E2B18FF24)
%21 = tail call double @llvm.fmuladd.f64(double %20, double %17, double 0xBF43813813813813)
%22 = tail call double @llvm.fmuladd.f64(double %21, double %17, double 0x3F4A01A01A01A01A)
%23 = tail call double @llvm.fmuladd.f64(double %22, double %17, double 0xBF66C16C16C16C17)
%24 = tail call double @llvm.fmuladd.f64(double %23, double %17, double 0x3FB5555555555555)
%25 = fdiv double %24, %14
%26 = fadd double %25, 0x3FED67F1C864BEB5
%27 = tail call double @log(double %15)
%28 = fsub double %26, %27
%29 = fsub double %28, %14
%30 = fadd double %14, -5.000000e-01
%31 = tail call double @log(double %14)
%32 = tail call double @llvm.fmuladd.f64(double %30, double %31, double %29)
br label %33
33: ; preds = %1, %13
%34 = phi double [ %32, %13 ], [ 0.000000e+00, %1 ]
ret double %34
}