// File: /workspace/github_cpp_makefile_star2_O3/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 0x5f1fe
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), %r11
movq (%rax,%r11,8), %r14
movq 0x8(%rax,%r11,8), %r15
movb $0x1, %r10b
movb $0x1, %bl
subq %r14, %r15
je 0x5f161
sarq $0x3, %r15
movb $0x1, %bl
xorl %r12d, %r12d
movb $0x1, %bpl
movq (%r14,%r12,8), %r13
movl (%rsi,%r13,4), %r13d
cmpl $0x2, %r13d
movzbl %bpl, %ebp
cmovnel %r8d, %ebp
testl %r13d, %r13d
movzbl %bl, %ebx
cmovnel %r8d, %ebx
testb $0x1, %bpl
jne 0x5f153
testb $0x1, %bl
je 0x5f15b
incl %r12d
cmpq %r12, %r15
ja 0x5f12a
testb $0x1, %bpl
je 0x5f1a0
movq (%rcx,%r11,8), %r14
movq 0x8(%rcx,%r11,8), %r15
subq %r14, %r15
je 0x5f199
sarq $0x3, %r15
cmpq $0x1, %r15
adcq $0x0, %r15
movb $0x1, %r10b
xorl %r12d, %r12d
movq (%r14,%r12,8), %r13
cmpl $0x0, (%rsi,%r13,4)
sete %bpl
andb %bpl, %r10b
incq %r12
cmpq %r12, %r15
jne 0x5f181
testb $0x1, %bl
jne 0x5f1a8
jmp 0x5f1df
movb $0x1, %r10b
testb $0x1, %bl
je 0x5f1f4
movq (%rcx,%r11,8), %rbx
movq 0x8(%rcx,%r11,8), %r11
subq %rbx, %r11
shrq $0x3, %r11
testl %r11d, %r11d
jle 0x5f1df
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq (%rbx,%r14,8), %r15
cmpl $0x2, (%rsi,%r15,4)
sete %bpl
andb %bpl, %r10b
incq %r14
cmpq %r14, %r11
jne 0x5f1c7
testb %r10b, %r10b
je 0x5f1e8
incl (%rdi,%r9,4)
incq %r9
cmpq %rdx, %r9
jne 0x5f107
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq