#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, y, tmp, ser;
  static double cof[6] = {76.18009172947,     -86.50532032942,
                          24.01409824083,     -1.231739572450,
                          0.1208650973866e-2, -0.5395239385e-5};
  int j;
  y = x = xx;
  tmp = x + 5.5;
  tmp -= (x + 0.5) * log(tmp);
  ser = 1.00000000019015;
  for (j = 0; j < 5; j++)
    ser += cof[j] / ++y;
  return -tmp + log(2.5066282746310005 * ser / x);
}


x86 assembly (clang, -O0):
<gammln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  0xedc(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec2(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe6d(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x5,-0x2c(%rbp)
jge    11e7 <gammln+0xd7>
movslq -0x2c(%rbp),%rcx
lea    0x2e7c(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe5f(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
movsd  %xmm1,-0x18(%rbp)
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119f <gammln+0x8f>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe08(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm0
add    $0x40,%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
movsd  0xebd(%rip),%xmm3
divsd  %xmm2,%xmm3
addsd  0xeb9(%rip),%xmm3
addsd  %xmm1,%xmm2
movapd %xmm2,%xmm4
addsd  %xmm1,%xmm4
unpcklpd %xmm4,%xmm2
movapd 0xeb9(%rip),%xmm5
divpd  %xmm2,%xmm5
addsd  %xmm5,%xmm3
unpckhpd %xmm5,%xmm5
addsd  %xmm3,%xmm5
addsd  %xmm1,%xmm4
addsd  %xmm4,%xmm1
unpcklpd %xmm1,%xmm4
movapd 0xea5(%rip),%xmm1
divpd  %xmm4,%xmm1
addsd  %xmm1,%xmm5
unpckhpd %xmm1,%xmm1
addsd  %xmm5,%xmm1
movsd  0xe6d(%rip),%xmm2
addsd  %xmm6,%xmm2
mulsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  0xe55(%rip),%xmm1
divsd  %xmm6,%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 0x40530B869F7616A4, double 0xC055A0572B143739, double 0x4038039BF13B4BC5, double 0xBFF3B5348DCDC9D2, double 0x3F53CD7319EC0F9E, double 0xBED6A1181C0F7147]
define double @gammln(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %2
%8 = load double, double* %2
store double %8, double* %3
store double %8, double* %4
%9 = load double, double* %3
%10 = fadd double %9, 5.500000e+00
store double %10, double* %5
%11 = load double, double* %3
%12 = fadd double %11, 5.000000e-01
%13 = load double, double* %5
%14 = call double @log(double %13)
%15 = load double, double* %5
%16 = fneg double %12
%17 = call double @llvm.fmuladd.f64(double %16, double %14, double %15)
store double %17, double* %5
store double 0x3FF00000000D1127, double* %6
store i32 0, i32* %7
br label %18
18: ; preds = %31, %1
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 5
br i1 %20, label %21, label %34
21: ; preds = %18
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [6 x double], [6 x double]* @gammln.cof, i64 0, i64 %23
%25 = load double, double* %24
%26 = load double, double* %4
%27 = fadd double %26, 1.000000e+00
store double %27, double* %4
%28 = fdiv double %25, %27
%29 = load double, double* %6
%30 = fadd double %29, %28
store double %30, double* %6
br label %31
31: ; preds = %21
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %18
34: ; preds = %18
%35 = load double, double* %5
%36 = fneg double %35
%37 = load double, double* %6
%38 = fmul double 0x40040D931FF62706, %37
%39 = load double, double* %3
%40 = fdiv double %38, %39
%41 = call double @log(double %40)
%42 = fadd double %36, %41
ret double %42
}

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 = fdiv double 0x40530B869F7616A4, %4
%6 = fadd double %5, 0x3FF00000000D1127
%7 = fadd double %4, 1.000000e+00
%8 = fadd double %7, 1.000000e+00
%9 = insertelement <2 x double> poison, double %7, i64 0
%10 = insertelement <2 x double> %9, double %8, i64 1
%11 = fdiv <2 x double> <double 0xC055A0572B143739, double 0x4038039BF13B4BC5>, %10
%12 = extractelement <2 x double> %11, i64 0
%13 = fadd double %6, %12
%14 = extractelement <2 x double> %11, i64 1
%15 = fadd double %13, %14
%16 = fadd double %8, 1.000000e+00
%17 = fadd double %16, 1.000000e+00
%18 = insertelement <2 x double> poison, double %16, i64 0
%19 = insertelement <2 x double> %18, double %17, i64 1
%20 = fdiv <2 x double> <double 0xBFF3B5348DCDC9D2, double 0x3F53CD7319EC0F9E>, %19
%21 = extractelement <2 x double> %20, i64 0
%22 = fadd double %15, %21
%23 = extractelement <2 x double> %20, i64 1
%24 = fadd double %22, %23
%25 = fadd double %0, 5.000000e-01
%26 = fneg double %25
%27 = tail call double @llvm.fmuladd.f64(double %26, double %3, double %2)
%28 = fmul double %24, 0x40040D931FF62706
%29 = fdiv double %28, %0
%30 = tail call double @log(double %29)
%31 = fsub double %30, %27
ret double %31
}