// File: millanek[P]evo/process_vcf_fst.cpp
// Function: calculateDxy(SetCounts const&, int, int)
double calculateDxy(const SetCounts& thisVarCounts, const int n1, const int n2) {
    double Dxy;
    int sumKij = 0;
    for (std::vector<std::string>::size_type i = 0; i != n1/2; i++) {
        for (std::vector<std::string>::size_type j = 0; j != n2/2; j++) {
            if (thisVarCounts.set1individualsWithVariant[i] == 0 && thisVarCounts.set2individualsWithVariant[j] == 0) {
            } else if (thisVarCounts.set1individualsWithVariant[i] == 1 && thisVarCounts.set2individualsWithVariant[j] == 0) {
                sumKij = sumKij + 2;
            } else if (thisVarCounts.set1individualsWithVariant[i] == 0 && thisVarCounts.set2individualsWithVariant[j] == 1) {
                sumKij = sumKij + 2;
            } else if (thisVarCounts.set1individualsWithVariant[i] == 1 && thisVarCounts.set2individualsWithVariant[j] == 1) {
                sumKij = sumKij + 2;
            } else if (thisVarCounts.set1individualsWithVariant[i] == 2 && thisVarCounts.set2individualsWithVariant[j] == 1) {
                sumKij = sumKij + 2;
            } else if (thisVarCounts.set1individualsWithVariant[i] == 1 && thisVarCounts.set2individualsWithVariant[j] == 2) {
                sumKij = sumKij + 2;
            } else if (thisVarCounts.set1individualsWithVariant[i] == 2 && thisVarCounts.set2individualsWithVariant[j] == 2) {
            } else if (thisVarCounts.set1individualsWithVariant[i] == 2 && thisVarCounts.set2individualsWithVariant[j] == 0) {
                sumKij = sumKij + 4;
            } else if (thisVarCounts.set1individualsWithVariant[i] == 0 && thisVarCounts.set2individualsWithVariant[j] == 2) {
                sumKij = sumKij + 4;
            }
        }
    }
    Dxy = (double)sumKij/(n1*n2);
    return Dxy;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0xc(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0xd986c
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x10(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0xd9859
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd964a
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd964a
jmp 0xd9846
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd968a
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd968a
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd9844
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd96ca
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd96ca
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd9842
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd970a
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd970a
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd9840
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x2, (%rax)
jne 0xd974a
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd974a
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd983e
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x1, (%rax)
jne 0xd978a
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x2, (%rax)
jne 0xd978a
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd983c
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x2, (%rax)
jne 0xd97be
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x2, (%rax)
jne 0xd97be
jmp 0xd983a
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x2, (%rax)
jne 0xd97fb
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd97fb
movl -0x1c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd9838
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
movq -0x28(%rbp), %rsi
callq 0x48250
cmpl $0x0, (%rax)
jne 0xd9836
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
movq -0x30(%rbp), %rsi
callq 0x48250
cmpl $0x2, (%rax)
jne 0xd9836
movl -0x1c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd9838
jmp 0xd983a
jmp 0xd983c
jmp 0xd983e
jmp 0xd9840
jmp 0xd9842
jmp 0xd9844
jmp 0xd9846
jmp 0xd9848
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xd95ee
jmp 0xd985b
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xd95c1
cvtsi2sdl -0x1c(%rbp), %xmm0
movl -0xc(%rbp), %eax
imull -0x10(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
addq $0x40, %rsp
popq %rbp
retq