#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 fabs(int /*<<< orphan*/);
double log(double);
int /*<<< orphan*/ sklearn_gamma(double);
double sklearn_lgamma(double x) {
  static const double c[8] = {
      1.0 / 12.0,   -1.0 / 360.0,      1.0 / 1260.0, -1.0 / 1680.0,
      1.0 / 1188.0, -691.0 / 360360.0, 1.0 / 156.0,  -3617.0 / 122400.0};
  double z, sum;
  int i;
  if (x < 12.0)
    return log(fabs(sklearn_gamma(x)));
  z = 1.0 / (x * x);
  sum = c[7];
  for (i = 6; i >= 0; i--) {
    sum *= z;
    sum += c[i];
  }
  return (x - 0.5) * log(x) - x + 0.91893853320467274178032973640562 + sum / x;
}


x86 assembly (clang, -O0):
<sklearn_lgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xebb(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1170 <sklearn_lgamma+0x40>
movsd  -0x10(%rbp),%xmm0
call   1030 <sklearn_gamma@plt>
mov    %eax,%edi
call   1040 <fabs@plt>
call   1050 <log@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    124b <sklearn_lgamma+0x11b>
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xe86(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x6,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11e0 <sklearn_lgamma+0xb0>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movslq -0x24(%rbp),%rcx
lea    0xe5d(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    119f <sklearn_lgamma+0x6f>
movsd  -0x10(%rbp),%xmm0
movsd  0xe2b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xddc(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
divsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sklearn_lgamma>:
sub    $0x18,%rsp
movsd  0xec4(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1157 <sklearn_lgamma+0x27>
call   1030 <sklearn_gamma@plt>
mov    %eax,%edi
call   1040 <fabs@plt>
add    $0x18,%rsp
jmp    1050 <log@plt>
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
movsd  0xea1(%rip),%xmm1
divsd  %xmm2,%xmm1
movsd  0xe9d(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe99(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe95(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe91(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe8d(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe89(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe85(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe81(%rip),%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  0xe7b(%rip),%xmm1
movsd  %xmm0,(%rsp)
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1050 <log@plt>
mulsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm2
subsd  %xmm2,%xmm0
addsd  0xe58(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@sklearn_lgamma.c = internal constant [8 x double] [double 0x3FB5555555555555, double 0xBF66C16C16C16C17, double 0x3F4A01A01A01A01A, double 0xBF43813813813814, double 0x3F4B951E2B18FF23, double 0xBF5F6AB0D9993C7D, double 0x3F7A41A41A41A41A, double 0xBF9E4286CB0F5398]
define double @sklearn_lgamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store double %0, double* %3
%7 = load double, double* %3
%8 = fcmp olt double %7, 1.200000e+01
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load double, double* %3
%11 = call i32 @sklearn_gamma(double %10)
%12 = call double @fabs(i32 %11)
%13 = call double @log(double %12)
store double %13, double* %2
br label %49
14: ; preds = %1
%15 = load double, double* %3
%16 = load double, double* %3
%17 = fmul double %15, %16
%18 = fdiv double 1.000000e+00, %17
store double %18, double* %4
%19 = load double, double* getelementptr inbounds ([8 x double], [8 x double]* @sklearn_lgamma.c, i64 0, i64 7)
store double %19, double* %5
store i32 6, i32* %6
br label %20
20: ; preds = %33, %14
%21 = load i32, i32* %6
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %20
%24 = load double, double* %4
%25 = load double, double* %5
%26 = fmul double %25, %24
store double %26, double* %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [8 x double], [8 x double]* @sklearn_lgamma.c, i64 0, i64 %28
%30 = load double, double* %29
%31 = load double, double* %5
%32 = fadd double %31, %30
store double %32, double* %5
br label %33
33: ; preds = %23
%34 = load i32, i32* %6
%35 = add nsw i32 %34, -1
store i32 %35, i32* %6
br label %20
36: ; preds = %20
%37 = load double, double* %3
%38 = fsub double %37, 5.000000e-01
%39 = load double, double* %3
%40 = call double @log(double %39)
%41 = load double, double* %3
%42 = fneg double %41
%43 = call double @llvm.fmuladd.f64(double %38, double %40, double %42)
%44 = fadd double %43, 0x3FED67F1C864BEB5
%45 = load double, double* %5
%46 = load double, double* %3
%47 = fdiv double %45, %46
%48 = fadd double %44, %47
store double %48, double* %2
br label %49
49: ; preds = %36, %9
%50 = load double, double* %2
ret double %50
}

LLVM IR (-O2):
define double @sklearn_lgamma(double %0) {
%2 = fcmp olt double %0, 1.200000e+01
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = tail call i32 @sklearn_gamma(double %0)
%5 = tail call double @fabs(i32 %4)
%6 = tail call double @log(double %5)
br label %31
7: ; preds = %1
%8 = fmul double %0, %0
%9 = fdiv double 1.000000e+00, %8
%10 = fmul double %9, 0xBF9E4286CB0F5398
%11 = fadd double %10, 0x3F7A41A41A41A41A
%12 = fmul double %9, %11
%13 = fadd double %12, 0xBF5F6AB0D9993C7D
%14 = fmul double %9, %13
%15 = fadd double %14, 0x3F4B951E2B18FF23
%16 = fmul double %9, %15
%17 = fadd double %16, 0xBF43813813813814
%18 = fmul double %9, %17
%19 = fadd double %18, 0x3F4A01A01A01A01A
%20 = fmul double %9, %19
%21 = fadd double %20, 0xBF66C16C16C16C17
%22 = fmul double %9, %21
%23 = fadd double %22, 0x3FB5555555555555
%24 = fadd double %0, -5.000000e-01
%25 = tail call double @log(double %0)
%26 = fneg double %0
%27 = tail call double @llvm.fmuladd.f64(double %24, double %25, double %26)
%28 = fadd double %27, 0x3FED67F1C864BEB5
%29 = fdiv double %23, %0
%30 = fadd double %29, %28
br label %31
31: ; preds = %7, %3
%32 = phi double [ %6, %3 ], [ %30, %7 ]
ret double %32
}