#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 gammln(double a) {
  int i;
  double x, y, tmp, ser;
  const double cof[6] = {76.18009172947146,     -86.50532032941677,
                         24.01409824083091,     -1.231739572450155,
                         0.1208650973866179e-2, -0.5395239384953e-5};
  y = x = a;
  tmp = x + 5.5;
  tmp -= (x + 0.5) * log(tmp);
  ser = 1.000000000190015;
  for (i = 0; i <= 5; i++) {
    y += 1;
    ser += cof[i] / y;
  }
  return -tmp + log(2.5066282746310005 * ser / x);
}


x86 assembly (clang, -O0):
<gammln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
movsd  0xefb(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xee6(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xea7(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  0xe6e(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe54(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xdff(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jg     1250 <gammln+0x130>
movsd  0xe31(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movslq -0xc(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm0
divsd  -0x20(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    120d <gammln+0xed>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xdcf(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
addsd  %xmm1,%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gammln>:
sub    $0x18,%rsp
movapd %xmm0,%xmm1
movsd  %xmm0,0x10(%rsp)
movsd  0xeda(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <log@plt>
movsd  0xecb(%rip),%xmm1
movsd  0x10(%rsp),%xmm6
movapd %xmm6,%xmm2
addsd  %xmm1,%xmm2
movapd %xmm2,%xmm3
addsd  %xmm1,%xmm3
unpcklpd %xmm3,%xmm2
movapd 0xed1(%rip),%xmm4
divpd  %xmm2,%xmm4
movsd  0xea5(%rip),%xmm2
addsd  %xmm4,%xmm2
unpckhpd %xmm4,%xmm4
addsd  %xmm2,%xmm4
addsd  %xmm1,%xmm3
movapd %xmm3,%xmm2
addsd  %xmm1,%xmm2
unpcklpd %xmm2,%xmm3
movapd 0xeb1(%rip),%xmm5
divpd  %xmm3,%xmm5
addsd  %xmm5,%xmm4
unpckhpd %xmm5,%xmm5
addsd  %xmm4,%xmm5
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm1
unpcklpd %xmm1,%xmm2
movapd 0xe9d(%rip),%xmm1
divpd  %xmm2,%xmm1
addsd  %xmm1,%xmm5
unpckhpd %xmm1,%xmm1
addsd  %xmm5,%xmm1
movsd  0xe4d(%rip),%xmm2
addsd  %xmm6,%xmm2
mulsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  0xe35(%rip),%xmm1
divsd  %xmm6,%xmm1
movapd %xmm1,%xmm0
call   1030 <log@plt>
subsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

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

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