// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
callq 0x861c
movq %rbx, 0x8(%rsp)
leaq 0xc8(%rbx), %r14
leaq 0x2e6fd(%rip), %rsi     # 0x36a9a
leaq 0x38(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x8102
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0xb760
movl (%rax), %ebx
leaq 0x38(%rsp), %rdi
callq 0x7898
testl %ebx, %ebx
jle 0x8471
leaq 0x2e6c6(%rip), %rsi     # 0x36a9a
leaq 0x38(%rsp), %rdi
leaq 0x17(%rsp), %rdx
callq 0x8102
movq 0x8(%rsp), %rax
leaq 0x98(%rax), %rdi
leaq 0x38(%rsp), %rsi
callq 0xb760
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
leaq 0x2e691(%rip), %rsi     # 0x36a9a
leaq 0x58(%rsp), %rdi
leaq 0x16(%rsp), %rdx
callq 0x8102
leaq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0xb760
cvtsi2sdl (%rax), %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
leaq 0x58(%rsp), %rdi
callq 0x7898
leaq 0x38(%rsp), %rdi
callq 0x7898
movsd 0x2e025(%rip), %xmm0    # 0x36478
ucomisd (%rsp), %xmm0
jbe 0x8465
movq 0x8(%rsp), %rax
andl $0x0, 0x4(%rax)
jmp 0x8471
movq 0x8(%rsp), %rax
movl $0x1, 0x4(%rax)
movq 0x8(%rsp), %rax
leaq 0x98(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0xb0(%rax), %rbp
leaq 0xa0(%rax), %r13
leaq 0x1e8(%rax), %r12
addq $0x220, %rax            # imm = 0x220
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x18(%rsp)
cmpq %r13, %rbp
je 0x8588
leaq 0x20(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0xb760
cmpl $0x0, (%rax)
jle 0x8578
incl %r15d
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0xb760
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0xb760
cvtsi2sdl (%rax), %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0xb7a6
movsd (%rsp), %xmm1
movsd %xmm1, (%rax)
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
testl %eax, %eax
je 0x8552
cmpl $0x1, %eax
jne 0x8578
movsd 0x2df27(%rip), %xmm0    # 0x36470
subsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0xb7a6
movsd (%rsp), %xmm1
movsd %xmm1, (%rax)
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbp, %rdi
callq 0x7300
movq %rax, %rbp
jmp 0x84b5
cvtsi2sd %r15d, %xmm0
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x8(%rsp), %rax
movsd %xmm1, 0x218(%rax)
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x250(%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r12
movq %rax, %r15
leaq 0x58(%rsp), %rdi
callq 0x7898
jmp 0x85e3
jmp 0x85dd
jmp 0x85dd
jmp 0x85ef
movq %rdx, %r12
movq %rax, %r15
leaq 0x38(%rsp), %rdi
callq 0x7898
jmp 0x85f5
movq %rdx, %r12
movq %rax, %r15
movq %r15, %rdi
cmpl $0x1, %r12d
jne 0x8616
callq 0x7190
movq 0x8(%rsp), %rax
orl $-0x1, 0x4(%rax)
callq 0x76a0
jmp 0x8471
callq 0x7750
nop