// File: /workspace/github_cpp_makefile_star2_O1/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 $0x30, %rsp
movsd 0x38(%rdi), %xmm1
ucomisd 0x95905(%rip), %xmm1    # 0xcf448
jne 0x39b50
jp 0x39b50
leaq 0xd1e2a(%rip), %rax     # 0x10b978
jmp 0x39bc2
movq %rdi, %rbx
movsd 0x48(%rdi), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0x39b6d
jp 0x39b6d
leaq 0xd1df1(%rip), %rax     # 0x10b95c
jmp 0x39bc2
movq %rsi, %r14
ucomisd %xmm2, %xmm1
movsd 0x40(%rbx), %xmm2
jne 0x39b92
jp 0x39b92
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm2
jne 0x39b92
jp 0x39b92
leaq 0xd1dc8(%rip), %rax     # 0x10b958
jmp 0x39bc2
ucomisd 0x958a6(%rip), %xmm1    # 0xcf440
jne 0x39bb3
jp 0x39bb3
ucomisd 0x9589a(%rip), %xmm2    # 0xcf440
jne 0x39bb3
jp 0x39bb3
leaq 0xd1daf(%rip), %rax     # 0x10b960
jmp 0x39bc2
ucomisd %xmm2, %xmm1
jne 0x39bce
jp 0x39bce
leaq 0xd1dae(%rip), %rax     # 0x10b970
incl (%rax)
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq
incl 0xd1da8(%rip)           # 0x10b97c
movsd 0x95863(%rip), %xmm8    # 0xcf440
movapd %xmm8, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm10
mulsd %xmm2, %xmm10
movapd %xmm8, %xmm5
subsd %xmm2, %xmm5
movapd %xmm1, %xmm4
mulsd %xmm5, %xmm4
movapd %xmm0, %xmm6
mulsd %xmm4, %xmm6
movapd %xmm10, %xmm7
mulsd %xmm0, %xmm7
movapd %xmm7, %xmm9
subsd %xmm6, %xmm9
addsd %xmm6, %xmm7
movsd (%r14), %xmm6
addsd %xmm9, %xmm6
movsd %xmm6, (%r14)
movsd 0x10(%r14), %xmm6
addsd %xmm9, %xmm6
movsd %xmm6, 0x10(%r14)
movsd 0x20(%r14), %xmm6
addsd %xmm9, %xmm6
movsd %xmm6, 0x20(%r14)
movsd 0x8(%r14), %xmm6
addsd %xmm7, %xmm6
movsd %xmm6, 0x8(%r14)
movsd 0x18(%r14), %xmm6
addsd %xmm7, %xmm6
movsd %xmm6, 0x18(%r14)
movsd 0x28(%r14), %xmm6
addsd %xmm7, %xmm6
movsd %xmm6, 0x28(%r14)
ucomisd %xmm0, %xmm2
jbe 0x39c9b
movapd %xmm2, %xmm6
mulsd %xmm4, %xmm6
movapd %xmm10, %xmm11
mulsd %xmm2, %xmm11
jmp 0x39cbb
movapd %xmm3, %xmm11
mulsd %xmm0, %xmm11
movapd %xmm8, %xmm6
subsd %xmm0, %xmm6
mulsd %xmm1, %xmm6
mulsd %xmm0, %xmm6
mulsd %xmm0, %xmm11
subsd %xmm6, %xmm11
movsd 0x30(%r14), %xmm6
addsd %xmm11, %xmm6
movsd %xmm6, 0x30(%r14)
movsd 0x38(%r14), %xmm6
addsd %xmm11, %xmm6
movsd %xmm6, 0x38(%r14)
movsd 0x40(%r14), %xmm6
addsd %xmm11, %xmm6
movsd %xmm6, 0x40(%r14)
movsd 0x60(%r14), %xmm6
addsd %xmm9, %xmm6
movsd %xmm6, 0x60(%r14)
movsd 0x68(%r14), %xmm6
addsd %xmm9, %xmm6
movsd %xmm6, 0x68(%r14)
movsd 0x70(%r14), %xmm6
addsd %xmm9, %xmm6
movsd %xmm6, 0x70(%r14)
incl 0xd1c54(%rip)           # 0x10b980
ucomisd %xmm1, %xmm2
movsd %xmm9, 0x8(%rsp)
jae 0x39d4f
ucomisd %xmm0, %xmm1
jbe 0x39d65
mulsd %xmm1, %xmm4
mulsd %xmm1, %xmm10
subsd %xmm4, %xmm10
jmp 0x39d86
ucomisd %xmm0, %xmm2
jbe 0x39d91
mulsd %xmm2, %xmm4
mulsd %xmm2, %xmm10
subsd %xmm4, %xmm10
jmp 0x39db3
movapd %xmm8, %xmm10
subsd %xmm0, %xmm10
mulsd %xmm2, %xmm10
mulsd %xmm0, %xmm5
mulsd %xmm0, %xmm5
mulsd %xmm0, %xmm10
subsd %xmm5, %xmm10
xorpd 0x956d1(%rip), %xmm10   # 0xcf460
jmp 0x39db3
mulsd %xmm0, %xmm3
movapd %xmm8, %xmm2
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm3
subsd %xmm2, %xmm3
movapd %xmm3, %xmm10
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm10
movsd %xmm7, 0x18(%rsp)
jne 0x39f21
jp 0x39f21
movq 0xd1213(%rip), %r15     # 0x10afe8
leaq 0x95953(%rip), %rsi     # 0xcf72f
movl $0x5, %edx
movq %r15, %rdi
movapd %xmm10, 0x20(%rsp)
movsd %xmm11, 0x10(%rsp)
callq 0x84e0
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movq %r15, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x9591b(%rip), %rsi     # 0xcf735
movl $0x7, %edx
movq %r15, %rdi
callq 0x84e0
movq %r15, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x958f9(%rip), %rsi     # 0xcf73d
movl $0xb, %edx
movq %r15, %rdi
callq 0x84e0
movq %r15, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x958db(%rip), %rsi     # 0xcf749
movl $0xc, %edx
movq %r15, %rdi
callq 0x84e0
movq %r15, %rdi
movaps 0x20(%rsp), %xmm0
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x958bf(%rip), %rsi     # 0xcf756
movl $0x4, %edx
movq %r15, %rdi
callq 0x84e0
movsd 0x38(%rbx), %xmm0
movq %r15, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x9589b(%rip), %rsi     # 0xcf75b
movl $0x4, %edx
movq %r15, %rdi
callq 0x84e0
movsd 0x40(%rbx), %xmm0
movq %r15, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
leaq 0x95877(%rip), %rsi     # 0xcf760
movl $0x4, %edx
movq %r15, %rdi
callq 0x84e0
movsd 0x48(%rbx), %xmm0
movq %r15, %rdi
callq 0x8730
movq %rax, %rdi
callq 0x8200
movapd 0x20(%rsp), %xmm10
movsd 0x95525(%rip), %xmm8    # 0xcf440
movsd 0x18(%rsp), %xmm7
movsd 0x48(%r14), %xmm0
addsd %xmm10, %xmm0
movsd %xmm0, 0x48(%r14)
movsd 0x50(%r14), %xmm0
addsd %xmm10, %xmm0
movsd %xmm0, 0x50(%r14)
addsd 0x58(%r14), %xmm10
movsd %xmm10, 0x58(%r14)
movsd 0x48(%rbx), %xmm0
ucomisd 0x954e4(%rip), %xmm0    # 0xcf440
jne 0x39fb7
jp 0x39fb7
subsd 0x38(%rbx), %xmm8
movsd 0x78(%r14), %xmm0
addsd %xmm8, %xmm0
movsd %xmm0, 0x78(%r14)
movsd 0x80(%r14), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x80(%r14)
addsd 0x90(%r14), %xmm8
movsd %xmm8, 0x90(%r14)
addsd 0x88(%r14), %xmm1
movsd %xmm1, 0x88(%r14)
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm7
jne 0x3a04d
jp 0x3a04d
movq 0xd1016(%rip), %r14     # 0x10afe8
leaq 0x9578c(%rip), %rsi     # 0xcf765
movl $0x3, %edx
movq %r14, %rdi
callq 0x84e0
movsd 0x38(%rbx), %xmm0
movq %r14, %rdi
callq 0x8730
movq %rax, %r14
leaq 0x9576c(%rip), %rsi     # 0xcf769
movl $0x4, %edx
movq %rax, %rdi
callq 0x84e0
movsd 0x40(%rbx), %xmm0
movq %r14, %rdi
callq 0x8730
movq %rax, %r14
leaq 0x9574d(%rip), %rsi     # 0xcf76e
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
movsd 0x18(%rsp), %xmm7
ucomisd %xmm0, %xmm7
jne 0x39bc4
jp 0x39bc4
leaq 0x9570f(%rip), %rdi     # 0xcf773
leaq 0x9559d(%rip), %rsi     # 0xcf608
leaq 0x95717(%rip), %rcx     # 0xcf789
movl $0xaa, %edx
callq 0x82c0