// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/evo_abba_baba.cpp
// Function: incrementDnumDdenomFrequency(ThreeSetCounts const&, ABBA_BABA_Freq_allResults&)
inline void incrementDnumDdenomFrequency(const ThreeSetCounts& c, ABBA_BABA_Freq_allResults& res) {
    if (c.set1daAF == -1) {
        ABBABABAcounts::noDafInfo++;
    } else if (c.set3daAF == 0) {
        ABBABABAcounts::XXAA++;
    } else if (c.set1daAF == 0 && c.set2daAF == 0) {
        ABBABABAcounts::AABA++;
    } else if (c.set1daAF == 1 && c.set2daAF == 1) {
        ABBABABAcounts::BBBA++;
    } else if (c.set1daAF == c.set2daAF) {
        ABBABABAcounts::p1p2++;
    } else {
        ABBABABAcounts::usedVariantsCounter++;
        // Green et al. (2010) eq. S15.2
        
        double thisDnumerator = ((1-c.set1daAF)*c.set2daAF*c.set3daAF) - (c.set1daAF*(1-c.set2daAF)*c.set3daAF);
        double thisDdenominator = ((1-c.set1daAF)*c.set2daAF*c.set3daAF) + (c.set1daAF*(1-c.set2daAF)*c.set3daAF);
        res.Dnumerator += thisDnumerator; res.lastVarsDnum += thisDnumerator; res.windowDnum += thisDnumerator;
        res.Ddenominator += thisDdenominator; res.lastVarsDdenom += thisDdenominator; res.windowDdenom += thisDdenominator;
        
        double thisF_d_denom;
        if (c.set2daAF > c.set3daAF) {
            thisF_d_denom = ((1-c.set1daAF)*c.set2daAF*c.set2daAF) - (c.set1daAF*(1-c.set2daAF)*c.set2daAF);
        } else {
            thisF_d_denom = ((1-c.set1daAF)*c.set3daAF*c.set3daAF) - (c.set1daAF*(1-c.set3daAF)*c.set3daAF);
        }
        //if (thisF_d_denom != 0) {
        /* if (thisDnumerator/thisF_d_denom > 1) {
         std::cerr << "f_d:\t" << thisDnumerator/thisF_d_denom << std::endl;
         std::cerr << "D num:\t" << thisDnumerator << std::endl;
         std::cerr << "f_d denom:\t" << thisF_d_denom << std::endl;
         std::cerr << "p1:\t" << c.set1daAF << std::endl;
         std::cerr << "p2:\t" << c.set2daAF << std::endl;
         std::cerr << "p3:\t" << c.set3daAF << std::endl;
         } */
        res.f_d_denominator += thisF_d_denom; res.window_f_d_denominator += thisF_d_denom; res.lastVarsF_d_denom += thisF_d_denom;
        res.f_d_num += thisDnumerator; res.window_f_d_num += thisDnumerator; res.lastVarsF_d_num += thisDnumerator;
        ABBABABAcounts::used_f_d_Counter++;
        //}
        
        double thisF_dM_denom;
        if (c.set1daAF <= c.set2daAF) {
            if (c.set2daAF > c.set3daAF) {
                thisF_dM_denom = ((1-c.set1daAF)*c.set2daAF*c.set2daAF) - (c.set1daAF*(1-c.set2daAF)*c.set2daAF);
            } else {
                thisF_dM_denom = ((1-c.set1daAF)*c.set3daAF*c.set3daAF) - (c.set1daAF*(1-c.set3daAF)*c.set3daAF);
            }
        } else {
            if (c.set1daAF > c.set3daAF) {
                thisF_dM_denom = -(((1-c.set1daAF)*c.set2daAF*c.set1daAF) - (c.set1daAF*(1-c.set2daAF)*c.set1daAF));
            } else {
                thisF_dM_denom = -(((1-c.set3daAF)*c.set2daAF*c.set3daAF) - (c.set3daAF*(1-c.set2daAF)*c.set3daAF));
            }
        }
        if (thisF_dM_denom == 0) {
            std::cerr << "f_d:\t" << thisDnumerator/thisF_d_denom << std::endl;
            std::cerr << "D num:\t" << thisDnumerator << std::endl;
            std::cerr << "f_d denom:\t" << thisF_d_denom << std::endl;
            std::cerr << "f_dM denom:\t" << thisF_dM_denom << std::endl;
            std::cerr << "p1:\t" << c.set1daAF << std::endl;
            std::cerr << "p2:\t" << c.set2daAF << std::endl;
            std::cerr << "p3:\t" << c.set3daAF << std::endl;
        }
        res.f_dM_denominator += thisF_dM_denom; res.window_f_dM_denominator += thisF_dM_denom; res.lastVarsF_dM_denom += thisF_dM_denom;
        
        if (c.set3daAF == 1) {
            res.f_G_denom += 1-c.set1daAF; res.f_G_num += thisDnumerator;
            res.lastVarsF_G_denom += 1-c.set1daAF; res.lastVarsF_G_num += thisDnumerator;
        }
        
        if (thisDdenominator == 0) {
            std::cerr << "P1:" << c.set1daAF << " P2:" << c.set2daAF << " P3:" << c.set3daAF << std::endl;
        }
        assert(thisDdenominator != 0);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x40, %rsp
movsd 0x38(%rdi), %xmm1
ucomisd 0x959af(%rip), %xmm1    # 0xcc718
jne 0x36d76
jp 0x36d76
leaq 0xcbc0c(%rip), %rax     # 0x102980
jmp 0x36de8
movq %rdi, %rbx
movsd 0x48(%rdi), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0x36d93
jp 0x36d93
leaq 0xcbbd3(%rip), %rax     # 0x102964
jmp 0x36de8
movq %rsi, %r14
ucomisd %xmm2, %xmm1
movsd 0x40(%rbx), %xmm2
jne 0x36db8
jp 0x36db8
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm2
jne 0x36db8
jp 0x36db8
leaq 0xcbbaa(%rip), %rax     # 0x102960
jmp 0x36de8
ucomisd 0x95950(%rip), %xmm1    # 0xcc710
jne 0x36dd9
jp 0x36dd9
ucomisd 0x95944(%rip), %xmm2    # 0xcc710
jne 0x36dd9
jp 0x36dd9
leaq 0xcbb91(%rip), %rax     # 0x102968
jmp 0x36de8
ucomisd %xmm2, %xmm1
jne 0x36df4
jp 0x36df4
leaq 0xcbb90(%rip), %rax     # 0x102978
incl (%rax)
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
incl 0xcbb8a(%rip)           # 0x102984
movsd 0x9590d(%rip), %xmm10   # 0xcc710
movapd %xmm10, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm11
mulsd %xmm2, %xmm11
movapd %xmm10, %xmm5
subsd %xmm2, %xmm5
movapd %xmm1, %xmm4
mulsd %xmm5, %xmm4
movapd %xmm0, %xmm6
mulsd %xmm4, %xmm6
movapd 0x958a9(%rip), %xmm7    # 0xcc6e0
xorpd %xmm6, %xmm7
unpcklpd %xmm6, %xmm7            # xmm7 = xmm7[0],xmm6[0]
movapd %xmm11, %xmm9
mulsd %xmm0, %xmm9
unpcklpd %xmm9, %xmm9            # xmm9 = xmm9[0,0]
addpd %xmm7, %xmm9
movupd (%r14), %xmm6
movupd 0x10(%r14), %xmm7
movupd 0x20(%r14), %xmm8
addpd %xmm9, %xmm6
movupd %xmm6, (%r14)
addpd %xmm9, %xmm7
movupd %xmm7, 0x10(%r14)
addpd %xmm9, %xmm8
movupd %xmm8, 0x20(%r14)
ucomisd %xmm0, %xmm2
jbe 0x36e9e
movapd %xmm2, %xmm6
mulsd %xmm4, %xmm6
movapd %xmm11, %xmm8
mulsd %xmm2, %xmm8
jmp 0x36ebe
movapd %xmm3, %xmm8
mulsd %xmm0, %xmm8
movapd %xmm10, %xmm6
subsd %xmm0, %xmm6
mulsd %xmm1, %xmm6
mulsd %xmm0, %xmm6
mulsd %xmm0, %xmm8
subsd %xmm6, %xmm8
movapd %xmm8, %xmm6
unpcklpd %xmm8, %xmm6            # xmm6 = xmm6[0],xmm8[0]
movupd 0x30(%r14), %xmm7
addpd %xmm6, %xmm7
movupd 0x60(%r14), %xmm6
movupd %xmm7, 0x30(%r14)
movsd 0x40(%r14), %xmm7
addsd %xmm8, %xmm7
movsd %xmm7, 0x40(%r14)
movapd %xmm9, %xmm7
unpcklpd %xmm9, %xmm7            # xmm7 = xmm7[0],xmm9[0]
addpd %xmm7, %xmm6
movupd %xmm6, 0x60(%r14)
movsd 0x70(%r14), %xmm6
addsd %xmm9, %xmm6
movsd %xmm6, 0x70(%r14)
incl 0xcba69(%rip)           # 0x102988
ucomisd %xmm1, %xmm2
jae 0x36f3b
ucomisd %xmm0, %xmm1
jbe 0x36f51
mulsd %xmm1, %xmm4
mulsd %xmm1, %xmm11
subsd %xmm4, %xmm11
jmp 0x36f72
ucomisd %xmm0, %xmm2
jbe 0x36f7d
mulsd %xmm2, %xmm4
mulsd %xmm2, %xmm11
subsd %xmm4, %xmm11
jmp 0x36f9f
movapd %xmm10, %xmm11
subsd %xmm0, %xmm11
mulsd %xmm2, %xmm11
mulsd %xmm0, %xmm5
mulsd %xmm0, %xmm5
mulsd %xmm0, %xmm11
subsd %xmm5, %xmm11
xorpd 0x95765(%rip), %xmm11   # 0xcc6e0
jmp 0x36f9f
mulsd %xmm0, %xmm3
movapd %xmm10, %xmm2
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm3
subsd %xmm2, %xmm3
movapd %xmm3, %xmm11
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm11
jne 0x3711a
jp 0x3711a
movq 0xcb02d(%rip), %r15     # 0x101fe8
leaq 0x95a25(%rip), %rsi     # 0xcc9e7
movl $0x5, %edx
movq %r15, %rdi
movapd %xmm9, (%rsp)
movapd %xmm11, 0x20(%rsp)
movapd %xmm7, 0x30(%rsp)
movapd %xmm8, 0x10(%rsp)
callq 0x84e0
movapd (%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movq %r15, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x959e2(%rip), %rsi     # 0xcc9ed
movl $0x7, %edx
movq %r15, %rdi
callq 0x84e0
movq %r15, %rdi
movaps (%rsp), %xmm0
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x959c2(%rip), %rsi     # 0xcc9f5
movl $0xb, %edx
movq %r15, %rdi
callq 0x84e0
movq %r15, %rdi
movaps 0x10(%rsp), %xmm0
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x959a5(%rip), %rsi     # 0xcca01
movl $0xc, %edx
movq %r15, %rdi
callq 0x84e0
movq %r15, %rdi
movaps 0x20(%rsp), %xmm0
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x95989(%rip), %rsi     # 0xcca0e
movl $0x4, %edx
movq %r15, %rdi
callq 0x84e0
movsd 0x38(%rbx), %xmm0
movq %r15, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x95965(%rip), %rsi     # 0xcca13
movl $0x4, %edx
movq %r15, %rdi
callq 0x84e0
movsd 0x40(%rbx), %xmm0
movq %r15, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x95941(%rip), %rsi     # 0xcca18
movl $0x4, %edx
movq %r15, %rdi
callq 0x84e0
movsd 0x48(%rbx), %xmm0
movq %r15, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
movapd 0x30(%rsp), %xmm7
movapd 0x20(%rsp), %xmm11
movsd 0x95601(%rip), %xmm10   # 0xcc710
movapd (%rsp), %xmm9
movsd 0x48(%rbx), %xmm0
movupd 0x48(%r14), %xmm1
movapd %xmm11, %xmm2
unpcklpd %xmm11, %xmm2           # xmm2 = xmm2[0],xmm11[0]
addpd %xmm1, %xmm2
movupd %xmm2, 0x48(%r14)
addsd 0x58(%r14), %xmm11
movsd %xmm11, 0x58(%r14)
ucomisd 0x955c8(%rip), %xmm0    # 0xcc710
jne 0x37187
jp 0x37187
subsd 0x38(%rbx), %xmm10
movsd %xmm10, %xmm7           # xmm7 = xmm10[0],xmm7[1]
movupd 0x78(%r14), %xmm0
addpd %xmm7, %xmm0
movupd 0x88(%r14), %xmm1
movupd %xmm0, 0x78(%r14)
movapd %xmm9, %xmm0
unpcklpd %xmm10, %xmm0           # xmm0 = xmm0[0],xmm10[0]
addpd %xmm1, %xmm0
movupd %xmm0, 0x88(%r14)
unpckhpd %xmm9, %xmm9            # xmm9 = xmm9[1,1]
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm9
jne 0x37229
jp 0x37229
movq 0xcae40(%rip), %r14     # 0x101fe8
leaq 0x9586e(%rip), %rsi     # 0xcca1d
movl $0x3, %edx
movq %r14, %rdi
movapd %xmm9, (%rsp)
callq 0x84e0
movsd 0x38(%rbx), %xmm0
movq %r14, %rdi
callq 0x8730
movq %rax, %r14
leaq 0x95848(%rip), %rsi     # 0xcca21
movl $0x4, %edx
movq %rax, %rdi
callq 0x84e0
movsd 0x40(%rbx), %xmm0
movq %r14, %rdi
callq 0x8730
movq %rax, %r14
leaq 0x95829(%rip), %rsi     # 0xcca26
movl $0x4, %edx
movq %rax, %rdi
callq 0x84e0
movsd 0x48(%rbx), %xmm0
movq %r14, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
xorpd %xmm0, %xmm0
movapd (%rsp), %xmm9
ucomisd %xmm0, %xmm9
jne 0x36dea
jp 0x36dea
leaq 0x957ea(%rip), %rdi     # 0xcca2b
leaq 0x95678(%rip), %rsi     # 0xcc8c0
leaq 0x957f2(%rip), %rcx     # 0xcca41
movl $0xaa, %edx
callq 0x82c0