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


x86 assembly (clang, -O0):
<lgamma>:
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)
jg     11e7 <lgamma+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 <lgamma+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):
<lgamma>:
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):
@lgamma.cof = internal global [6 x double] [double 0x40530B869F76170A, double 0xC055A0572B143656, double 0x4038039BF13B4CC6, double 0xBFF3B5348DCDCC8C, double 0x3F53CD7319EC12D8, double 0x3ED6A1181C0E9888]
define double @lgamma(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 0x3FF00000000D0EC7, double* %6
store i32 0, i32* %7
br label %18
18: ; preds = %31, %1
%19 = load i32, i32* %7
%20 = icmp sle 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]* @lgamma.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 @lgamma(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 0x3ED6A1181C0E9888>, %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
}