// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/./process_vcf_stats_utils.h
// Function: pearson_chi_sq_indep(int, int, int, int)
inline double pearson_chi_sq_indep(int a, int b, int c, int d) {
    // Expected values for a,b,c,and d: (RowTotal*ColTotal)/GridTotal
    double n = (double)a+b+c+d;
    double exp_a = (double)((a+b)*(a+c))/n;
    double exp_b = (double)((a+b)*(b+d))/n;
    double exp_c = (double)((c+d)*(a+c))/n;
    double exp_d = (double)((c+d)*(b+d))/n;
    //std::cerr << "exp_a: " << exp_a << "exp_b: " << exp_b << "exp_c: " << exp_c << "exp_d: " << exp_d << std::endl;
    double chi_sq = pow((a-exp_a),2.0)/exp_a + pow((b-exp_b),2.0)/exp_b + pow((c-exp_c),2.0)/exp_c + pow((d-exp_d),2.0)/exp_d;
    //std::cerr << "Chisq stat: " << chi_sq << std::endl;
    double df = 1.0;
    double p = (1-chisq_cdf(df, chi_sq));
    return p;
}

// Assembly:
subq $0x58, %rsp
movd %edi, %xmm0
movd %esi, %xmm3
punpckldq %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
cvtdq2pd %xmm3, %xmm1
movd %edx, %xmm0
movd %ecx, %xmm2
punpckldq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
cvtdq2pd %xmm2, %xmm0
addl %edi, %esi
paddd %xmm3, %xmm2
addl %edx, %ecx
movd %esi, %xmm3
movdqa %xmm2, %xmm4
pmuludq %xmm3, %xmm4
pshufd $0x55, %xmm2, %xmm5     # xmm5 = xmm2[1,1,1,1]
pmuludq %xmm5, %xmm3
punpckldq %xmm3, %xmm4    # xmm4 = xmm4[0],xmm3[0],xmm4[1],xmm3[1]
cvtdq2pd %xmm4, %xmm3
movapd %xmm1, %xmm4
unpckhpd %xmm1, %xmm4            # xmm4 = xmm4[1],xmm1[1]
addsd %xmm1, %xmm4
movapd %xmm0, %xmm6
unpckhpd %xmm0, %xmm6            # xmm6 = xmm6[1],xmm0[1]
addsd %xmm4, %xmm6
addsd %xmm0, %xmm6
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
divpd %xmm6, %xmm3
subpd %xmm3, %xmm1
mulpd %xmm1, %xmm1
movd %ecx, %xmm4
pmuludq %xmm4, %xmm2
pmuludq %xmm5, %xmm4
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
cvtdq2pd %xmm2, %xmm2
divpd %xmm3, %xmm1
divpd %xmm6, %xmm2
subpd %xmm2, %xmm0
mulpd %xmm0, %xmm0
divpd %xmm2, %xmm0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq %xmm1, %rax
movsd %xmm1, 0x40(%rsp)
leaq -0x1(%rax), %rcx
movabsq $0xfffffffffffff, %rdx  # imm = 0xFFFFFFFFFFFFF
cmpq %rdx, %rcx
setb %cl
movq %rax, %rdx
btrq $0x3f, %rdx
testq %rdx, %rdx
sete %sil
orb %cl, %sil
testq %rax, %rax
setns %al
movabsq $-0x10000000000000, %rcx # imm = 0xFFF0000000000000
addq %rdx, %rcx
shrq $0x35, %rcx
cmpl $0x3ff, %ecx            # imm = 0x3FF
setb %cl
andb %al, %cl
orb %sil, %cl
je 0x98983
mulsd 0x33e00(%rip), %xmm1    # 0xcc720
movsd %xmm1, 0x38(%rsp)
fldl 0x38(%rsp)
flds 0x306d4(%rip)           # 0xc9004
fstpt (%rsp)
fstpt 0x10(%rsp)
leaq 0x2f(%rsp), %rdx
movl $0x1, %edi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x52504
fld %st(0)
fabs
fldl 0x333cc(%rip)           # 0xcbd20
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x98977
leaq 0x37e26(%rip), %rdi     # 0xd0789
leaq 0x32aff(%rip), %rsi     # 0xcb469
fstpt 0x4c(%rsp)
callq 0x530c4
fldt 0x4c(%rsp)
fstpl 0x30(%rsp)
movsd 0x30(%rsp), %xmm1
jmp 0x989a3
movq 0x69b4e(%rip), %rdi     # 0x1024d8
leaq 0x37dbb(%rip), %rsi     # 0xd074c
leaq 0x40(%rsp), %rdx
callq 0x52256
movsd 0x33395(%rip), %xmm1    # 0xcbd38
movsd 0x33d65(%rip), %xmm0    # 0xcc710
subsd %xmm1, %xmm0
addq $0x58, %rsp
retq