// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdx), %r8
movq 0x8(%rdx), %rax
subq %r8, %rax
movabsq $0x18, %r9
cqto
idivq %r9
movq (%rcx), %rcx
movq (%rdi), %rdx
xorl %edi, %edi
testl %eax, %eax
cmovlel %edi, %eax
xorl %r9d, %r9d
cmpq %rax, %r9
je 0x4bd5d
imulq $0x18, %r9, %r11
movq (%r8,%r11), %r14
movq 0x8(%r8,%r11), %r15
subq %r14, %r15
sarq $0x3, %r15
movq 0x78(%rsi), %r10
movb $0x1, %bpl
xorl %r12d, %r12d
movb $0x1, %bl
cmpq %r12, %r15
je 0x4bcd2
movq (%r14,%r12,8), %r13
movl (%r10,%r13,4), %r13d
cmpl $0x2, %r13d
movzbl %bpl, %ebp
cmovnel %edi, %ebp
testl %r13d, %r13d
movzbl %bl, %ebx
cmovnel %edi, %ebx
testb $0x1, %bpl
jne 0x4bccd
testb $0x1, %bl
je 0x4bcd2
incq %r12
jmp 0x4bca1
testb $0x1, %bpl
je 0x4bd08
movq (%rcx,%r11), %r14
movq 0x8(%rcx,%r11), %r15
subq %r14, %r15
sarq $0x3, %r15
movb $0x1, %bpl
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x4bd12
movq (%r14,%r12,8), %r13
cmpl $0x0, (%r10,%r13,4)
sete %r13b
andb %r13b, %bpl
incq %r12
jmp 0x4bcee
movb $0x1, %bpl
testb $0x1, %bl
jne 0x4bd17
jmp 0x4bd5d
testb $0x1, %bl
je 0x4bd4b
movq (%rcx,%r11), %rbx
movq 0x8(%rcx,%r11), %r11
subq %rbx, %r11
shrq $0x3, %r11
testl %r11d, %r11d
cmovlel %edi, %r11d
xorl %r14d, %r14d
cmpq %r14, %r11
je 0x4bd4b
movq (%rbx,%r14,8), %r15
cmpl $0x2, (%r10,%r15,4)
sete %r15b
andb %r15b, %bpl
incq %r14
jmp 0x4bd31
testb $0x1, %bpl
je 0x4bd55
incl (%rdx,%r9,4)
incq %r9
jmp 0x4bc78
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq