// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/process_vcf_utils.cpp
// Function: GeneralSetCounts::getSetVariantCounts(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::map<unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>> const&)
void GeneralSetCounts::getSetVariantCounts(const std::vector<std::string>& genotypes, const std::map<size_t, string>& posToSpeciesMap) {
    
    getBasicCounts(genotypes, posToSpeciesMap);
    
    // If at least one of the outgroup individuals has non-missing data
    // Find out what is the "ancestral allele" - i.e. the one more common in the outgroup
    int AAint;
    try {
        if (setAlleleCounts.at("Outgroup") > 0) {
            if (setRefCounts.at("Outgroup") > setAltCounts.at("Outgroup")) { AAint = 0; }
            else { AAint = 1; }
        }
    } catch (std::out_of_range& e) { AAint = -1; }
    
    // Now fill in the allele frequencies
    for(std::map<string,int>::iterator it = setAltCounts.begin(); it != setAltCounts.end(); ++it) {
        if (setAlleleCounts.at(it->first) > 0) {
            setAAFs[it->first] = (double)setAltCounts.at(it->first)/setAlleleCounts.at(it->first);
            if (AAint == 0) { // Ancestral allele seems to be the ref, so derived is alt
                setDAFs[it->first] = (double)setAltCounts.at(it->first)/setAlleleCounts.at(it->first);
            } else if (AAint == 1) { // Ancestral allele seems to be alt, so derived is ref
                setDAFs[it->first] = (double)setRefCounts.at(it->first)/setAlleleCounts.at(it->first);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
callq 0x3fde8
movq %rbx, %r13
leaq 0x68(%rbx), %r14
leaq 0x5f588(%rip), %rsi     # 0x9f17a
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x21904
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x43738
movl (%rax), %ebx
leaq 0x28(%rsp), %rdi
callq 0x8978
testl %ebx, %ebx
jle 0x3fc87
leaq 0x5f555(%rip), %rsi     # 0x9f17a
leaq 0x28(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x21904
leaq 0x8(%r13), %rdi
leaq 0x28(%rsp), %rsi
callq 0x43738
movl (%rax), %ebx
leaq 0x5f52f(%rip), %rsi     # 0x9f17a
leaq 0x48(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x21904
leaq 0x38(%r13), %rdi
leaq 0x48(%rsp), %rsi
callq 0x43738
cmpl (%rax), %ebx
setg %bl
setle %r12b
leaq 0x48(%rsp), %rdi
callq 0x8978
leaq 0x28(%rsp), %rdi
callq 0x8978
jmp 0x3fc87
movq %r13, %rax
leaq 0x38(%r13), %r15
movq 0x50(%r13), %rbp
addq $0x40, %r13
leaq 0xe0(%rax), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x8(%rax), %rcx
addq $0x118, %rax            # imm = 0x118
movq %rax, 0x18(%rsp)
orb %bl, %r12b
testb $0x1, %bl
cmovneq %r15, %rcx
movq %rcx, 0x10(%rsp)
cmpq %r13, %rbp
je 0x3fd87
leaq 0x20(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x43738
cmpl $0x0, (%rax)
jle 0x3fd77
movq %r15, %rdi
movq %rbx, %rsi
callq 0x43738
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x43738
cvtsi2sdl (%rax), %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x4377e
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
testb $0x1, %r12b
je 0x3fd77
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x43738
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x43738
cvtsi2sdl (%rax), %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x4377e
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbp, %rdi
callq 0x8340
movq %rax, %rbp
jmp 0x3fcc0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r12
movq %rax, %r15
leaq 0x48(%rsp), %rdi
callq 0x8978
jmp 0x3fdb4
jmp 0x3fdae
jmp 0x3fdae
jmp 0x3fdc0
movq %rdx, %r12
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x8978
jmp 0x3fdc6
movq %rdx, %r12
movq %rax, %r15
movq %r15, %rdi
cmpl $0x1, %r12d
jne 0x3fde3
callq 0x81d0
callq 0x8780
xorl %ebx, %ebx
xorl %r12d, %r12d
jmp 0x3fc87
callq 0x8870