#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(int);
double _loggamma(double x) {
  double invx, invx2, invx3, invx5, invx7;
  double sum = 0.0;
  x -= 1.0;
  if (x <= 1.0)
    return (1.0);
  invx = 1.0 / x;
  invx2 = invx * invx;
  invx3 = invx2 * invx;
  invx5 = invx3 * invx2;
  invx7 = invx5 * invx2;
  sum = ((x + 0.5) * log(x)) - x;
  sum += log(2 * 3.1415926535897932384626) * 0.5;
  sum += (invx / 12.0) - (invx3 / 360.0);
  sum += (invx5 / 1260.0) - (invx7 / 1680.0);
  return (sum);
}


x86 assembly (clang, -O0):
<_loggamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xece(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xebd(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1160 <_loggamma+0x50>
movsd  0xeaa(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1289 <_loggamma+0x179>
movsd  0xe98(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe72(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
cvttsd2si -0x10(%rbp),%edi
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x6,%edi
call   1030 <log@plt>
movsd  -0x40(%rbp),%xmm1
movsd  0xe16(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xdf4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xddb(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdb4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  0xd9b(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_loggamma>:
sub    $0x58,%rsp
movapd %xmm0,%xmm2
addsd  0xee0(%rip),%xmm2
movsd  0xee0(%rip),%xmm0
ucomisd %xmm2,%xmm0
jae    11fd <_loggamma+0xed>
movsd  0xece(%rip),%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,0x30(%rsp)
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movapd %xmm2,%xmm3
movapd %xmm1,%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,0x40(%rsp)
movapd %xmm0,%xmm1
mulsd  %xmm2,%xmm1
movapd %xmm1,0x10(%rsp)
mulsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  %xmm3,(%rsp)
movapd %xmm3,%xmm0
addsd  0xe89(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
cvttsd2si %xmm3,%edi
call   1030 <log@plt>
mulsd  0x8(%rsp),%xmm0
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x6,%edi
call   1030 <log@plt>
movapd %xmm0,%xmm1
mulsd  0xe54(%rip),%xmm1
movapd 0x10(%rsp),%xmm0
unpcklpd 0x30(%rsp),%xmm0
divpd  0xe50(%rip),%xmm0
addsd  (%rsp),%xmm1
movapd 0x20(%rsp),%xmm2
unpcklpd 0x40(%rsp),%xmm2
divpd  0xe47(%rip),%xmm2
addpd  %xmm0,%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
add    $0x58,%rsp
ret

LLVM IR (-O0):
define double @_loggamma(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 double
store double %0, double* %3
store double 0.000000e+00, double* %9
%10 = load double, double* %3
%11 = fsub double %10, 1.000000e+00
store double %11, double* %3
%12 = load double, double* %3
%13 = fcmp ole double %12, 1.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %1
store double 1.000000e+00, double* %2
br label %56
15: ; preds = %1
%16 = load double, double* %3
%17 = fdiv double 1.000000e+00, %16
store double %17, double* %4
%18 = load double, double* %4
%19 = load double, double* %4
%20 = fmul double %18, %19
store double %20, double* %5
%21 = load double, double* %5
%22 = load double, double* %4
%23 = fmul double %21, %22
store double %23, double* %6
%24 = load double, double* %6
%25 = load double, double* %5
%26 = fmul double %24, %25
store double %26, double* %7
%27 = load double, double* %7
%28 = load double, double* %5
%29 = fmul double %27, %28
store double %29, double* %8
%30 = load double, double* %3
%31 = fadd double %30, 5.000000e-01
%32 = load double, double* %3
%33 = fptosi double %32 to i32
%34 = call double @log(i32 %33)
%35 = load double, double* %3
%36 = fneg double %35
%37 = call double @llvm.fmuladd.f64(double %31, double %34, double %36)
store double %37, double* %9
%38 = call double @log(i32 6)
%39 = load double, double* %9
%40 = call double @llvm.fmuladd.f64(double %38, double 5.000000e-01, double %39)
store double %40, double* %9
%41 = load double, double* %4
%42 = fdiv double %41, 1.200000e+01
%43 = load double, double* %6
%44 = fdiv double %43, 3.600000e+02
%45 = fsub double %42, %44
%46 = load double, double* %9
%47 = fadd double %46, %45
store double %47, double* %9
%48 = load double, double* %7
%49 = fdiv double %48, 1.260000e+03
%50 = load double, double* %8
%51 = fdiv double %50, 1.680000e+03
%52 = fsub double %49, %51
%53 = load double, double* %9
%54 = fadd double %53, %52
store double %54, double* %9
%55 = load double, double* %9
store double %55, double* %2
br label %56
56: ; preds = %15, %14
%57 = load double, double* %2
ret double %57
}

LLVM IR (-O2):
define double @_loggamma(double %0) {
%2 = fadd double %0, -1.000000e+00
%3 = fcmp ugt double %2, 1.000000e+00
br i1 %3, label %4, label %28
4: ; preds = %1
%5 = fdiv double 1.000000e+00, %2
%6 = fmul double %5, %5
%7 = fmul double %5, %6
%8 = fmul double %6, %7
%9 = fmul double %6, %8
%10 = fadd double %2, 5.000000e-01
%11 = fptosi double %2 to i32
%12 = tail call double @log(i32 %11)
%13 = fneg double %2
%14 = tail call double @llvm.fmuladd.f64(double %10, double %12, double %13)
%15 = tail call double @log(i32 6)
%16 = tail call double @llvm.fmuladd.f64(double %15, double 5.000000e-01, double %14)
%17 = insertelement <2 x double> poison, double %8, i64 0
%18 = insertelement <2 x double> %17, double %5, i64 1
%19 = fdiv <2 x double> %18, <double 1.260000e+03, double 1.200000e+01>
%20 = insertelement <2 x double> poison, double %9, i64 0
%21 = insertelement <2 x double> %20, double %7, i64 1
%22 = fdiv <2 x double> %21, <double 1.680000e+03, double 3.600000e+02>
%23 = fsub <2 x double> %19, %22
%24 = extractelement <2 x double> %23, i64 1
%25 = fadd double %24, %16
%26 = extractelement <2 x double> %23, i64 0
%27 = fadd double %26, %25
br label %28
28: ; preds = %1, %4
%29 = phi double [ %27, %4 ], [ 1.000000e+00, %1 ]
ret double %29
}