// File: 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 %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x70(%rbp)
movq %rdi, %rax
movq %rax, -0x68(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0xd99a2
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
cmpq %rcx, %rax
je 0xd998f
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd993c
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movq -0x38(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd993c
movsd 0x58988(%rip), %xmm0    # 0x1322b8
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0xd997c
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd997a
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movq -0x38(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd997a
movsd 0x58948(%rip), %xmm0    # 0x1322b8
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0xd997c
jmp 0xd997e
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xd98eb
jmp 0xd9991
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xd98c9
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0xd9a83
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movslq -0x18(%rbp), %rcx
cmpq %rcx, %rax
je 0xd9a70
movq -0x10(%rbp), %rdi
addq $0x78, %rdi
movq -0x40(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd9a1d
movq -0x10(%rbp), %rdi
addq $0x78, %rdi
movq -0x48(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd9a1d
movsd 0x588a7(%rip), %xmm0    # 0x1322b8
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0xd9a5d
movq -0x10(%rbp), %rdi
addq $0x78, %rdi
movq -0x40(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd9a5b
movq -0x10(%rbp), %rdi
addq $0x78, %rdi
movq -0x48(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd9a5b
movsd 0x58867(%rip), %xmm0    # 0x1322b8
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0xd9a5d
jmp 0xd9a5f
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xd99cc
jmp 0xd9a72
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xd99aa
movq -0x70(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc8(%rax), %eax
movl %eax, %ecx
decl %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm2
movsd 0x59c24(%rip), %xmm0    # 0x1336c8
movaps %xmm0, %xmm1
divsd %xmm2, %xmm1
movsd -0x20(%rbp), %xmm2
mulsd %xmm2, %xmm1
movsd %xmm1, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0xcc(%rax), %eax
movl %eax, %ecx
decl %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movb $0x0, -0x49(%rbp)
callq 0x48410
movq -0x70(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0xb77b0
jmp 0xd9af8
movq -0x70(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xb77b0
jmp 0xd9b07
movb $0x1, -0x49(%rbp)
testb $0x1, -0x49(%rbp)
jne 0xd9b33
jmp 0xd9b2a
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x3ecb0
jmp 0xd9b3d
movq -0x70(%rbp), %rdi
callq 0x3ecb0
movq -0x68(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0xab50
nopw %cs:(%rax,%rax)