double chiSquaredDistribution(double chi, int dof) {
  int i;
  double p = 1.0;
  double chi2Distribution[10][3] = {
      {3.84, 6.64, 10.83},   {5.99, 9.21, 13.82},   {7.82, 11.34, 16.27},
      {9.49, 13.28, 18.47},  {11.07, 15.09, 20.52}, {12.59, 16.81, 22.46},
      {14.07, 18.48, 24.32}, {15.51, 20.09, 26.12}, {16.92, 21.67, 27.88},
      {18.31, 23.21, 29.59}};
  double prob[3] = {0.05, 0.01, 0.001};
  if (dof > 10)
    dof = 10;
  for (i = 0; i < 3; i++)
    if (chi >= chi2Distribution[dof - 1][i])
      p = prob[i];
  return p;
}


x86 assembly (clang, -O0):
<chiSquaredDistribution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  0xed5(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0xf0,%edx
call   1030 <memcpy@plt>
mov    0xfb1(%rip),%rax
mov    %rax,-0x130(%rbp)
mov    0xfab(%rip),%rax
mov    %rax,-0x128(%rbp)
mov    0xfa5(%rip),%rax
mov    %rax,-0x120(%rbp)
cmpl   $0xa,-0xc(%rbp)
jle    1183 <chiSquaredDistribution+0x73>
movl   $0xa,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    11e4 <chiSquaredDistribution+0xd4>
movsd  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    -0x110(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jb     11d1 <chiSquaredDistribution+0xc1>
movslq -0x10(%rbp),%rax
movsd  -0x130(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0x18(%rbp)
jmp    11d6 <chiSquaredDistribution+0xc6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118a <chiSquaredDistribution+0x7a>
movsd  -0x18(%rbp),%xmm0
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chiSquaredDistribution>:
cmp    $0xa,%edi
mov    $0xa,%eax
cmovl  %edi,%eax
add    $0xffffffff,%eax
cltq
lea    (%rax,%rax,2),%rax
lea    0xf05(%rip),%rcx
xor    %edx,%edx
ucomisd (%rcx,%rax,8),%xmm0
setb   %dl
lea    0xed4(%rip),%rsi
movsd  (%rsi,%rdx,8),%xmm2
movsd  0x8(%rcx,%rax,8),%xmm3
movsd  0x10(%rcx,%rax,8),%xmm1
cmpnlesd %xmm0,%xmm3
andpd  %xmm3,%xmm2
movsd  0xec2(%rip),%xmm4
andnpd %xmm4,%xmm3
orpd   %xmm2,%xmm3
cmpnlesd %xmm0,%xmm1
andpd  %xmm1,%xmm3
movsd  0xeb1(%rip),%xmm0
andnpd %xmm0,%xmm1
orpd   %xmm3,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
@__const.chiSquaredDistribution.chi2Distribution = [10 x [3 x double]] [[3 x double] [double 3.840000e+00, double 6.640000e+00, double 1.083000e+01], [3 x double] [double 5.990000e+00, double 9.210000e+00, double 1.382000e+01], [3 x double] [double 7.820000e+00, double 1.134000e+01, double 1.627000e+01], [3 x double] [double 9.490000e+00, double 1.328000e+01, double 1.847000e+01], [3 x double] [double 1.107000e+01, double 1.509000e+01, double 2.052000e+01], [3 x double] [double 1.259000e+01, double 1.681000e+01, double 2.246000e+01], [3 x double] [double 1.407000e+01, double 1.848000e+01, double 2.432000e+01], [3 x double] [double 1.551000e+01, double 2.009000e+01, double 2.612000e+01], [3 x double] [double 1.692000e+01, double 2.167000e+01, double 2.788000e+01], [3 x double] [double 1.831000e+01, double 2.321000e+01, double 2.959000e+01]]
@__const.chiSquaredDistribution.prob = [3 x double] [double 5.000000e-02, double 1.000000e-02, double 1.000000e-03]
define double @chiSquaredDistribution(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca [10 x [3 x double]]
%8 = alloca [3 x double]
store double %0, double* %3
store i32 %1, i32* %4
store double 1.000000e+00, double* %6
%9 = bitcast [10 x [3 x double]]* %7 to i8*
%10 = bitcast [3 x double]* %8 to i8*
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 10
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 10, i32* %4
br label %14
14: ; preds = %13, %2
store i32 0, i32* %5
br label %15
15: ; preds = %35, %14
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %38
18: ; preds = %15
%19 = load double, double* %3
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10 x [3 x double]], [10 x [3 x double]]* %7, i64 0, i64 %22
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 0, i64 %25
%27 = load double, double* %26
%28 = fcmp oge double %19, %27
br i1 %28, label %29, label %34
29: ; preds = %18
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 %31
%33 = load double, double* %32
store double %33, double* %6
br label %34
34: ; preds = %29, %18
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %15
38: ; preds = %15
%39 = load double, double* %6
ret double %39
}

LLVM IR (-O2):
@__const.chiSquaredDistribution.chi2Distribution = [10 x [3 x double]] [[3 x double] [double 3.840000e+00, double 6.640000e+00, double 1.083000e+01], [3 x double] [double 5.990000e+00, double 9.210000e+00, double 1.382000e+01], [3 x double] [double 7.820000e+00, double 1.134000e+01, double 1.627000e+01], [3 x double] [double 9.490000e+00, double 1.328000e+01, double 1.847000e+01], [3 x double] [double 1.107000e+01, double 1.509000e+01, double 2.052000e+01], [3 x double] [double 1.259000e+01, double 1.681000e+01, double 2.246000e+01], [3 x double] [double 1.407000e+01, double 1.848000e+01, double 2.432000e+01], [3 x double] [double 1.551000e+01, double 2.009000e+01, double 2.612000e+01], [3 x double] [double 1.692000e+01, double 2.167000e+01, double 2.788000e+01], [3 x double] [double 1.831000e+01, double 2.321000e+01, double 2.959000e+01]]
define double @chiSquaredDistribution(double %0, i32 %1) {
%3 = icmp slt i32 %1, 10
%4 = select i1 %3, i32 %1, i32 10
%5 = add nsw i32 %4, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [10 x [3 x double]], [10 x [3 x double]]* @__const.chiSquaredDistribution.chi2Distribution, i64 0, i64 %6, i64 0
%8 = load double, double* %7
%9 = fcmp ugt double %8, %0
%10 = select i1 %9, double 1.000000e+00, double 5.000000e-02
%11 = getelementptr inbounds [10 x [3 x double]], [10 x [3 x double]]* @__const.chiSquaredDistribution.chi2Distribution, i64 0, i64 %6, i64 1
%12 = load double, double* %11
%13 = fcmp ugt double %12, %0
%14 = select i1 %13, double %10, double 1.000000e-02
%15 = getelementptr inbounds [10 x [3 x double]], [10 x [3 x double]]* @__const.chiSquaredDistribution.chi2Distribution, i64 0, i64 %6, i64 2
%16 = load double, double* %15
%17 = fcmp ugt double %16, %0
%18 = select i1 %17, double %14, double 1.000000e-03
ret double %18
}