#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 x) {
  int i;
  double xx, tx;
  double tmp, value;
  static double cof[11] = {
      4.694580336184385e+04,  -1.560605207784446e+05, 2.065049568014106e+05,
      -1.388934775095388e+05, 5.031796415085709e+04,  -9.601592329182778e+03,
      8.785855930895250e+02,  -3.155153906098611e+01, 2.908143421162229e-01,
      -2.319827630494973e-04, 1.251639670050933e-10};
  if (x <= 0.0)
    return 999999.;
  xx = x - 1.0;
  tx = tmp = xx + 11.0;
  value = 1.0;
  for (i = 10; i >= 0; i--) {
    value += cof[i] / tmp;
    tmp -= 1.0;
  }
  value = log(value);
  tx += 0.5;
  value += 0.918938533 + (xx + 0.5) * log(tx) - tx;
  return value;
}


x86 assembly (clang, -O0):
<Gammln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     113d <Gammln+0x2d>
movsd  0xeed(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1239 <Gammln+0x129>
movsd  -0x10(%rbp),%xmm0
movsd  0xeb6(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xead(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  0xe8e(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0xa,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11cb <Gammln+0xbb>
movslq -0x14(%rbp),%rcx
lea    0x2e9d(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    117e <Gammln+0x6e>
movsd  -0x38(%rbp),%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe36(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe24(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdf4(%rip),%xmm1
addsd  %xmm1,%xmm0
subsd  -0x28(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Gammln>:
sub    $0x18,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1271 <Gammln+0x161>
movsd  0xede(%rip),%xmm5
addsd  %xmm5,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xed4(%rip),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movsd  0xecb(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  0xec7(%rip),%xmm1
addsd  %xmm5,%xmm2
movapd %xmm2,%xmm3
addsd  %xmm5,%xmm3
unpcklpd %xmm3,%xmm2
movapd 0xecf(%rip),%xmm4
divpd  %xmm2,%xmm4
addsd  %xmm4,%xmm1
unpckhpd %xmm4,%xmm4
addsd  %xmm1,%xmm4
addsd  %xmm5,%xmm3
movapd %xmm3,%xmm1
addsd  %xmm5,%xmm1
unpcklpd %xmm1,%xmm3
movapd 0xeb7(%rip),%xmm2
divpd  %xmm3,%xmm2
addsd  %xmm2,%xmm4
unpckhpd %xmm2,%xmm2
addsd  %xmm4,%xmm2
addsd  %xmm5,%xmm1
movapd %xmm1,%xmm3
addsd  %xmm5,%xmm3
unpcklpd %xmm3,%xmm1
movapd 0xe9f(%rip),%xmm4
divpd  %xmm1,%xmm4
addsd  %xmm4,%xmm2
unpckhpd %xmm4,%xmm4
addsd  %xmm2,%xmm4
addsd  %xmm5,%xmm3
movapd %xmm3,%xmm1
addsd  %xmm5,%xmm1
unpcklpd %xmm1,%xmm3
movapd 0xe87(%rip),%xmm2
divpd  %xmm3,%xmm2
addsd  %xmm2,%xmm4
unpckhpd %xmm2,%xmm2
addsd  %xmm4,%xmm2
addsd  %xmm5,%xmm1
addsd  %xmm1,%xmm5
unpcklpd %xmm5,%xmm1
movapd 0xe73(%rip),%xmm0
divpd  %xmm1,%xmm0
addsd  %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
call   1030 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0xdf8(%rip),%xmm2
movsd  (%rsp),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0xdcf(%rip),%xmm0
subsd  (%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret
movsd  0xd87(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@Gammln.cof = internal global [11 x double] [double 0x40E6EC39B523E5C6, double 0xC1030CE42A8DE3A0, double 0x41093547A7877F7A, double 0xC100F46BD1F08565, double 0x40E891BEDA52E5F4, double 0xC0C2C0CBD1715240, double 0x408B74AF4B6E0230, double 0xC03F8D31A9F566E2, double 0x3FD29CB3C2263426, double 0xBF2E680CC2D54303, double 0x3DE133D0CA52FB5A]
define double @Gammln(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
%9 = load double, double* %3
%10 = fcmp ole double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %1
store double 9.999990e+05, double* %2
br label %49
12: ; preds = %1
%13 = load double, double* %3
%14 = fsub double %13, 1.000000e+00
store double %14, double* %5
%15 = load double, double* %5
%16 = fadd double %15, 1.100000e+01
store double %16, double* %7
store double %16, double* %6
store double 1.000000e+00, double* %8
store i32 10, i32* %4
br label %17
17: ; preds = %31, %12
%18 = load i32, i32* %4
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [11 x double], [11 x double]* @Gammln.cof, i64 0, i64 %22
%24 = load double, double* %23
%25 = load double, double* %7
%26 = fdiv double %24, %25
%27 = load double, double* %8
%28 = fadd double %27, %26
store double %28, double* %8
%29 = load double, double* %7
%30 = fsub double %29, 1.000000e+00
store double %30, double* %7
br label %31
31: ; preds = %20
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
store i32 %33, i32* %4
br label %17
34: ; preds = %17
%35 = load double, double* %8
%36 = call double @log(double %35)
store double %36, double* %8
%37 = load double, double* %6
%38 = fadd double %37, 5.000000e-01
store double %38, double* %6
%39 = load double, double* %5
%40 = fadd double %39, 5.000000e-01
%41 = load double, double* %6
%42 = call double @log(double %41)
%43 = call double @llvm.fmuladd.f64(double %40, double %42, double 0x3FED67F1C8489D6C)
%44 = load double, double* %6
%45 = fsub double %43, %44
%46 = load double, double* %8
%47 = fadd double %46, %45
store double %47, double* %8
%48 = load double, double* %8
store double %48, double* %2
br label %49
49: ; preds = %34, %11
%50 = load double, double* %2
ret double %50
}

LLVM IR (-O2):
define double @Gammln(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %3, label %60
3: ; preds = %1
%4 = fadd double %0, -1.000000e+00
%5 = fadd double %4, 1.100000e+01
%6 = fdiv double 0x3DE133D0CA52FB5A, %5
%7 = fadd double %6, 1.000000e+00
%8 = fadd double %5, -1.000000e+00
%9 = fadd double %8, -1.000000e+00
%10 = insertelement <2 x double> poison, double %8, i64 0
%11 = insertelement <2 x double> %10, double %9, i64 1
%12 = fdiv <2 x double> <double 0xBF2E680CC2D54303, double 0x3FD29CB3C2263426>, %11
%13 = extractelement <2 x double> %12, i64 0
%14 = fadd double %7, %13
%15 = extractelement <2 x double> %12, i64 1
%16 = fadd double %14, %15
%17 = fadd double %9, -1.000000e+00
%18 = fadd double %17, -1.000000e+00
%19 = insertelement <2 x double> poison, double %17, i64 0
%20 = insertelement <2 x double> %19, double %18, i64 1
%21 = fdiv <2 x double> <double 0xC03F8D31A9F566E2, double 0x408B74AF4B6E0230>, %20
%22 = extractelement <2 x double> %21, i64 0
%23 = fadd double %16, %22
%24 = extractelement <2 x double> %21, i64 1
%25 = fadd double %23, %24
%26 = fadd double %18, -1.000000e+00
%27 = fadd double %26, -1.000000e+00
%28 = insertelement <2 x double> poison, double %26, i64 0
%29 = insertelement <2 x double> %28, double %27, i64 1
%30 = fdiv <2 x double> <double 0xC0C2C0CBD1715240, double 0x40E891BEDA52E5F4>, %29
%31 = extractelement <2 x double> %30, i64 0
%32 = fadd double %25, %31
%33 = extractelement <2 x double> %30, i64 1
%34 = fadd double %32, %33
%35 = fadd double %27, -1.000000e+00
%36 = fadd double %35, -1.000000e+00
%37 = insertelement <2 x double> poison, double %35, i64 0
%38 = insertelement <2 x double> %37, double %36, i64 1
%39 = fdiv <2 x double> <double 0xC100F46BD1F08565, double 0x41093547A7877F7A>, %38
%40 = extractelement <2 x double> %39, i64 0
%41 = fadd double %34, %40
%42 = extractelement <2 x double> %39, i64 1
%43 = fadd double %41, %42
%44 = fadd double %36, -1.000000e+00
%45 = fadd double %44, -1.000000e+00
%46 = insertelement <2 x double> poison, double %44, i64 0
%47 = insertelement <2 x double> %46, double %45, i64 1
%48 = fdiv <2 x double> <double 0xC1030CE42A8DE3A0, double 0x40E6EC39B523E5C6>, %47
%49 = extractelement <2 x double> %48, i64 0
%50 = fadd double %43, %49
%51 = extractelement <2 x double> %48, i64 1
%52 = fadd double %50, %51
%53 = tail call double @log(double %52)
%54 = fadd double %5, 5.000000e-01
%55 = fadd double %4, 5.000000e-01
%56 = tail call double @log(double %54)
%57 = tail call double @llvm.fmuladd.f64(double %55, double %56, double 0x3FED67F1C8489D6C)
%58 = fsub double %57, %54
%59 = fadd double %53, %58
br label %60
60: ; preds = %1, %3
%61 = phi double [ %59, %3 ], [ 9.999990e+05, %1 ]
ret double %61
}