// File: /workspace/github_cpp_makefile_star2_O3/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 0x8e0a
leaq 0xc8(%r13), %r14
leaq 0x28(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x38ff1(%rip), %rsi     # 0x41b02
leaq 0x38ff2(%rip), %rdx     # 0x41b0a
leaq 0x18(%rsp), %rdi
movq %r14, 0x38(%rsp)
callq 0x88ba
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0xd0dc
movl (%rax), %ebp
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8b4d
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x7420
testl %ebp, %ebp
jle 0x8c2a
leaq 0x18(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x38f9e(%rip), %rsi     # 0x41b02
leaq 0x38f9f(%rip), %rdx     # 0x41b0a
callq 0x88ba
leaq 0x98(%r13), %rdi
leaq 0x18(%rsp), %rsi
movq 0x38(%rsp), %r15
callq 0xd0dc
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x38f63(%rip), %rsi     # 0x41b02
leaq 0x38f64(%rip), %rdx     # 0x41b0a
leaq 0x58(%rsp), %rdi
callq 0x88ba
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0xd0dc
cvtsi2sdl (%rax), %xmm1
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x8be4
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 0x8c09
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x7420
movsd 0x38867(%rip), %xmm0    # 0x41478
ucomisd (%rsp), %xmm0
jbe 0x8c22
movl $0x0, 0x4(%r13)
jmp 0x8c2a
movl $0x1, 0x4(%r13)
movq 0xb0(%r13), %r15
leaq 0xa0(%r13), %rbp
cmpq %rbp, %r15
je 0x8d65
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 0xd0dc
cmpl $0x0, (%rax)
jle 0x8d3b
incl %r14d
movq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0xd0dc
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0xd0dc
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0xd130
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 0x8d15
cmpl $0x1, %eax
jne 0x8d3b
movsd 0x38764(%rip), %xmm0    # 0x41470
subsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0xd130
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 0x8c7d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
jmp 0x8d71
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 0x8dc5
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x7420
jmp 0x8dc5
jmp 0x8dbf
jmp 0x8dbf
jmp 0x8dde
movq %rdx, %r12
movq %rax, %r15
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x8de4
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x7420
jmp 0x8de4
movq %rdx, %r12
movq %rax, %r15
movq %r15, %rdi
cmpl $0x1, %r12d
jne 0x8e04
callq 0x7170
movl $0xffffffff, 0x4(%r13)  # imm = 0xFFFFFFFF
callq 0x76a0
jmp 0x8c2a
callq 0x7740
nop