// File: 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
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x7b270
movq -0xd8(%rbp), %rax
addq $0x68, %rax
movq %rax, -0xd0(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0xab60
movq -0xc8(%rbp), %rdx
leaq 0xc052b(%rip), %rsi     # 0x13b25a
leaq -0x40(%rbp), %rdi
callq 0x2d6c0
jmp 0x7ad3a
movq -0xd0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x83190
movq %rax, -0xe0(%rbp)
jmp 0x7ad53
movq -0xe0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xe4(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xac88
leaq -0x41(%rbp), %rdi
callq 0xa640
movl -0xe4(%rbp), %eax
cmpl $0x0, %eax
jle 0x7b16c
movq -0xd8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xf8(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0xab60
movq -0xf0(%rbp), %rdx
leaq 0xc04a7(%rip), %rsi     # 0x13b25a
leaq -0x78(%rbp), %rdi
callq 0x2d6c0
jmp 0x7adbe
movq -0xf8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x83190
movq %rax, -0x100(%rbp)
jmp 0x7add7
movq -0xd8(%rbp), %rax
movq -0x100(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, -0x114(%rbp)
addq $0x38, %rax
movq %rax, -0x110(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0xab60
movq -0x108(%rbp), %rdx
leaq 0xc0441(%rip), %rsi     # 0x13b25a
leaq -0xa0(%rbp), %rdi
callq 0x2d6c0
jmp 0x7ae27
movq -0x110(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x83190
movq %rax, -0x120(%rbp)
jmp 0x7ae43
movq -0x120(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x124(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xac88
leaq -0xa1(%rbp), %rdi
callq 0xa640
leaq -0x78(%rbp), %rdi
callq 0xac88
leaq -0x79(%rbp), %rdi
callq 0xa640
movl -0x124(%rbp), %ecx
movl -0x114(%rbp), %eax
cmpl %ecx, %eax
jle 0x7b163
movl $0x0, -0x1c(%rbp)
jmp 0x7b16a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7aebf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xac88
leaq -0x41(%rbp), %rdi
callq 0xa640
jmp 0x7af2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7af21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7af18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7af0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xac88
leaq -0xa1(%rbp), %rdi
callq 0xa640
leaq -0x78(%rbp), %rdi
callq 0xac88
leaq -0x79(%rbp), %rdi
callq 0xa640
movl -0x54(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x7b25a
movq -0x50(%rbp), %rdi
callq 0xa210
movq %rax, -0xb0(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
callq 0xaa20
movq -0xd8(%rbp), %rdi
addq $0x38, %rdi
callq 0x83230
movq %rax, -0xb8(%rbp)
movq -0xd8(%rbp), %rdi
addq $0x38, %rdi
callq 0x59dd0
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x83260
testb $0x1, %al
jne 0x7afa0
jmp 0x7b251
movq -0xd8(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x130(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0x83190
cmpl $0x0, (%rax)
jle 0x7b23e
movq -0xd8(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x158(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0x83190
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cvtsi2sdl (%rcx), %xmm0
movsd %xmm0, -0x148(%rbp)
addq $0x68, %rax
movq %rax, -0x150(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x150(%rbp), %rdi
movq %rax, %rsi
callq 0x83190
movsd -0x148(%rbp), %xmm0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cvtsi2sdl (%rcx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x138(%rbp)
addq $0xe0, %rax
movq %rax, -0x140(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x140(%rbp), %rdi
movq %rax, %rsi
callq 0x832b0
movsd -0x138(%rbp), %xmm0
movsd %xmm0, (%rax)
cmpl $0x0, -0x1c(%rbp)
jne 0x7b171
movq -0xd8(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x180(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x180(%rbp), %rdi
movq %rax, %rsi
callq 0x83190
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cvtsi2sdl (%rcx), %xmm0
movsd %xmm0, -0x170(%rbp)
addq $0x68, %rax
movq %rax, -0x178(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x178(%rbp), %rdi
movq %rax, %rsi
callq 0x83190
movsd -0x170(%rbp), %xmm0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cvtsi2sdl (%rcx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x160(%rbp)
addq $0x118, %rax            # imm = 0x118
movq %rax, -0x168(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x168(%rbp), %rdi
movq %rax, %rsi
callq 0x832b0
movsd -0x160(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x7b23c
movl $0x1, -0x1c(%rbp)
jmp 0x7b16c
jmp 0x7af56
cmpl $0x1, -0x1c(%rbp)
jne 0x7b23a
movq -0xd8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1a8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x1a8(%rbp), %rdi
movq %rax, %rsi
callq 0x83190
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cvtsi2sdl (%rcx), %xmm0
movsd %xmm0, -0x198(%rbp)
addq $0x68, %rax
movq %rax, -0x1a0(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x1a0(%rbp), %rdi
movq %rax, %rsi
callq 0x83190
movsd -0x198(%rbp), %xmm0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cvtsi2sdl (%rcx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x188(%rbp)
addq $0x118, %rax            # imm = 0x118
movq %rax, -0x190(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x83290
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x832b0
movsd -0x188(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x7b23c
jmp 0x7b23e
jmp 0x7b240
leaq -0xb8(%rbp), %rdi
callq 0x5ac30
jmp 0x7af6d
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0xab50
nopw %cs:(%rax,%rax)