#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 coef[] = {76.18009173,  -86.50532033,  24.01409822,
                   -1.231739516, 0.00120858003, -0.00000536382};
  double step = 2.50662827465, fpf = 5.5, t, tmp, ser;
  int i;
  t = x - 1;
  tmp = t + fpf;
  tmp = (t + 0.5) * log(tmp) - tmp;
  ser = 1;
  for (i = 1; i <= 6; i++) {
    t = t + 1;
    ser = ser + coef[i - 1] / t;
  }
  return tmp + log(step * ser);
}


x86 assembly (clang, -O0):
<logGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
movsd  0xf00(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xeeb(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xed6(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeac(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe97(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe82(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe6d(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe4b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xe33(%rip),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x78(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xdde(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x1,-0x6c(%rbp)
cmpl   $0x6,-0x6c(%rbp)
jg     1279 <logGamma+0x159>
movsd  0xdc0(%rip),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x68(%rbp),%xmm0
mov    -0x6c(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x40(%rbp,%rax,8),%xmm1
divsd  -0x58(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    122e <logGamma+0x10e>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
addsd  %xmm1,%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logGamma>:
sub    $0x18,%rsp
addsd  0xee4(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xede(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1030 <log@plt>
movapd %xmm0,%xmm5
movsd  0xec7(%rip),%xmm0
movsd  0x10(%rsp),%xmm6
movapd %xmm6,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm2
addsd  %xmm0,%xmm2
unpcklpd %xmm2,%xmm1
movapd 0xec5(%rip),%xmm3
divpd  %xmm1,%xmm3
movapd %xmm3,%xmm1
addsd  %xmm0,%xmm1
unpckhpd %xmm3,%xmm3
addsd  %xmm1,%xmm3
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm1
addsd  %xmm0,%xmm1
unpcklpd %xmm1,%xmm2
movapd 0xea9(%rip),%xmm4
divpd  %xmm2,%xmm4
addsd  %xmm4,%xmm3
unpckhpd %xmm4,%xmm4
addsd  %xmm3,%xmm4
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm0
unpcklpd %xmm0,%xmm1
movapd 0xe95(%rip),%xmm0
divpd  %xmm1,%xmm0
addsd  %xmm0,%xmm4
unpckhpd %xmm0,%xmm0
addsd  %xmm4,%xmm0
movapd %xmm6,%xmm1
addsd  0xe41(%rip),%xmm1
mulsd  %xmm1,%xmm5
subsd  0x8(%rsp),%xmm5
movsd  %xmm5,0x8(%rsp)
mulsd  0xe31(%rip),%xmm0
call   1030 <log@plt>
addsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @logGamma(double %0) {
%2 = alloca double
%3 = alloca [6 x double]
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store double %0, double* %2
%10 = bitcast [6 x double]* %3 to i8*
%11 = bitcast i8* %10 to [6 x double]*
%12 = getelementptr inbounds [6 x double], [6 x double]* %11, i32 0, i32 0
store double 0x40530B869F76A853, double* %12
%13 = getelementptr inbounds [6 x double], [6 x double]* %11, i32 0, i32 1
store double 0xC055A0572B14D6A7, double* %13
%14 = getelementptr inbounds [6 x double], [6 x double]* %11, i32 0, i32 2
store double 0x4038039BF0E1D4F2, double* %14
%15 = getelementptr inbounds [6 x double], [6 x double]* %11, i32 0, i32 3
store double 0xBFF3B5347EA692EB, double* %15
%16 = getelementptr inbounds [6 x double], [6 x double]* %11, i32 0, i32 4
store double 0x3F53CD26ED054DB1, double* %16
%17 = getelementptr inbounds [6 x double], [6 x double]* %11, i32 0, i32 5
store double 0xBED67F5B9D652131, double* %17
store double 0x40040D931FF6CE25, double* %4
store double 5.500000e+00, double* %5
%18 = load double, double* %2
%19 = fsub double %18, 1.000000e+00
store double %19, double* %6
%20 = load double, double* %6
%21 = load double, double* %5
%22 = fadd double %20, %21
store double %22, double* %7
%23 = load double, double* %6
%24 = fadd double %23, 5.000000e-01
%25 = load double, double* %7
%26 = call double @log(double %25)
%27 = load double, double* %7
%28 = fneg double %27
%29 = call double @llvm.fmuladd.f64(double %24, double %26, double %28)
store double %29, double* %7
store double 1.000000e+00, double* %8
store i32 1, i32* %9
br label %30
30: ; preds = %45, %1
%31 = load i32, i32* %9
%32 = icmp sle i32 %31, 6
br i1 %32, label %33, label %48
33: ; preds = %30
%34 = load double, double* %6
%35 = fadd double %34, 1.000000e+00
store double %35, double* %6
%36 = load double, double* %8
%37 = load i32, i32* %9
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [6 x double], [6 x double]* %3, i64 0, i64 %39
%41 = load double, double* %40
%42 = load double, double* %6
%43 = fdiv double %41, %42
%44 = fadd double %36, %43
store double %44, double* %8
br label %45
45: ; preds = %33
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %30
48: ; preds = %30
%49 = load double, double* %7
%50 = load double, double* %4
%51 = load double, double* %8
%52 = fmul double %50, %51
%53 = call double @log(double %52)
%54 = fadd double %49, %53
ret double %54
}

LLVM IR (-O2):
define double @logGamma(double %0) {
%2 = fadd double %0, -1.000000e+00
%3 = fadd double %2, 5.500000e+00
%4 = tail call double @log(double %3)
%5 = fadd double %2, 1.000000e+00
%6 = fadd double %5, 1.000000e+00
%7 = insertelement <2 x double> poison, double %5, i64 0
%8 = insertelement <2 x double> %7, double %6, i64 1
%9 = fdiv <2 x double> <double 0x40530B869F76A853, double 0xC055A0572B14D6A7>, %8
%10 = extractelement <2 x double> %9, i64 0
%11 = fadd double %10, 1.000000e+00
%12 = extractelement <2 x double> %9, i64 1
%13 = fadd double %11, %12
%14 = fadd double %6, 1.000000e+00
%15 = fadd double %14, 1.000000e+00
%16 = insertelement <2 x double> poison, double %14, i64 0
%17 = insertelement <2 x double> %16, double %15, i64 1
%18 = fdiv <2 x double> <double 0x4038039BF0E1D4F2, double 0xBFF3B5347EA692EB>, %17
%19 = extractelement <2 x double> %18, i64 0
%20 = fadd double %13, %19
%21 = extractelement <2 x double> %18, i64 1
%22 = fadd double %20, %21
%23 = fadd double %15, 1.000000e+00
%24 = fadd double %23, 1.000000e+00
%25 = insertelement <2 x double> poison, double %23, i64 0
%26 = insertelement <2 x double> %25, double %24, i64 1
%27 = fdiv <2 x double> <double 0x3F53CD26ED054DB1, double 0xBED67F5B9D652131>, %26
%28 = extractelement <2 x double> %27, i64 0
%29 = fadd double %22, %28
%30 = extractelement <2 x double> %27, i64 1
%31 = fadd double %29, %30
%32 = fadd double %2, 5.000000e-01
%33 = fneg double %3
%34 = tail call double @llvm.fmuladd.f64(double %32, double %4, double %33)
%35 = fmul double %31, 0x40040D931FF6CE25
%36 = tail call double @log(double %35)
%37 = fadd double %34, %36
ret double %37
}