#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 M_PI;
double ceil(double);
double cos(double);
double fabs(double);
double floor(double);
double large_lgam(double);
double log(double);
int signgam;
double sin(double);
double neg_lgam(double x) {
  int xi;
  double y, z, one = 1.0, zero = 0.0;
  extern double gamma();
  if (x > -170) {
    xi = x;
    if (xi == x) {
      if (1)
        return (one / zero);
      else
        return (0.0);
    }
    y = gamma(x);
    if (y < 0)
      y = -y, signgam = -1;
    return (log(y));
  }
  z = floor(x + .5);
  if (z == x) {
    if (1)
      return (one / zero);
    else
      return (0.0);
  }
  y = .5 * ceil(x);
  if (y == ceil(y))
    signgam = -1;
  x = -x;
  z = fabs(x + z);
  if (z < .25)
    z = sin(M_PI * z);
  else
    z = cos(M_PI * (0.5 - z));
  z = log(M_PI / (z * x));
  y = large_lgam(x);
  return (z - y);
}


x86 assembly (clang, -O0):
<neg_lgam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xe83(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe61(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    123c <neg_lgam+0xcc>
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11db <neg_lgam+0x6b>
jp     11db <neg_lgam+0x6b>
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13a8 <neg_lgam+0x238>
movsd  -0x10(%rbp),%xmm0
mov    $0x1,%al
call   1030 <gamma@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1228 <neg_lgam+0xb8>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2dbe(%rip),%rax
movl   $0xffffffff,(%rax)
movsd  -0x20(%rbp),%xmm0
call   1080 <log@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    13a8 <neg_lgam+0x238>
movsd  0xdcc(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    127d <neg_lgam+0x10d>
jp     127d <neg_lgam+0x10d>
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13a8 <neg_lgam+0x238>
movsd  -0x10(%rbp),%xmm0
call   1040 <ceil@plt>
movaps %xmm0,%xmm1
movsd  0xd7e(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <ceil@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jne    12d4 <neg_lgam+0x164>
jp     12d4 <neg_lgam+0x164>
mov    0x2d12(%rip),%rax
movl   $0xffffffff,(%rax)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movaps 0xd1a(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xd01(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1341 <neg_lgam+0x1d1>
mov    0x2cbf(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    1367 <neg_lgam+0x1f7>
mov    0x2ca0(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xcbc(%rip),%xmm1
subsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1070 <cos@plt>
movsd  %xmm0,-0x28(%rbp)
mov    0x2c7a(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1080 <log@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <large_lgam@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neg_lgam>:
push   %rbx
sub    $0x30,%rsp
movapd %xmm0,%xmm1
ucomisd 0xe7f(%rip),%xmm0
jbe    11cb <neg_lgam+0x5b>
cvttpd2dq %xmm1,%xmm0
cvtdq2pd %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jne    1193 <neg_lgam+0x23>
jnp    11ee <neg_lgam+0x7e>
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1030 <gamma@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11c1 <neg_lgam+0x51>
movapd 0xe70(%rip),%xmm1
xorpd  %xmm1,%xmm0
mov    0x2e25(%rip),%rax
movl   $0xffffffff,(%rax)
add    $0x30,%rsp
pop    %rbx
jmp    1080 <log@plt>
movsd  0xe35(%rip),%xmm0
addsd  %xmm1,%xmm0
movapd %xmm1,(%rsp)
call   1090 <floor@plt>
movapd (%rsp),%xmm1
ucomisd %xmm1,%xmm0
jne    11fb <neg_lgam+0x8b>
jp     11fb <neg_lgam+0x8b>
movsd  0xe1a(%rip),%xmm0
jmp    12cd <neg_lgam+0x15d>
movapd %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
call   1040 <ceil@plt>
mulsd  0xdf6(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
call   1040 <ceil@plt>
movsd  0x28(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    1238 <neg_lgam+0xc8>
jp     1238 <neg_lgam+0xc8>
mov    0x2dae(%rip),%rax
movl   $0xffffffff,(%rax)
movapd (%rsp),%xmm0
movapd 0x10(%rsp),%xmm2
subsd  %xmm0,%xmm2
xorpd  0xdd1(%rip),%xmm0
movapd %xmm0,(%rsp)
andpd  0xdd4(%rip),%xmm2
movsd  0xdb4(%rip),%xmm0
ucomisd %xmm2,%xmm0
mov    0x2d79(%rip),%rbx
movsd  (%rbx),%xmm0
jbe    1280 <neg_lgam+0x110>
mulsd  %xmm2,%xmm0
call   1050 <sin@plt>
jmp    1299 <neg_lgam+0x129>
movsd  0xd80(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1070 <cos@plt>
movsd  (%rbx),%xmm1
mulsd  (%rsp),%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1080 <log@plt>
movsd  %xmm0,0x10(%rsp)
movapd (%rsp),%xmm0
call   1060 <large_lgam@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@signgam = global i32 0
@M_PI = global double 0.000000e+00
define double @neg_lgam(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store double 1.000000e+00, double* %7
store double 0.000000e+00, double* %8
%9 = load double, double* %3
%10 = fcmp ogt double %9, -1.700000e+02
br i1 %10, label %11, label %33
11: ; preds = %1
%12 = load double, double* %3
%13 = fptosi double %12 to i32
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = sitofp i32 %14 to double
%16 = load double, double* %3
%17 = fcmp oeq double %15, %16
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load double, double* %7
%20 = load double, double* %8
%21 = fdiv double %19, %20
store double %21, double* %2
br label %85
22: ; preds = %11
%23 = load double, double* %3
%24 = call double (double, ...) bitcast (double (...)* @gamma to double (double, ...)*)(double %23)
store double %24, double* %5
%25 = load double, double* %5
%26 = fcmp olt double %25, 0.000000e+00
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load double, double* %5
%29 = fneg double %28
store double %29, double* %5
store i32 -1, i32* @signgam
br label %30
30: ; preds = %27, %22
%31 = load double, double* %5
%32 = call double @log(double %31)
store double %32, double* %2
br label %85
33: ; preds = %1
%34 = load double, double* %3
%35 = fadd double %34, 5.000000e-01
%36 = call double @llvm.floor.f64(double %35)
store double %36, double* %6
%37 = load double, double* %6
%38 = load double, double* %3
%39 = fcmp oeq double %37, %38
br i1 %39, label %40, label %44
40: ; preds = %33
%41 = load double, double* %7
%42 = load double, double* %8
%43 = fdiv double %41, %42
store double %43, double* %2
br label %85
44: ; preds = %33
%45 = load double, double* %3
%46 = call double @llvm.ceil.f64(double %45)
%47 = fmul double 5.000000e-01, %46
store double %47, double* %5
%48 = load double, double* %5
%49 = load double, double* %5
%50 = call double @llvm.ceil.f64(double %49)
%51 = fcmp oeq double %48, %50
br i1 %51, label %52, label %53
52: ; preds = %44
store i32 -1, i32* @signgam
br label %53
53: ; preds = %52, %44
%54 = load double, double* %3
%55 = fneg double %54
store double %55, double* %3
%56 = load double, double* %3
%57 = load double, double* %6
%58 = fadd double %56, %57
%59 = call double @llvm.fabs.f64(double %58)
store double %59, double* %6
%60 = load double, double* %6
%61 = fcmp olt double %60, 2.500000e-01
br i1 %61, label %62, label %67
62: ; preds = %53
%63 = load double, double* @M_PI
%64 = load double, double* %6
%65 = fmul double %63, %64
%66 = call double @sin(double %65)
store double %66, double* %6
br label %73
67: ; preds = %53
%68 = load double, double* @M_PI
%69 = load double, double* %6
%70 = fsub double 5.000000e-01, %69
%71 = fmul double %68, %70
%72 = call double @cos(double %71)
store double %72, double* %6
br label %73
73: ; preds = %67, %62
%74 = load double, double* @M_PI
%75 = load double, double* %6
%76 = load double, double* %3
%77 = fmul double %75, %76
%78 = fdiv double %74, %77
%79 = call double @log(double %78)
store double %79, double* %6
%80 = load double, double* %3
%81 = call double @large_lgam(double %80)
store double %81, double* %5
%82 = load double, double* %6
%83 = load double, double* %5
%84 = fsub double %82, %83
store double %84, double* %2
br label %85
85: ; preds = %73, %40, %30, %18
%86 = load double, double* %2
ret double %86
}

LLVM IR (-O2):
@signgam = global i32 0
@M_PI = global double 0.000000e+00
define double @neg_lgam(double %0) {
%2 = fcmp ogt double %0, -1.700000e+02
br i1 %2, label %3, label %15
3: ; preds = %1
%4 = fptosi double %0 to i32
%5 = sitofp i32 %4 to double
%6 = fcmp oeq double %5, %0
br i1 %6, label %46, label %7
7: ; preds = %3
%8 = tail call double (double, ...) bitcast (double (...)* @gamma to double (double, ...)*)(double %0)
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = fneg double %8
store i32 -1, i32* @signgam
br label %12
12: ; preds = %10, %7
%13 = phi double [ %11, %10 ], [ %8, %7 ]
%14 = tail call double @log(double %13)
br label %46
15: ; preds = %1
%16 = fadd double %0, 5.000000e-01
%17 = tail call double @llvm.floor.f64(double %16)
%18 = fcmp oeq double %17, %0
br i1 %18, label %46, label %19
19: ; preds = %15
%20 = tail call double @llvm.ceil.f64(double %0)
%21 = fmul double %20, 5.000000e-01
%22 = tail call double @llvm.ceil.f64(double %21)
%23 = fcmp oeq double %21, %22
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* @signgam
br label %25
25: ; preds = %24, %19
%26 = fneg double %0
%27 = fsub double %17, %0
%28 = tail call double @llvm.fabs.f64(double %27)
%29 = fcmp olt double %28, 2.500000e-01
%30 = load double, double* @M_PI
br i1 %29, label %31, label %34
31: ; preds = %25
%32 = fmul double %28, %30
%33 = tail call double @sin(double %32)
br label %38
34: ; preds = %25
%35 = fsub double 5.000000e-01, %28
%36 = fmul double %35, %30
%37 = tail call double @cos(double %36)
br label %38
38: ; preds = %34, %31
%39 = phi double [ %33, %31 ], [ %37, %34 ]
%40 = load double, double* @M_PI
%41 = fmul double %39, %26
%42 = fdiv double %40, %41
%43 = tail call double @log(double %42)
%44 = tail call double @large_lgam(double %26)
%45 = fsub double %43, %44
br label %46
46: ; preds = %15, %3, %38, %12
%47 = phi double [ %14, %12 ], [ %45, %38 ], [ 0x7FF0000000000000, %3 ], [ 0x7FF0000000000000, %15 ]
ret double %47
}