// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %r13
callq 0x8e06
leaq 0xc8(%r13), %r14
leaq 0x28(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x37f8d(%rip), %rsi     # 0x40a9a
leaq 0x37f8e(%rip), %rdx     # 0x40aa2
leaq 0x18(%rsp), %rdi
movq %r14, 0x38(%rsp)
callq 0x88ba
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0xd180
movl (%rax), %ebp
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8b49
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x7420
testl %ebp, %ebp
jle 0x8c26
leaq 0x18(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x37f3a(%rip), %rsi     # 0x40a9a
leaq 0x37f3b(%rip), %rdx     # 0x40aa2
callq 0x88ba
leaq 0x98(%r13), %rdi
leaq 0x18(%rsp), %rsi
movq 0x38(%rsp), %r15
callq 0xd180
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x37eff(%rip), %rsi     # 0x40a9a
leaq 0x37f00(%rip), %rdx     # 0x40aa2
leaq 0x58(%rsp), %rdi
callq 0x88ba
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0xd180
cvtsi2sdl (%rax), %xmm1
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x8be0
movq 0x68(%rsp), %rsi
incq %rsi
movsd %xmm1, 0x8(%rsp)
callq 0x7420
movsd 0x8(%rsp), %xmm1
movsd (%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8c05
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x7420
movsd 0x3786b(%rip), %xmm0    # 0x40478
ucomisd (%rsp), %xmm0
jbe 0x8c1e
movl $0x0, 0x4(%r13)
jmp 0x8c26
movl $0x1, 0x4(%r13)
movq 0xb0(%r13), %r15
leaq 0xa0(%r13), %rbp
cmpq %rbp, %r15
je 0x8d61
leaq 0x98(%r13), %rax
movq %rax, 0x50(%rsp)
leaq 0x1e8(%r13), %rcx
movq %rcx, 0x48(%rsp)
leaq 0x220(%r13), %rax
movq %rax, 0x40(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %r14d, %r14d
movsd %xmm0, 0x8(%rsp)
movq 0x38(%rsp), %r12
leaq 0x20(%r15), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xd180
cmpl $0x0, (%rax)
jle 0x8d37
incl %r14d
movq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0xd180
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0xd180
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0xd1d4
movsd (%rsp), %xmm1
movsd %xmm1, (%rax)
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movl 0x4(%r13), %eax
testl %eax, %eax
movsd %xmm0, 0x8(%rsp)
je 0x8d11
cmpl $0x1, %eax
jne 0x8d37
movsd 0x37768(%rip), %xmm0    # 0x40470
subsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0xd1d4
movsd (%rsp), %xmm1
movsd %xmm1, (%rax)
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x72f0
movq %rax, %r15
cmpq %rbp, %rax
jne 0x8c79
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
jmp 0x8d6d
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x218(%r13)
divsd %xmm0, %xmm1
movsd %xmm1, 0x250(%r13)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r12
movq %rax, %r15
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x8dc1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x7420
jmp 0x8dc1
jmp 0x8dbb
jmp 0x8dbb
jmp 0x8dda
movq %rdx, %r12
movq %rax, %r15
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8de0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x7420
jmp 0x8de0
movq %rdx, %r12
movq %rax, %r15
movq %r15, %rdi
cmpl $0x1, %r12d
jne 0x8e00
callq 0x7170
movl $0xffffffff, 0x4(%r13)  # imm = 0xFFFFFFFF
callq 0x76a0
jmp 0x8c26
callq 0x7740
nop