// File: millanek[P]Dsuite/Dsuite_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
    try {
        if (setAlleleCounts.at("Outgroup") > 0) {
            if ((double)setAltCounts.at("Outgroup")/setAlleleCounts.at("Outgroup") < 0.5) { AAint = AncestralAlleleRef; }
            else { AAint = AncestralAlleleAlt; }
        }
    } catch (std::out_of_range& e) { AAint = AncestralAlleleMissing; }
    
    // Now fill in the allele frequencies
    double totalAAF = 0; double totalDAF = 0; int numNonZeroCounts = 0;
    for(std::map<string,int>::iterator it = setAltCounts.begin(); it != setAltCounts.end(); ++it) {
        if (setAlleleCounts.at(it->first) > 0) {
            numNonZeroCounts++;
            double thisAAF = (double)setAltCounts.at(it->first)/setAlleleCounts.at(it->first);
            setAAFs[it->first] = thisAAF; totalAAF += thisAAF;
            if (AAint == 0) { // Ancestral allele seems to be the ref, so derived is alt
                setDAFs[it->first] = thisAAF; totalDAF += thisAAF;
            } else if (AAint == 1) { // Ancestral allele seems to be alt, so derived is ref
                setDAFs[it->first] = (1 - thisAAF); totalDAF += (1 - thisAAF);
            }
        }
    }
    averageAAF = totalAAF/numNonZeroCounts; averageDAF = totalDAF/numNonZeroCounts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xa820
movq -0xf0(%rbp), %rax
addq $0xc8, %rax
movq %rax, -0xe8(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x8a60
movq -0xe0(%rbp), %rdx
leaq 0x7e7f1(%rip), %rsi     # 0x88aa2
leaq -0x38(%rbp), %rdi
callq 0x9a00
jmp 0xa2bc
movq -0xe8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x10360
movq %rax, -0xf8(%rbp)
jmp 0xa2d5
movq -0xf8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xfc(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x8c08
leaq -0x39(%rbp), %rdi
callq 0x8610
movl -0xfc(%rbp), %eax
cmpl $0x0, %eax
jle 0xa731
movq -0xf0(%rbp), %rax
addq $0x98, %rax
movq %rax, -0x110(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x8a60
movq -0x108(%rbp), %rdx
leaq 0x7e76b(%rip), %rsi     # 0x88aa2
leaq -0x70(%rbp), %rdi
callq 0x9a00
jmp 0xa342
movq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x10360
movq %rax, -0x118(%rbp)
jmp 0xa35b
movq -0xf0(%rbp), %rax
movq -0x118(%rbp), %rcx
cvtsi2sdl (%rcx), %xmm0
movsd %xmm0, -0x130(%rbp)
addq $0xc8, %rax
movq %rax, -0x128(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x8a60
movq -0x120(%rbp), %rdx
leaq 0x7e6ff(%rip), %rsi     # 0x88aa2
leaq -0x98(%rbp), %rdi
callq 0x9a00
jmp 0xa3b1
movq -0x128(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x10360
movq %rax, -0x138(%rbp)
jmp 0xa3cd
movsd -0x130(%rbp), %xmm0
movq -0x138(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x140(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8c08
leaq -0x99(%rbp), %rdi
callq 0x8610
leaq -0x70(%rbp), %rdi
callq 0x8c08
leaq -0x71(%rbp), %rdi
callq 0x8610
movsd -0x140(%rbp), %xmm1
movsd 0x7e08a(%rip), %xmm0    # 0x884b0
ucomisd %xmm1, %xmm0
jbe 0xa721
movq -0xf0(%rbp), %rax
movl $0x0, 0x4(%rax)
jmp 0xa72f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa466
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x8c08
leaq -0x39(%rbp), %rdi
callq 0x8610
jmp 0xa4d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa4c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa4bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa4b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8c08
leaq -0x99(%rbp), %rdi
callq 0x8610
leaq -0x70(%rbp), %rdi
callq 0x8c08
leaq -0x71(%rbp), %rdi
callq 0x8610
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xa815
movq -0x48(%rbp), %rdi
callq 0x8220
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movq %rcx, -0xa8(%rbp)
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
callq 0x8950
movq -0xf0(%rbp), %rdi
xorps %xmm0, %xmm0
movsd %xmm0, -0xb0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
addq $0x98, %rdi
callq 0x10400
movq %rax, -0xc8(%rbp)
movq -0xf0(%rbp), %rdi
addq $0x98, %rdi
callq 0x10460
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x10430
testb $0x1, %al
jne 0xa577
jmp 0xa7cd
movq -0xf0(%rbp), %rax
addq $0xc8, %rax
movq %rax, -0x148(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x10490
movq -0x148(%rbp), %rdi
movq %rax, %rsi
callq 0x10360
cmpl $0x0, (%rax)
jle 0xa7ba
movq -0xf0(%rbp), %rax
movl -0xbc(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0xbc(%rbp)
addq $0x98, %rax
movq %rax, -0x170(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x10490
movq -0x170(%rbp), %rdi
movq %rax, %rsi
callq 0x10360
movq %rax, %rcx
movq -0xf0(%rbp), %rax
cvtsi2sdl (%rcx), %xmm0
movsd %xmm0, -0x160(%rbp)
addq $0xc8, %rax
movq %rax, -0x168(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x10490
movq -0x168(%rbp), %rdi
movq %rax, %rsi
callq 0x10360
movsd -0x160(%rbp), %xmm0
movq %rax, %rcx
movq -0xf0(%rbp), %rax
cvtsi2sdl (%rcx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x150(%rbp)
addq $0x1e8, %rax            # imm = 0x1E8
movq %rax, -0x158(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x10490
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0x104b0
movsd -0x150(%rbp), %xmm0
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movsd %xmm0, (%rcx)
movsd -0xd8(%rbp), %xmm0
addsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
cmpl $0x0, 0x4(%rax)
jne 0xa736
movq -0xf0(%rbp), %rax
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x178(%rbp)
addq $0x220, %rax            # imm = 0x220
movq %rax, -0x180(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x10490
movq -0x180(%rbp), %rdi
movq %rax, %rsi
callq 0x104b0
movsd -0x178(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0xd8(%rbp), %xmm0
addsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
jmp 0xa7b8
movq -0xf0(%rbp), %rax
movl $0x1, 0x4(%rax)
jmp 0xa731
jmp 0xa507
movq -0xf0(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0xa7b6
movq -0xf0(%rbp), %rax
movsd 0x7dd56(%rip), %xmm0    # 0x884a8
subsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x188(%rbp)
addq $0x220, %rax            # imm = 0x220
movq %rax, -0x190(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x10490
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x104b0
movsd -0x188(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd 0x7dd0a(%rip), %xmm0    # 0x884a8
subsd -0xd8(%rbp), %xmm0
addsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
jmp 0xa7b8
jmp 0xa7ba
jmp 0xa7bc
leaq -0xc8(%rbp), %rdi
callq 0x10590
jmp 0xa541
movq -0xf0(%rbp), %rax
movsd -0xb0(%rbp), %xmm0
cvtsi2sdl -0xbc(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x218(%rax)
movsd -0xb8(%rbp), %xmm0
cvtsi2sdl -0xbc(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x250(%rax)
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x8a50
nop