#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(double);
double log(double);
double sin(double);
double lgamma(double z) {
  static double a[] = {
      .99999999999980993227684700473478296744476168282198,
      676.52036812188509856700919044401903816411251975244084,
      -1259.13921672240287047156078755282840836424300664868028,
      771.32342877765307884865282588943070775227268469602500,
      -176.61502916214059906584551353999392943274507608117860,
      12.50734327868690481445893685327104972970563021816420,
      -.13857109526572011689554706984971501358032683492780,
      .00000998436957801957085956266828104544089848531228,
      .00000015056327351493115583383579667028994545044040,
  };
  double sum, ZPos, LG, tmp;
  int i;
  if (z <= 0.0)
    ZPos = 1.0 - z;
  else
    ZPos = z;
  sum = a[0];
  for (i = 1, tmp = ZPos; i < 9; i++) {
    sum += a[i] / tmp;
    tmp++;
  }
  LG = log(sum) + 0.9189385332046727 - ZPos - 6.5 +
       (ZPos - 0.5) * log(ZPos + 6.5);
  if (z <= 0.0) {
    tmp = sin(z * 3.14159265358979323846);
    if (fabs(tmp) < 1.0E-08)
      tmp = 0.0;
    else if (tmp < 0.0)
      tmp = -tmp;
    LG = 1.14472988584940016 - LG - log(tmp);
  }
  return LG;
}


x86 assembly (clang, -O0):
<lgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1152 <lgamma+0x32>
movsd  0xebd(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    115c <lgamma+0x3c>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0x2edc(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x9,-0x2c(%rbp)
jge    11c3 <lgamma+0xa3>
movslq -0x2c(%rbp),%rcx
lea    0x2eb1(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x28(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe55(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117a <lgamma+0x5a>
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movsd  0xe43(%rip),%xmm1
addsd  %xmm1,%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe22(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe14(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xdfb(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     12e6 <lgamma+0x1c6>
movsd  0xde1(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movaps 0xdde(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xdb2(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1285 <lgamma+0x165>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12b9 <lgamma+0x199>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    12b4 <lgamma+0x194>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12b9 <lgamma+0x199>
movsd  0xd6f(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lgamma>:
sub    $0x38,%rsp
movapd %xmm0,0x20(%rsp)
movsd  0xece(%rip),%xmm5
movapd %xmm5,%xmm1
subsd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
cmplesd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
movapd %xmm3,(%rsp)
movapd %xmm3,%xmm1
addsd  %xmm5,%xmm1
movapd %xmm3,%xmm2
unpcklpd %xmm1,%xmm2
movapd 0xee0(%rip),%xmm3
divpd  %xmm2,%xmm3
movsd  0xe8c(%rip),%xmm2
addsd  %xmm3,%xmm2
unpckhpd %xmm3,%xmm3
addsd  %xmm2,%xmm3
addsd  %xmm5,%xmm1
movapd %xmm1,%xmm2
addsd  %xmm5,%xmm2
unpcklpd %xmm2,%xmm1
movapd 0xec0(%rip),%xmm4
divpd  %xmm1,%xmm4
addsd  %xmm4,%xmm3
unpckhpd %xmm4,%xmm4
addsd  %xmm3,%xmm4
addsd  %xmm5,%xmm2
movapd %xmm2,%xmm1
addsd  %xmm5,%xmm1
unpcklpd %xmm1,%xmm2
movapd 0xea8(%rip),%xmm3
divpd  %xmm2,%xmm3
addsd  %xmm3,%xmm4
unpckhpd %xmm3,%xmm3
addsd  %xmm4,%xmm3
addsd  %xmm5,%xmm1
addsd  %xmm1,%xmm5
unpcklpd %xmm5,%xmm1
movapd 0xe94(%rip),%xmm0
divpd  %xmm1,%xmm0
addsd  %xmm0,%xmm3
unpckhpd %xmm0,%xmm0
addsd  %xmm3,%xmm0
call   1040 <log@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0xe01(%rip),%xmm0
addsd  (%rsp),%xmm0
call   1040 <log@plt>
xorpd  %xmm1,%xmm1
movapd 0x20(%rsp),%xmm2
ucomisd %xmm2,%xmm1
movapd %xmm2,%xmm1
movsd  0x18(%rsp),%xmm3
addsd  0xddf(%rip),%xmm3
movapd (%rsp),%xmm2
subsd  %xmm2,%xmm3
addsd  0xdd6(%rip),%xmm3
addsd  0xdd6(%rip),%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
addsd  %xmm3,%xmm0
jb     12d8 <lgamma+0x1b8>
movapd %xmm0,(%rsp)
mulsd  0xdc3(%rip),%xmm1
movapd %xmm1,%xmm0
call   1030 <sin@plt>
movapd 0xe12(%rip),%xmm1
andpd  %xmm0,%xmm1
movsd  0xdae(%rip),%xmm2
ucomisd %xmm1,%xmm2
xorpd  %xmm1,%xmm1
ja     12b0 <lgamma+0x190>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    12ac <lgamma+0x18c>
movapd 0xdfa(%rip),%xmm1
xorpd  %xmm0,%xmm1
jmp    12b0 <lgamma+0x190>
movapd %xmm0,%xmm1
movsd  0xd88(%rip),%xmm0
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
call   1040 <log@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
@lgamma.a = internal global [9 x double] [double 0x3FEFFFFFFFFFF950, double 0x40852429B6C30B05, double 0xC093AC8E8ED4171B, double 0x40881A9661D3B4D8, double 0xC06613AE51A32F5D, double 0x402903C27F8B9C81, double 0xBFC1BCB2992B2855, double 0x3EE4F0514E4E324F, double 0x3E8435508F3FAEEF]
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
%9 = fcmp ole double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load double, double* %2
%12 = fsub double 1.000000e+00, %11
store double %12, double* %4
br label %15
13: ; preds = %1
%14 = load double, double* %2
store double %14, double* %4
br label %15
15: ; preds = %13, %10
%16 = load double, double* getelementptr inbounds ([9 x double], [9 x double]* @lgamma.a, i64 0, i64 0)
store double %16, double* %3
store i32 1, i32* %7
%17 = load double, double* %4
store double %17, double* %6
br label %18
18: ; preds = %32, %15
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 9
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [9 x double], [9 x double]* @lgamma.a, i64 0, i64 %23
%25 = load double, double* %24
%26 = load double, double* %6
%27 = fdiv double %25, %26
%28 = load double, double* %3
%29 = fadd double %28, %27
store double %29, double* %3
%30 = load double, double* %6
%31 = fadd double %30, 1.000000e+00
store double %31, double* %6
br label %32
32: ; preds = %21
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %18
35: ; preds = %18
%36 = load double, double* %3
%37 = call double @log(double %36)
%38 = fadd double %37, 0x3FED67F1C864BEB4
%39 = load double, double* %4
%40 = fsub double %38, %39
%41 = fsub double %40, 6.500000e+00
%42 = load double, double* %4
%43 = fsub double %42, 5.000000e-01
%44 = load double, double* %4
%45 = fadd double %44, 6.500000e+00
%46 = call double @log(double %45)
%47 = call double @llvm.fmuladd.f64(double %43, double %46, double %41)
store double %47, double* %5
%48 = load double, double* %2
%49 = fcmp ole double %48, 0.000000e+00
br i1 %49, label %50, label %71
50: ; preds = %35
%51 = load double, double* %2
%52 = fmul double %51, 0x400921FB54442D18
%53 = call double @sin(double %52)
store double %53, double* %6
%54 = load double, double* %6
%55 = call double @llvm.fabs.f64(double %54)
%56 = fcmp olt double %55, 1.000000e-08
br i1 %56, label %57, label %58
57: ; preds = %50
store double 0.000000e+00, double* %6
br label %65
58: ; preds = %50
%59 = load double, double* %6
%60 = fcmp olt double %59, 0.000000e+00
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load double, double* %6
%63 = fneg double %62
store double %63, double* %6
br label %64
64: ; preds = %61, %58
br label %65
65: ; preds = %64, %57
%66 = load double, double* %5
%67 = fsub double 0x3FF250D048E7A1BD, %66
%68 = load double, double* %6
%69 = call double @log(double %68)
%70 = fsub double %67, %69
store double %70, double* %5
br label %71
71: ; preds = %65, %35
%72 = load double, double* %5
ret double %72
}

LLVM IR (-O2):
define double @lgamma(double %0) {
%2 = fcmp ole double %0, 0.000000e+00
%3 = fsub double 1.000000e+00, %0
%4 = select i1 %2, double %3, double %0
%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 0x40852429B6C30B05, double 0xC093AC8E8ED4171B>, %7
%9 = extractelement <2 x double> %8, i64 0
%10 = fadd double %9, 0x3FEFFFFFFFFFF950
%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 0x40881A9661D3B4D8, double 0xC06613AE51A32F5D>, %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 0x402903C27F8B9C81, double 0xBFC1BCB2992B2855>, %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 %23, 1.000000e+00
%32 = fadd double %31, 1.000000e+00
%33 = insertelement <2 x double> poison, double %31, i64 0
%34 = insertelement <2 x double> %33, double %32, i64 1
%35 = fdiv <2 x double> <double 0x3EE4F0514E4E324F, double 0x3E8435508F3FAEEF>, %34
%36 = extractelement <2 x double> %35, i64 0
%37 = fadd double %30, %36
%38 = extractelement <2 x double> %35, i64 1
%39 = fadd double %37, %38
%40 = tail call double @log(double %39)
%41 = fadd double %40, 0x3FED67F1C864BEB4
%42 = fsub double %41, %4
%43 = fadd double %42, -6.500000e+00
%44 = fadd double %4, -5.000000e-01
%45 = fadd double %4, 6.500000e+00
%46 = tail call double @log(double %45)
%47 = tail call double @llvm.fmuladd.f64(double %44, double %46, double %43)
br i1 %2, label %48, label %62
48: ; preds = %1
%49 = fmul double %0, 0x400921FB54442D18
%50 = tail call double @sin(double %49)
%51 = tail call double @llvm.fabs.f64(double %50)
%52 = fcmp olt double %51, 1.000000e-08
br i1 %52, label %57, label %53
53: ; preds = %48
%54 = fcmp olt double %50, 0.000000e+00
br i1 %54, label %55, label %57
55: ; preds = %53
%56 = fneg double %50
br label %57
57: ; preds = %48, %53, %55
%58 = phi double [ %56, %55 ], [ %50, %53 ], [ 0.000000e+00, %48 ]
%59 = fsub double 0x3FF250D048E7A1BD, %47
%60 = tail call double @log(double %58)
%61 = fsub double %59, %60
br label %62
62: ; preds = %57, %1
%63 = phi double [ %61, %57 ], [ %47, %1 ]
ret double %63
}