#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 */
int /*<<< orphan*/ ERANGE;
double HUGE_VAL;
int /*<<< orphan*/ errno;
double fmod(double, double);
double log(double);
double loggamma(double);
double modf(double, double *);
double sin(double);
double lgamma_r(double x, int *signp) {
  if (x <= 0) {
    double i, f, s;
    f = modf(-x, &i);
    if (f == 0.0) {
      *signp = 1;
      errno = ERANGE;
      return HUGE_VAL;
    }
    *signp = (fmod(i, 2.0) != 0.0) ? 1 : -1;
    s = sin(3.14159265358979324 * f);
    if (s < 0)
      s = -s;
    return 1.14472988584940017 - log(s) - loggamma(1 - x);
  }
  *signp = 1;
  return loggamma(x);
}


x86 assembly (clang, -O0):
<lgamma_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     12a4 <lgamma_r+0x154>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
lea    -0x20(%rbp),%rdi
call   1040 <modf@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11e2 <lgamma_r+0x92>
jp     11e2 <lgamma_r+0x92>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    0x2e1e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e05(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e14(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bd <lgamma_r+0x16d>
movsd  -0x20(%rbp),%xmm0
movsd  0xe19(%rip),%xmm1
call   1030 <fmod@plt>
xorps  %xmm1,%xmm1
mov    $0xffffffff,%ecx
mov    $0x1,%eax
ucomisd %xmm1,%xmm0
setp   %sil
setne  %dl
or     %sil,%dl
cmovne %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movsd  0xde0(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1060 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    125e <lgamma_r+0x10e>
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1070 <log@plt>
movaps %xmm0,%xmm1
movsd  0xda5(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xd8c(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1050 <loggamma@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bd <lgamma_r+0x16d>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movsd  -0x10(%rbp),%xmm0
call   1050 <loggamma@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lgamma_r>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    117a <lgamma_r+0x2a>
movl   $0x1,(%rbx)
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
jmp    1050 <loggamma@plt>
movapd 0xe7e(%rip),%xmm0
movapd %xmm1,0x10(%rsp)
xorpd  %xmm1,%xmm0
lea    0x8(%rsp),%rdi
call   1040 <modf@plt>
ucomisd 0xe92(%rip),%xmm0
jne    11ca <lgamma_r+0x7a>
jp     11ca <lgamma_r+0x7a>
movl   $0x1,(%rbx)
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    0x2e18(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e27(%rip),%rax
movsd  (%rax),%xmm0
jmp    126b <lgamma_r+0x11b>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0xe33(%rip),%xmm1
call   1030 <fmod@plt>
xorpd  %xmm1,%xmm1
cmpneqsd %xmm1,%xmm0
movq   %xmm0,%rax
and    $0x1,%eax
add    %eax,%eax
add    $0xffffffff,%eax
mov    %eax,(%rbx)
movsd  (%rsp),%xmm0
mulsd  0xe11(%rip),%xmm0
call   1060 <sin@plt>
movapd 0xdec(%rip),%xmm2
xorpd  %xmm0,%xmm2
movapd %xmm0,%xmm1
cmpltsd 0xe0b(%rip),%xmm1
andpd  %xmm1,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
movapd %xmm1,%xmm0
call   1070 <log@plt>
movsd  0xdde(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xdd5(%rip),%xmm0
subsd  0x10(%rsp),%xmm0
call   1050 <loggamma@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VAL = global double 0.000000e+00
define double @lgamma_r(double %0, i32* %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32*
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store i32* %1, i32** %5
%9 = load double, double* %4
%10 = fcmp ole double %9, 0.000000e+00
br i1 %10, label %11, label %44
11: ; preds = %2
%12 = load double, double* %4
%13 = fneg double %12
%14 = call double @modf(double %13, double* %6)
store double %14, double* %7
%15 = load double, double* %7
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i32*, i32** %5
store i32 1, i32* %18
%19 = load i32, i32* @ERANGE
store i32 %19, i32* @errno
%20 = load double, double* @HUGE_VAL
store double %20, double* %3
br label %48
21: ; preds = %11
%22 = load double, double* %6
%23 = call double @fmod(double %22, double 2.000000e+00)
%24 = fcmp une double %23, 0.000000e+00
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 1, i32 -1
%27 = load i32*, i32** %5
store i32 %26, i32* %27
%28 = load double, double* %7
%29 = fmul double 0x400921FB54442D18, %28
%30 = call double @sin(double %29)
store double %30, double* %8
%31 = load double, double* %8
%32 = fcmp olt double %31, 0.000000e+00
br i1 %32, label %33, label %36
33: ; preds = %21
%34 = load double, double* %8
%35 = fneg double %34
store double %35, double* %8
br label %36
36: ; preds = %33, %21
%37 = load double, double* %8
%38 = call double @log(double %37)
%39 = fsub double 0x3FF250D048E7A1BD, %38
%40 = load double, double* %4
%41 = fsub double 1.000000e+00, %40
%42 = call double @loggamma(double %41)
%43 = fsub double %39, %42
store double %43, double* %3
br label %48
44: ; preds = %2
%45 = load i32*, i32** %5
store i32 1, i32* %45
%46 = load double, double* %4
%47 = call double @loggamma(double %46)
store double %47, double* %3
br label %48
48: ; preds = %44, %36, %17
%49 = load double, double* %3
ret double %49
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VAL = global double 0.000000e+00
define double @lgamma_r(double %0, i32* nocapture writeonly %1) {
%3 = alloca double
%4 = fcmp ugt double %0, 0.000000e+00
br i1 %4, label %30, label %5
5: ; preds = %2
%6 = bitcast double* %3 to i8*
%7 = fneg double %0
%8 = call double @modf(double %7, double* %3)
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %5
store i32 1, i32* %1
%11 = load i32, i32* @ERANGE
store i32 %11, i32* @errno
%12 = load double, double* @HUGE_VAL
br label %28
13: ; preds = %5
%14 = load double, double* %3
%15 = tail call double @fmod(double %14, double 2.000000e+00)
%16 = fcmp une double %15, 0.000000e+00
%17 = select i1 %16, i32 1, i32 -1
store i32 %17, i32* %1
%18 = fmul double %8, 0x400921FB54442D18
%19 = tail call double @sin(double %18)
%20 = fcmp olt double %19, 0.000000e+00
%21 = fneg double %19
%22 = select i1 %20, double %21, double %19
%23 = tail call double @log(double %22)
%24 = fsub double 0x3FF250D048E7A1BD, %23
%25 = fsub double 1.000000e+00, %0
%26 = tail call double @loggamma(double %25)
%27 = fsub double %24, %26
br label %28
28: ; preds = %13, %10
%29 = phi double [ %12, %10 ], [ %27, %13 ]
br label %32
30: ; preds = %2
store i32 1, i32* %1
%31 = tail call double @loggamma(double %0)
br label %32
32: ; preds = %30, %28
%33 = phi double [ %29, %28 ], [ %31, %30 ]
ret double %33
}