#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 xx) {
  double x, tmp, ser;
  static double cof[6] = {76.18009173,  -86.50532033,   24.01409822,
                          -1.231739516, 0.120858003e-2, -0.536382e-5};
  int j;
  x = xx - 1.0;
  tmp = x + 5.5;
  tmp -= (x + 0.5) * log(tmp);
  ser = 1.0;
  for (j = 0; j <= 5; j++) {
    x += 1.0;
    ser += cof[j] / x;
  }
  return -tmp + log(2.50662827465 * ser);
}


x86 assembly (clang, -O0):
<gammln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xed5(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xebb(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe66(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jg     11ef <gammln+0xdf>
movsd  0xe48(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movslq -0x24(%rbp),%rcx
lea    0x2e63(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x10(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <gammln+0x96>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe00(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gammln>:
sub    $0x18,%rsp
movapd %xmm0,%xmm1
addsd  0xee0(%rip),%xmm1
movsd  %xmm1,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 0xec9(%rip),%xmm4
divpd  %xmm2,%xmm4
movapd %xmm4,%xmm2
addsd  %xmm1,%xmm2
unpckhpd %xmm4,%xmm4
addsd  %xmm2,%xmm4
addsd  %xmm1,%xmm3
movapd %xmm3,%xmm2
addsd  %xmm1,%xmm2
unpcklpd %xmm2,%xmm3
movapd 0xead(%rip),%xmm5
divpd  %xmm3,%xmm5
addsd  %xmm5,%xmm4
unpckhpd %xmm5,%xmm5
addsd  %xmm4,%xmm5
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm1
unpcklpd %xmm1,%xmm2
movapd 0xe99(%rip),%xmm1
divpd  %xmm2,%xmm1
addsd  %xmm1,%xmm5
unpckhpd %xmm1,%xmm1
addsd  %xmm5,%xmm1
movapd %xmm6,%xmm2
addsd  0xe45(%rip),%xmm2
mulsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  0xe31(%rip),%xmm1
movapd %xmm1,%xmm0
call   1030 <log@plt>
subsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @gammln(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 %32
%34 = tail call double @llvm.fmuladd.f64(double %33, double %4, double %3)
%35 = fmul double %31, 0x40040D931FF6CE25
%36 = tail call double @log(double %35)
%37 = fsub double %36, %34
ret double %37
}