// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/process_vcf_fst.cpp
// Function: calculatePiTwoSets(SetCounts const&, int, int)
std::vector<double> calculatePiTwoSets(const SetCounts& thisVarCounts, const int n1, const int n2) {
    double pi1 = 0; double pi2 = 0;
 
    for (std::vector<std::string>::size_type i = 0; i != n1 - 1; i++) {
        for (std::vector<std::string>::size_type j = i+1; j != n1; j++) {
            if (thisVarCounts.set1HaplotypeVariant[i] == 1 && thisVarCounts.set1HaplotypeVariant[j] == 0) {
                pi1++;
            } else if (thisVarCounts.set1HaplotypeVariant[i] == 0 && thisVarCounts.set1HaplotypeVariant[j] == 1) {
                pi1++;
            }
        }
    }
    for (std::vector<std::string>::size_type i = 0; i != n2 - 1; i++) {
        for (std::vector<std::string>::size_type j = i+1; j != n2; j++) {
            if (thisVarCounts.set2HaplotypeVariant[i] == 1 && thisVarCounts.set2HaplotypeVariant[j] == 0) {
                pi2++;
            } else if (thisVarCounts.set2HaplotypeVariant[i] == 0 && thisVarCounts.set2HaplotypeVariant[j] == 1) {
                pi2++;
            }
        }
    }
    pi1 = (2.0/(thisVarCounts.set1_n_withoutMissing*(thisVarCounts.set1_n_withoutMissing-1)))*pi1;
    pi2 = (2.0/(thisVarCounts.set2_n_withoutMissing*(thisVarCounts.set2_n_withoutMissing-1)))*pi2;
    
    std::vector<double> pis; pis.push_back(pi1); pis.push_back(pi2);
    return pis;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl %edx, %eax
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
decl %eax
je 0x8db04
cltq
movslq %edx, %rdx
movq 0x60(%rsi), %rdi
xorl %r9d, %r9d
movsd 0x3ec5a(%rip), %xmm2    # 0xcc710
movq %rdi, %r8
movq %rdx, %r10
movq %r9, %r11
incq %r9
cmpq %rdx, %r9
je 0x8daf8
movl (%rdi,%r11,4), %r11d
movl $0x1, %r14d
testl %r11d, %r11d
je 0x8dae5
cmpl $0x1, %r11d
jne 0x8daf0
cmpl $0x0, (%r8,%r14,4)
jne 0x8daf0
jmp 0x8daec
cmpl $0x1, (%r8,%r14,4)
jne 0x8daf0
addsd %xmm2, %xmm1
incq %r14
cmpq %r14, %r10
jne 0x8dad1
decq %r10
addq $0x4, %r8
cmpq %rax, %r9
jne 0x8dabc
movl %ecx, %eax
decl %eax
je 0x8db70
cltq
movslq %ecx, %rcx
movq 0x78(%rsi), %rdx
xorpd %xmm0, %xmm0
xorl %r8d, %r8d
movsd 0x3ebee(%rip), %xmm2    # 0xcc710
movq %rdx, %rdi
movq %rcx, %r9
movq %r8, %r10
incq %r8
cmpq %rcx, %r8
je 0x8db64
movl (%rdx,%r10,4), %r10d
movl $0x1, %r11d
testl %r10d, %r10d
je 0x8db51
cmpl $0x1, %r10d
jne 0x8db5c
cmpl $0x0, (%rdi,%r11,4)
jne 0x8db5c
jmp 0x8db58
cmpl $0x1, (%rdi,%r11,4)
jne 0x8db5c
addsd %xmm2, %xmm0
incq %r11
cmpq %r11, %r9
jne 0x8db3d
decq %r9
addq $0x4, %rdi
cmpq %rax, %r8
jne 0x8db28
movl 0xc8(%rsi), %eax
leal -0x1(%rax), %ecx
imull %eax, %ecx
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
movsd 0x47f95(%rip), %xmm4    # 0xd5b20
movapd %xmm4, %xmm3
divsd %xmm2, %xmm3
mulsd %xmm3, %xmm1
leaq 0x10(%rsp), %rdx
movsd %xmm1, (%rdx)
movl 0xcc(%rsi), %eax
leal -0x1(%rax), %ecx
imull %eax, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm4
mulsd %xmm0, %xmm4
movsd %xmm4, (%rsp)
movsd %xmm4, 0x8(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x79b8e
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x8dbfd
movsd (%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x8dc0a
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x79b8e
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r14
retq
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x8dc2c
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x8480
movq %r14, %rdi
callq 0x8840