#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 exp(double);
double expl(long double);
long double log_gamma(double);
long double log_igf(double, double);
double chisqr(int Dof, double Cv) {
  if (Cv < 0 || Dof < 1) {
    return 0.0;
  }
  double K = ((double)Dof) * 0.5;
  double X = Cv * 0.5;
  if (Dof == 2) {
    return exp(-1.0 * X);
  }
  long double PValue, Gam;
  long double ln_PV;
  ln_PV = log_igf(K, X);
  Gam = log_gamma(K);
  ln_PV -= Gam;
  PValue = 1.0 - expl(ln_PV);
  return (double)PValue;
}


x86 assembly (clang, -O0):
<chisqr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
ja     116b <chisqr+0x2b>
cmpl   $0x1,-0xc(%rbp)
jge    1178 <chisqr+0x38>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1227 <chisqr+0xe7>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe7b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe6a(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    11c6 <chisqr+0x86>
movsd  0xe5e(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1060 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1227 <chisqr+0xe7>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1040 <log_igf@plt>
fstpt  -0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <log_gamma@plt>
fstpt  -0x50(%rbp)
fldt   -0x50(%rbp)
fldt   -0x60(%rbp)
fsubp  %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1050 <expl@plt>
movaps %xmm0,%xmm1
movsd  0xe00(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
fldl   -0x68(%rbp)
fstpt  -0x40(%rbp)
fldt   -0x40(%rbp)
fstpl  -0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chisqr>:
sub    $0x28,%rsp
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
test   %edi,%edi
jle    11c3 <chisqr+0x83>
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
ja     11c3 <chisqr+0x83>
movsd  0xe9e(%rip),%xmm2
mulsd  %xmm2,%xmm1
cmp    $0x2,%edi
jne    1180 <chisqr+0x40>
xorpd  0xe9d(%rip),%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
jmp    1060 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <log_igf@plt>
fstpt  0x1c(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <log_gamma@plt>
fldt   0x1c(%rsp)
fsubp  %st,%st(1)
fstpt  (%rsp)
call   1050 <expl@plt>
movapd %xmm0,%xmm1
movsd  0xe49(%rip),%xmm0
subsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @chisqr(i32 %0, double %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca x86_fp80
%9 = alloca x86_fp80
%10 = alloca x86_fp80
store i32 %0, i32* %4
store double %1, double* %5
%11 = load double, double* %5
%12 = fcmp olt double %11, 0.000000e+00
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %13, %2
store double 0.000000e+00, double* %3
br label %44
17: ; preds = %13
%18 = load i32, i32* %4
%19 = sitofp i32 %18 to double
%20 = fmul double %19, 5.000000e-01
store double %20, double* %6
%21 = load double, double* %5
%22 = fmul double %21, 5.000000e-01
store double %22, double* %7
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = load double, double* %7
%27 = fmul double -1.000000e+00, %26
%28 = call double @exp(double %27)
store double %28, double* %3
br label %44
29: ; preds = %17
%30 = load double, double* %6
%31 = load double, double* %7
%32 = call x86_fp80 @log_igf(double %30, double %31)
store x86_fp80 %32, x86_fp80* %10
%33 = load double, double* %6
%34 = call x86_fp80 @log_gamma(double %33)
store x86_fp80 %34, x86_fp80* %9
%35 = load x86_fp80, x86_fp80* %9
%36 = load x86_fp80, x86_fp80* %10
%37 = fsub x86_fp80 %36, %35
store x86_fp80 %37, x86_fp80* %10
%38 = load x86_fp80, x86_fp80* %10
%39 = call double @expl(x86_fp80 %38)
%40 = fsub double 1.000000e+00, %39
%41 = fpext double %40 to x86_fp80
store x86_fp80 %41, x86_fp80* %8
%42 = load x86_fp80, x86_fp80* %8
%43 = fptrunc x86_fp80 %42 to double
store double %43, double* %3
br label %44
44: ; preds = %29, %25, %16
%45 = load double, double* %3
ret double %45
}

LLVM IR (-O2):
define double @chisqr(i32 %0, double %1) {
%3 = fcmp olt double %1, 0.000000e+00
%4 = icmp slt i32 %0, 1
%5 = or i1 %4, %3
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = sitofp i32 %0 to double
%8 = fmul double %7, 5.000000e-01
%9 = fmul double %1, 5.000000e-01
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = fneg double %9
%13 = tail call double @exp(double %12)
br label %20
14: ; preds = %6
%15 = tail call x86_fp80 @log_igf(double %8, double %9)
%16 = tail call x86_fp80 @log_gamma(double %8)
%17 = fsub x86_fp80 %15, %16
%18 = tail call double @expl(x86_fp80 %17)
%19 = fsub double 1.000000e+00, %18
br label %20
20: ; preds = %11, %14, %2
%21 = phi double [ 0.000000e+00, %2 ], [ %13, %11 ], [ %19, %14 ]
ret double %21
}