// File: /workspace/github_cpp_makefile_star2_O1/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 0x4ff16
movq %rbx, %r12
addq $0x68, %rbx
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x872d7(%rip), %rsi     # 0xd6f6a
leaq 0x872d8(%rip), %rdx     # 0xd6f72
leaq 0x10(%rsp), %rdi
movq %rbx, 0x40(%rsp)
callq 0x28952
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x54a86
movl (%rax), %ebx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4fccf
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8480
testl %ebx, %ebx
jle 0x4fd72
leaq 0x10(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x87284(%rip), %rsi     # 0xd6f6a
leaq 0x87285(%rip), %rdx     # 0xd6f72
callq 0x28952
leaq 0x8(%r12), %rdi
leaq 0x10(%rsp), %rsi
callq 0x54a86
movl (%rax), %ebp
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x87257(%rip), %rsi     # 0xd6f6a
leaq 0x87258(%rip), %rdx     # 0xd6f72
leaq 0x48(%rsp), %rdi
callq 0x28952
leaq 0x38(%r12), %rdi
leaq 0x48(%rsp), %rsi
callq 0x54a86
movl (%rax), %r15d
cmpl %r15d, %ebp
setg %bl
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x4fd53
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4fd6a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8480
cmpl %r15d, %ebp
setle %al
jmp 0x4fd72
movl %eax, 0x4(%rsp)
movq 0x50(%r12), %r15
leaq 0x40(%r12), %r14
cmpq %r14, %r15
je 0x4fe96
movq %r12, %rax
addq $0x38, %r12
leaq 0xe0(%rax), %r13
leaq 0x8(%rax), %rdx
movl 0x4(%rsp), %ecx
orb %bl, %cl
movl %ecx, 0x4(%rsp)
addq $0x118, %rax            # imm = 0x118
movq %rax, 0x38(%rsp)
testb $0x1, %bl
cmovneq %r12, %rdx
movq %rdx, 0x30(%rsp)
movq 0x40(%rsp), %rbp
leaq 0x20(%r15), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x54a86
cmpl $0x0, (%rax)
jle 0x4fe82
movq %r12, %rdi
movq %rbx, %rsi
callq 0x54a86
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x54a86
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x54ada
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
testb $0x1, 0x4(%rsp)
je 0x4fe82
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x54a86
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x54a86
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 0x54ada
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
callq 0x8310
movq %rax, %r15
cmpq %r14, %rax
jne 0x4fdc1
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 0x4fed0
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x4fed0
jmp 0x4feca
jmp 0x4feca
jmp 0x4fee9
movq %rdx, %rbx
movq %rax, %r15
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4feef
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x4feef
movq %rdx, %rbx
movq %rax, %r15
movq %r15, %rdi
cmpl $0x1, %ebx
jne 0x4ff10
callq 0x81c0
callq 0x8760
xorl %ebx, %ebx
movl $0x0, 0x4(%rsp)
jmp 0x4fd76
callq 0x8840
nop