#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*/ EDOM;
int /*<<< orphan*/ ERANGE;
double HUGE_VAL;
int /*<<< orphan*/ errno;
int exp(double);
double lgamma_r(double, int *);
double modf(double, double *);
double tgamma(double x) {
  int sign;
  double d;
  if (x == 0.0) {
    errno = ERANGE;
    return 1 / x < 0 ? -HUGE_VAL : HUGE_VAL;
  }
  if (x < 0) {
    static double zero = 0.0;
    double i, f;
    f = modf(-x, &i);
    if (f == 0.0) {
      errno = EDOM;
      return zero / zero;
    }
  }
  d = lgamma_r(x, &sign);
  return sign * exp(d);
}


x86 assembly (clang, -O0):
<tgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11cc <tgamma+0x9c>
jp     11cc <tgamma+0x9c>
mov    0x2e7c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e63(%rip),%rax
mov    %ecx,(%rax)
movsd  0xe91(%rip),%xmm1
divsd  -0x10(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11ad <tgamma+0x7d>
mov    0x2e60(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11bd <tgamma+0x8d>
mov    0x2e34(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1281 <tgamma+0x151>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    124d <tgamma+0x11d>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
lea    -0x28(%rbp),%rdi
call   1040 <modf@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1248 <tgamma+0x118>
jp     1248 <tgamma+0x118>
mov    0x2dbd(%rip),%rax
mov    (%rax),%ecx
mov    0x2d9c(%rip),%rax
mov    %ecx,(%rax)
movsd  0x2e1a(%rip),%xmm0
divsd  0x2e12(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1281 <tgamma+0x151>
jmp    124d <tgamma+0x11d>
movsd  -0x10(%rbp),%xmm0
lea    -0x14(%rbp),%rdi
call   1030 <lgamma_r@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <exp@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tgamma>:
push   %rbx
sub    $0x30,%rsp
movapd %xmm0,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118d <tgamma+0x5d>
jp     118d <tgamma+0x5d>
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    0x2e73(%rip),%rcx
mov    %eax,(%rcx)
movsd  0xeb9(%rip),%xmm0
divsd  %xmm2,%xmm0
mov    0x2e7e(%rip),%rax
movsd  (%rax),%xmm2
movapd 0xe8a(%rip),%xmm3
xorpd  %xmm2,%xmm3
cmpltsd %xmm1,%xmm0
andpd  %xmm0,%xmm3
andnpd %xmm2,%xmm0
orpd   %xmm3,%xmm0
jmp    11fe <tgamma+0xce>
ucomisd %xmm2,%xmm1
jbe    11dd <tgamma+0xad>
movapd 0xe65(%rip),%xmm0
xorpd  %xmm2,%xmm0
lea    0x28(%rsp),%rdi
movapd %xmm2,0x10(%rsp)
call   1040 <modf@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d7 <tgamma+0xa7>
jp     11d7 <tgamma+0xa7>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    0x2dfd(%rip),%rcx
mov    %eax,(%rcx)
movsd  0xe3b(%rip),%xmm0
jmp    11fe <tgamma+0xce>
movapd 0x10(%rsp),%xmm2
lea    0xc(%rsp),%rdi
movapd %xmm2,%xmm0
call   1030 <lgamma_r@plt>
mov    0xc(%rsp),%ebx
call   1050 <exp@plt>
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VAL = global double 0.000000e+00
@tgamma.zero = internal global double 0.000000e+00
@EDOM = global i32 0
define double @tgamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %3
%8 = load double, double* %3
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %22
10: ; preds = %1
%11 = load i32, i32* @ERANGE
store i32 %11, i32* @errno
%12 = load double, double* %3
%13 = fdiv double 1.000000e+00, %12
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load double, double* @HUGE_VAL
%17 = fneg double %16
br label %20
18: ; preds = %10
%19 = load double, double* @HUGE_VAL
br label %20
20: ; preds = %18, %15
%21 = phi double [ %17, %15 ], [ %19, %18 ]
store double %21, double* %2
br label %45
22: ; preds = %1
%23 = load double, double* %3
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load double, double* %3
%27 = fneg double %26
%28 = call double @modf(double %27, double* %6)
store double %28, double* %7
%29 = load double, double* %7
%30 = fcmp oeq double %29, 0.000000e+00
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = load i32, i32* @EDOM
store i32 %32, i32* @errno
%33 = load double, double* @tgamma.zero
%34 = load double, double* @tgamma.zero
%35 = fdiv double %33, %34
store double %35, double* %2
br label %45
36: ; preds = %25
br label %37
37: ; preds = %36, %22
%38 = load double, double* %3
%39 = call double @lgamma_r(double %38, i32* %4)
store double %39, double* %5
%40 = load i32, i32* %4
%41 = load double, double* %5
%42 = call i32 @exp(double %41)
%43 = mul nsw i32 %40, %42
%44 = sitofp i32 %43 to double
store double %44, double* %2
br label %45
45: ; preds = %37, %31, %20
%46 = load double, double* %2
ret double %46
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VAL = global double 0.000000e+00
@EDOM = global i32 0
define double @tgamma(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = bitcast i32* %2 to i8*
%5 = fcmp oeq double %0, 0.000000e+00
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i32, i32* @ERANGE
store i32 %7, i32* @errno
%8 = fdiv double 1.000000e+00, %0
%9 = fcmp olt double %8, 0.000000e+00
%10 = load double, double* @HUGE_VAL
%11 = fneg double %10
%12 = select i1 %9, double %11, double %10
br label %29
13: ; preds = %1
%14 = fcmp olt double %0, 0.000000e+00
br i1 %14, label %15, label %23
15: ; preds = %13
%16 = bitcast double* %3 to i8*
%17 = fneg double %0
%18 = call double @modf(double %17, double* %3)
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* @EDOM
store i32 %21, i32* @errno
br label %29
22: ; preds = %15
br label %23
23: ; preds = %22, %13
%24 = call double @lgamma_r(double %0, i32* %2)
%25 = load i32, i32* %2
%26 = call i32 @exp(double %24)
%27 = mul nsw i32 %26, %25
%28 = sitofp i32 %27 to double
br label %29
29: ; preds = %20, %23, %6
%30 = phi double [ %12, %6 ], [ %28, %23 ], [ 0x7FF8000000000000, %20 ]
ret double %30
}