// File: /workspace/github_cpp_makefile_star2_O3/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 0x4cf1a
movq %rbx, %r12
addq $0x68, %rbx
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x837ff(%rip), %rsi     # 0xd0496
leaq 0x83800(%rip), %rdx     # 0xd049e
leaq 0x10(%rsp), %rdi
movq %rbx, 0x40(%rsp)
callq 0x28a52
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x518f2
movl (%rax), %ebx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4ccd3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8480
testl %ebx, %ebx
jle 0x4cd76
leaq 0x10(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x837ac(%rip), %rsi     # 0xd0496
leaq 0x837ad(%rip), %rdx     # 0xd049e
callq 0x28a52
leaq 0x8(%r12), %rdi
leaq 0x10(%rsp), %rsi
callq 0x518f2
movl (%rax), %ebp
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x8377f(%rip), %rsi     # 0xd0496
leaq 0x83780(%rip), %rdx     # 0xd049e
leaq 0x48(%rsp), %rdi
callq 0x28a52
leaq 0x38(%r12), %rdi
leaq 0x48(%rsp), %rsi
callq 0x518f2
movl (%rax), %r15d
cmpl %r15d, %ebp
setg %bl
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x4cd57
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4cd6e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8480
cmpl %r15d, %ebp
setle %al
jmp 0x4cd76
movl %eax, 0x4(%rsp)
movq 0x50(%r12), %r15
leaq 0x40(%r12), %r14
cmpq %r14, %r15
je 0x4ce9a
movq %r12, %rax
addq $0x38, %r12
leaq 0xe0(%rax), %r13
leaq 0x8(%rax), %rcx
addq $0x118, %rax            # imm = 0x118
movq %rax, 0x38(%rsp)
movl 0x4(%rsp), %eax
orb %bl, %al
movl %eax, 0x4(%rsp)
testb $0x1, %bl
cmovneq %r12, %rcx
movq %rcx, 0x30(%rsp)
movq 0x40(%rsp), %rbp
leaq 0x20(%r15), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x518f2
cmpl $0x0, (%rax)
jle 0x4ce86
movq %r12, %rdi
movq %rbx, %rsi
callq 0x518f2
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x518f2
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x51946
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
testb $0x1, 0x4(%rsp)
je 0x4ce86
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x518f2
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x518f2
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x51946
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
callq 0x8310
movq %rax, %r15
cmpq %r14, %rax
jne 0x4cdc5
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %rbx
movq %rax, %r15
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x4ced4
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x4ced4
jmp 0x4cece
jmp 0x4cece
jmp 0x4ceed
movq %rdx, %rbx
movq %rax, %r15
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4cef3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x4cef3
movq %rdx, %rbx
movq %rax, %r15
movq %r15, %rdi
cmpl $0x1, %ebx
jne 0x4cf14
callq 0x81c0
callq 0x8760
xorl %ebx, %ebx
movl $0x0, 0x4(%rsp)
jmp 0x4cd7a
callq 0x8840
nop