#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 NormalP(double);
double fabs(double);
double log(double);
double sqrt(double);
double ChiSqPN(unsigned long degfree, double x2) {
  double d, z, s = degfree - 1;
  if (fabs(x2 - s) < 0.1) {
    z = ((double)1.0 / 3.0) + (0.08 / degfree);
    z = -z / sqrt(s + s);
  } else {
    d = x2 - degfree + ((double)2.0 / 3.0) - ((double)0.08 / degfree);
    if (degfree == 1)
      z = sqrt(x2);
    else
      z = sqrt((s * log(s / x2)) + x2 - s);
    z = (d * z) / fabs(x2 - s);
  }
  return NormalP(z);
}


x86 assembly (clang, -O0):
<ChiSqPN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
movq   %rax,%xmm0
movaps 0xedb(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xedf(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movaps 0xe9a(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe6e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1226 <ChiSqPN+0xf6>
movaps 0xe8d(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe8c(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe3d(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe41(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12fb <ChiSqPN+0x1cb>
movsd  -0x10(%rbp),%xmm0
movaps 0xdfe(%rip),%xmm1
movq   -0x8(%rbp),%xmm2
punpckldq %xmm1,%xmm2
movapd 0xdfd(%rip),%xmm1
subpd  %xmm1,%xmm2
movaps %xmm2,%xmm1
unpckhpd %xmm2,%xmm2
addsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
movsd  0xdb2(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xd9e(%rip),%xmm1
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpq   $0x1,-0x8(%rbp)
jne    1296 <ChiSqPN+0x166>
movsd  -0x10(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    12d3 <ChiSqPN+0x1a3>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movaps 0xd32(%rip),%xmm2
pand   %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <NormalP@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ChiSqPN>:
sub    $0x48,%rsp
movapd %xmm0,%xmm5
lea    -0x1(%rdi),%rax
movq   %rax,%xmm0
movdqa 0xeb7(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xebb(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm6
unpckhpd %xmm0,%xmm6
addsd  %xmm0,%xmm6
movapd %xmm5,%xmm4
subsd  %xmm6,%xmm4
andpd  0xeab(%rip),%xmm4
movsd  0xec3(%rip),%xmm0
ucomisd %xmm4,%xmm0
movq   %rdi,%xmm3
punpckldq %xmm1,%xmm3
subpd  %xmm2,%xmm3
movapd %xmm3,%xmm0
unpckhpd %xmm3,%xmm0
addsd  %xmm3,%xmm0
jbe    11da <ChiSqPN+0xaa>
movsd  0xeb4(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0xeb0(%rip),%xmm1
xorpd  0xe78(%rip),%xmm1
addsd  %xmm6,%xmm6
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm6
jb     1260 <ChiSqPN+0x130>
xorps  %xmm0,%xmm0
sqrtsd %xmm6,%xmm0
divsd  %xmm0,%xmm1
jmp    129a <ChiSqPN+0x16a>
movapd %xmm5,%xmm1
subsd  %xmm0,%xmm1
addsd  0xe5e(%rip),%xmm1
movsd  0xe5e(%rip),%xmm2
divsd  %xmm0,%xmm2
cmp    $0x1,%rdi
movapd %xmm4,0x20(%rsp)
je     1249 <ChiSqPN+0x119>
movapd %xmm6,%xmm0
divsd  %xmm5,%xmm0
movapd %xmm1,(%rsp)
movsd  %xmm5,0x10(%rsp)
movapd %xmm6,0x30(%rsp)
movsd  %xmm2,0x18(%rsp)
call   1040 <log@plt>
movsd  0x18(%rsp),%xmm2
movapd (%rsp),%xmm1
movapd %xmm0,%xmm5
movapd 0x30(%rsp),%xmm3
mulsd  %xmm3,%xmm5
addsd  0x10(%rsp),%xmm5
subsd  %xmm3,%xmm5
addsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm5
jb     1279 <ChiSqPN+0x149>
xorps  %xmm0,%xmm0
sqrtsd %xmm5,%xmm0
jmp    128c <ChiSqPN+0x15c>
movapd %xmm6,%xmm0
movapd %xmm1,(%rsp)
call   1050 <sqrt@plt>
movapd (%rsp),%xmm1
divsd  %xmm0,%xmm1
jmp    129a <ChiSqPN+0x16a>
movapd %xmm5,%xmm0
movapd %xmm1,(%rsp)
call   1050 <sqrt@plt>
movapd (%rsp),%xmm1
movapd 0x20(%rsp),%xmm2
mulsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
add    $0x48,%rsp
jmp    1030 <NormalP@plt>

LLVM IR (-O0):
define double @ChiSqPN(i64 %0, double %1) {
%3 = alloca i64
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i64 %0, i64* %3
store double %1, double* %4
%8 = load i64, i64* %3
%9 = sub i64 %8, 1
%10 = uitofp i64 %9 to double
store double %10, double* %7
%11 = load double, double* %4
%12 = load double, double* %7
%13 = fsub double %11, %12
%14 = call double @llvm.fabs.f64(double %13)
%15 = fcmp olt double %14, 1.000000e-01
br i1 %15, label %16, label %28
16: ; preds = %2
%17 = load i64, i64* %3
%18 = uitofp i64 %17 to double
%19 = fdiv double 8.000000e-02, %18
%20 = fadd double 0x3FD5555555555555, %19
store double %20, double* %6
%21 = load double, double* %6
%22 = fneg double %21
%23 = load double, double* %7
%24 = load double, double* %7
%25 = fadd double %23, %24
%26 = call double @sqrt(double %25)
%27 = fdiv double %22, %26
store double %27, double* %6
br label %63
28: ; preds = %2
%29 = load double, double* %4
%30 = load i64, i64* %3
%31 = uitofp i64 %30 to double
%32 = fsub double %29, %31
%33 = fadd double %32, 0x3FE5555555555555
%34 = load i64, i64* %3
%35 = uitofp i64 %34 to double
%36 = fdiv double 8.000000e-02, %35
%37 = fsub double %33, %36
store double %37, double* %5
%38 = load i64, i64* %3
%39 = icmp eq i64 %38, 1
br i1 %39, label %40, label %43
40: ; preds = %28
%41 = load double, double* %4
%42 = call double @sqrt(double %41)
store double %42, double* %6
br label %54
43: ; preds = %28
%44 = load double, double* %7
%45 = load double, double* %7
%46 = load double, double* %4
%47 = fdiv double %45, %46
%48 = call double @log(double %47)
%49 = load double, double* %4
%50 = call double @llvm.fmuladd.f64(double %44, double %48, double %49)
%51 = load double, double* %7
%52 = fsub double %50, %51
%53 = call double @sqrt(double %52)
store double %53, double* %6
br label %54
54: ; preds = %43, %40
%55 = load double, double* %5
%56 = load double, double* %6
%57 = fmul double %55, %56
%58 = load double, double* %4
%59 = load double, double* %7
%60 = fsub double %58, %59
%61 = call double @llvm.fabs.f64(double %60)
%62 = fdiv double %57, %61
store double %62, double* %6
br label %63
63: ; preds = %54, %16
%64 = load double, double* %6
%65 = call double @NormalP(double %64)
ret double %65
}

LLVM IR (-O2):
define double @ChiSqPN(i64 %0, double %1) {
%3 = add i64 %0, -1
%4 = uitofp i64 %3 to double
%5 = fsub double %1, %4
%6 = tail call double @llvm.fabs.f64(double %5)
%7 = fcmp olt double %6, 1.000000e-01
%8 = uitofp i64 %0 to double
br i1 %7, label %9, label %16
9: ; preds = %2
%10 = fdiv double 8.000000e-02, %8
%11 = fadd double %10, 0x3FD5555555555555
%12 = fneg double %11
%13 = fadd double %4, %4
%14 = tail call double @sqrt(double %13)
%15 = fdiv double %12, %14
br label %32
16: ; preds = %2
%17 = fsub double %1, %8
%18 = fadd double %17, 0x3FE5555555555555
%19 = fdiv double 8.000000e-02, %8
%20 = fsub double %18, %19
%21 = icmp eq i64 %0, 1
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = fdiv double %4, %1
%24 = tail call double @log(double %23)
%25 = tail call double @llvm.fmuladd.f64(double %4, double %24, double %1)
%26 = fsub double %25, %4
br label %27
27: ; preds = %16, %22
%28 = phi double [ %26, %22 ], [ %1, %16 ]
%29 = tail call double @sqrt(double %28)
%30 = fmul double %20, %29
%31 = fdiv double %30, %6
br label %32
32: ; preds = %27, %9
%33 = phi double [ %15, %9 ], [ %31, %27 ]
%34 = tail call double @NormalP(double %33)
ret double %34
}