// File: /workspace/github_cpp_makefile_star2_O1/millanek[P]evo/process_vcf_stats_functions.cpp
// Function: privateVars_analysis(std::vector<int, std::allocator<int>>&, FilterResult const&, std::vector<std::vector<unsigned long, std::allocator<unsigned long>>, std::allocator<std::vector<unsigned long, std::allocator<unsigned long>>>> const&, std::vector<std::vector<unsigned long, std::allocator<unsigned long>>, std::allocator<std::vector<unsigned long, std::allocator<unsigned long>>>> const&)
void privateVars_analysis(std::vector<int>& privateVarCounts, const FilterResult& result, const std::vector<std::vector<size_t> >& populationsIndices, const std::vector<std::vector<size_t> >& populationsIndicesComplements) {
    for (int i = 0; i < (int)populationsIndices.size(); i++) {
        bool allAlts = true; bool allRefs = true;
        for (int j = 0; j < populationsIndices[i].size(); j++) {
            if (result.counts.individualsWithVariant[populationsIndices[i][j]] != 2)
                allAlts = false;
            if (result.counts.individualsWithVariant[populationsIndices[i][j]] != 0)
                allRefs = false;
            if (!allAlts && !allRefs)
                break;
        }
        if (!allAlts && !allRefs)
            break;
        
        // If all individuals in the population have the same allele (either all alt or all ref)
        // Then we look at the rest of the individuals in the dataset (complement)
        bool privateVar = true;
        if (allAlts) {
            for (int j = 0; j < populationsIndicesComplements[i].size(); j++) {
                if (result.counts.individualsWithVariant[populationsIndicesComplements[i][j]] != 0)
                    privateVar = false;
            }
            //print_vector_stream(populationsIndices[i], std::cerr);
            //print_vector_stream(result.counts.individualsWithVariant, std::cerr);
        }
        if (allRefs) {
            for (int j = 0; j < (int)populationsIndicesComplements[i].size(); j++) {
                if (result.counts.individualsWithVariant[populationsIndicesComplements[i][j]] != 2)
                privateVar = false;
            }
        }
        if (privateVar) {
            privateVarCounts[i]++;
        }
    }
}

// Assembly:
movq (%rdx), %rax
movq 0x8(%rdx), %r8
subq %rax, %r8
sarq $0x3, %r8
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %r8, %rdx
testl %edx, %edx
jle 0x5f0e8
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x78(%rsi), %rsi
movq (%rcx), %rcx
movq (%rdi), %rdi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %r8d, %r8d
xorl %r9d, %r9d
leaq (%r9,%r9,2), %r10
movq (%rax,%r10,8), %rbx
movq 0x8(%rax,%r10,8), %r14
subq %rbx, %r14
je 0x5f03b
sarq $0x3, %r14
movb $0x1, %r11b
xorl %r15d, %r15d
movb $0x1, %bpl
movq (%rbx,%r15,8), %r12
movl (%rsi,%r12,4), %r12d
cmpl $0x2, %r12d
movzbl %bpl, %ebp
cmovnel %r8d, %ebp
testl %r12d, %r12d
movzbl %r11b, %r11d
cmovnel %r8d, %r11d
testb $0x1, %bpl
jne 0x5f031
testb $0x1, %r11b
je 0x5f041
incl %r15d
cmpq %r15, %r14
ja 0x5f006
jmp 0x5f041
movb $0x1, %bpl
movb $0x1, %r11b
testb $0x1, %bpl
je 0x5f080
movq (%rcx,%r10,8), %r14
movq 0x8(%rcx,%r10,8), %r15
subq %r14, %r15
je 0x5f08a
sarq $0x3, %r15
cmpq $0x1, %r15
adcq $0x0, %r15
movb $0x1, %bl
xorl %r12d, %r12d
movq (%r14,%r12,8), %r13
cmpl $0x0, (%rsi,%r13,4)
movzbl %bl, %ebx
cmovnel %r8d, %ebx
incq %r12
cmpq %r12, %r15
jne 0x5f066
jmp 0x5f08c
movb $0x1, %bl
testb $0x1, %r11b
jne 0x5f08c
jmp 0x5f0de
movb $0x1, %bl
testb $0x1, %r11b
je 0x5f0c9
movq (%rcx,%r10,8), %r11
movq 0x8(%rcx,%r10,8), %r10
subq %r11, %r10
shrq $0x3, %r10
testl %r10d, %r10d
jle 0x5f0c9
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq (%r11,%r14,8), %r15
cmpl $0x2, (%rsi,%r15,4)
movzbl %bl, %ebx
cmovnel %r8d, %ebx
incq %r14
cmpq %r14, %r10
jne 0x5f0b1
testb $0x1, %bl
je 0x5f0d2
incl (%rdi,%r9,4)
incq %r9
cmpq %rdx, %r9
jne 0x5efe7
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq