// File: millanek[P]evo/process_vcf_utils.cpp
// Function: MultiallelicCounts::getPiThisVariant()
double MultiallelicCounts::getPiThisVariant() {
    
    std::vector<int> nonMissingHaplotypeVars = haplotypeVariants;
    nonMissingHaplotypeVars.erase(std::remove(nonMissingHaplotypeVars.begin(), nonMissingHaplotypeVars.end(), -1), nonMissingHaplotypeVars.end());
    
    int countedNumComparisons = 0;  // TEST
    int numDiffs = 0; int numHaplotypes = (int) nonMissingHaplotypeVars.size();
    for (std::vector<std::string>::size_type i = 0; i !=  numHaplotypes - 1; i++) {
        for (std::vector<std::string>::size_type j = i+1; j != numHaplotypes; j++) {
            if (nonMissingHaplotypeVars[i] != nonMissingHaplotypeVars[j]) {
                numDiffs++;
            }
            countedNumComparisons++;
        }
    }
    int numComparisons = (numHaplotypes * (numHaplotypes -1)) / 2;
    assert(numComparisons == countedNumComparisons);
    
    double piThisVar = (double)numDiffs/(double)numComparisons;
    
    return piThisVar;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
addq $0x38, %rsi
leaq -0x20(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x4cf20
movq -0xb0(%rbp), %rdi
callq 0x46a90
movq -0xb0(%rbp), %rdi
movq %rax, -0x38(%rbp)
callq 0x46ac0
movq %rax, -0x40(%rbp)
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x44(%rbp), %rdx
callq 0x83840
movq %rax, -0xa8(%rbp)
jmp 0x7ccd8
movq -0xa8(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x83890
leaq -0x20(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x46ac0
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x83890
movq -0xc0(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x837b0
movq %rax, -0xb8(%rbp)
jmp 0x7cd2e
movq -0xb8(%rbp), %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x467f0
movl %eax, -0x7c(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl -0x7c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x7ce2c
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movslq -0x7c(%rbp), %rcx
cmpq %rcx, %rax
je 0x7ce13
movq -0x88(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x4d100
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0x90(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x4d100
movq %rax, %rcx
movl -0xc4(%rbp), %eax
cmpl (%rcx), %eax
je 0x7cdf3
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x7cdf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x48290
jmp 0x7ceb5
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x7cd89
jmp 0x7ce15
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x7cd5e
movl -0x7c(%rbp), %eax
movl -0x7c(%rbp), %ecx
subl $0x1, %ecx
imull %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x74(%rbp), %eax
jne 0x7ce53
jmp 0x7ce72
leaq 0xbe41c(%rip), %rdi     # 0x13b276
leaq 0xbe43d(%rip), %rsi     # 0x13b29e
movl $0x15e, %edx            # imm = 0x15E
leaq 0xbe447(%rip), %rcx     # 0x13b2b4
callq 0xa390
cvtsi2sdl -0x78(%rbp), %xmm0
cvtsi2sdl -0x94(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x48290
movsd -0xd0(%rbp), %xmm0
addq $0xd0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0xab50
nop