#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);
float Gammln(float 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 (float)value;
}


x86 assembly (clang, -O0):
<Gammln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jb     1145 <Gammln+0x35>
movss  0xee5(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1249 <Gammln+0x139>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeaa(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xea1(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  0xe82(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0xa,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11d7 <Gammln+0xc7>
movslq -0xc(%rbp),%rcx
lea    0x2e91(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe40(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    118a <Gammln+0x7a>
movsd  -0x30(%rbp),%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  0xe2a(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe18(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xde8(%rip),%xmm1
addsd  %xmm1,%xmm0
subsd  -0x20(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Gammln>:
sub    $0x18,%rsp
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jae    127a <Gammln+0x16a>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xed9(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xecf(%rip),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rsp)
movsd  0xec6(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  0xec2(%rip),%xmm1
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm3
addsd  %xmm0,%xmm3
unpcklpd %xmm3,%xmm2
movapd 0xeca(%rip),%xmm4
divpd  %xmm2,%xmm4
addsd  %xmm4,%xmm1
unpckhpd %xmm4,%xmm4
addsd  %xmm1,%xmm4
addsd  %xmm0,%xmm3
movapd %xmm3,%xmm1
addsd  %xmm0,%xmm1
unpcklpd %xmm1,%xmm3
movapd 0xeb2(%rip),%xmm2
divpd  %xmm3,%xmm2
addsd  %xmm2,%xmm4
unpckhpd %xmm2,%xmm2
addsd  %xmm4,%xmm2
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm3
addsd  %xmm0,%xmm3
unpcklpd %xmm3,%xmm1
movapd 0xe9a(%rip),%xmm4
divpd  %xmm1,%xmm4
addsd  %xmm4,%xmm2
unpckhpd %xmm4,%xmm4
addsd  %xmm2,%xmm4
addsd  %xmm0,%xmm3
movapd %xmm3,%xmm1
addsd  %xmm0,%xmm1
unpcklpd %xmm1,%xmm3
movapd 0xe82(%rip),%xmm2
divpd  %xmm3,%xmm2
addsd  %xmm2,%xmm4
unpckhpd %xmm2,%xmm2
addsd  %xmm4,%xmm2
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm0
unpcklpd %xmm0,%xmm1
movapd 0xe6e(%rip),%xmm0
divpd  %xmm1,%xmm0
addsd  %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
call   1030 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0xdf3(%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  0xdca(%rip),%xmm0
subsd  (%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x18,%rsp
ret
movss  0xd7e(%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 float @Gammln(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store float %0, float* %3
%9 = load float, float* %3
%10 = fpext float %9 to double
%11 = fcmp ole double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %1
store float 9.999990e+05, float* %2
br label %52
13: ; preds = %1
%14 = load float, float* %3
%15 = fpext float %14 to double
%16 = fsub double %15, 1.000000e+00
store double %16, double* %5
%17 = load double, double* %5
%18 = fadd double %17, 1.100000e+01
store double %18, double* %7
store double %18, double* %6
store double 1.000000e+00, double* %8
store i32 10, i32* %4
br label %19
19: ; preds = %33, %13
%20 = load i32, i32* %4
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %19
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [11 x double], [11 x double]* @Gammln.cof, i64 0, i64 %24
%26 = load double, double* %25
%27 = load double, double* %7
%28 = fdiv double %26, %27
%29 = load double, double* %8
%30 = fadd double %29, %28
store double %30, double* %8
%31 = load double, double* %7
%32 = fsub double %31, 1.000000e+00
store double %32, double* %7
br label %33
33: ; preds = %22
%34 = load i32, i32* %4
%35 = add nsw i32 %34, -1
store i32 %35, i32* %4
br label %19
36: ; preds = %19
%37 = load double, double* %8
%38 = call double @log(double %37)
store double %38, double* %8
%39 = load double, double* %6
%40 = fadd double %39, 5.000000e-01
store double %40, double* %6
%41 = load double, double* %5
%42 = fadd double %41, 5.000000e-01
%43 = load double, double* %6
%44 = call double @log(double %43)
%45 = call double @llvm.fmuladd.f64(double %42, double %44, double 0x3FED67F1C8489D6C)
%46 = load double, double* %6
%47 = fsub double %45, %46
%48 = load double, double* %8
%49 = fadd double %48, %47
store double %49, double* %8
%50 = load double, double* %8
%51 = fptrunc double %50 to float
store float %51, float* %2
br label %52
52: ; preds = %36, %12
%53 = load float, float* %2
ret float %53
}

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