// File: millanek[P]evo/process_vcf_utils.cpp
// Function: testMaxNumHet(FilterResult&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, int, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>&)
bool testMaxNumHet(FilterResult& result, std::vector<int>& depthsHetFailed, std::vector<int>& depthsHetPassed, std::vector<int>& numVariantsPerHetCount, int maxNumHet, std::vector<std::vector<int> >& num_indiv_het_vs_depth) {
    // filter out sites where more than MAX_NUM_HET individuals are heterozygous
    int num_hets = 0;
    for (std::vector<std::vector<int> >::size_type i = 0; i < result.counts.individualsWithVariant.size(); i++) {
        if (result.counts.individualsWithVariant[i] == 1)
            num_hets++;
    }
    numVariantsPerHetCount[num_hets]++;
    
    // Randomly sample 1% of sites for num_indiv_het vs depth scatterplot
    double rn = ((double) rand() / RAND_MAX);
    if (rn < 0.01) {
        std::vector<int> this_num_het_depth; this_num_het_depth.push_back(num_hets); this_num_het_depth.push_back(result.counts.overallDepth); 
        num_indiv_het_vs_depth.push_back(this_num_het_depth);
    }
    
    if (num_hets > maxNumHet) {
        depthsHetFailed.push_back(result.counts.overallDepth);
        return false;
    } else {
        depthsHetPassed.push_back(result.counts.overallDepth);
        return true;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
addq $0x70, %rdi
callq 0x467f0
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jae 0x802ba
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
addq $0x70, %rdi
movq -0x48(%rbp), %rsi
callq 0x4d100
cmpl $0x1, (%rax)
jne 0x802aa
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x802ac
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x80262
movq -0x28(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x4d100
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
callq 0xa180
cvtsi2sd %eax, %xmm0
movsd 0xbae49(%rip), %xmm1    # 0x13b128
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0xbae40(%rip), %xmm0    # 0x13b130
ucomisd -0x50(%rbp), %xmm0
jbe 0x8035d
leaq -0x68(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x46270
movq -0x88(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x6b600
jmp 0x80319
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
leaq -0x68(%rbp), %rdi
callq 0x6b600
jmp 0x8032c
movq -0x38(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6ccd0
jmp 0x8033b
leaq -0x68(%rbp), %rdi
callq 0x48290
jmp 0x8035d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x48290
jmp 0x803a7
movl -0x3c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0x80380
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
addq $0x8, %rsi
callq 0x6b600
movb $0x0, -0x1(%rbp)
jmp 0x80399
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
addq $0x8, %rsi
callq 0x6b600
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0xab50