// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/process_vcf_utils.cpp
// Function: GeneralSetCounts::getAFsFromGenotypeLikelihoodsOrProbabilities(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&, int)
void GeneralSetCounts::getAFsFromGenotypeLikelihoodsOrProbabilities(const std::vector<std::string>& genotypeFields, const std::map<size_t, string>& posToSpeciesMap, const int likelihoodsOrProbabilitiesTagPosition) {
    if (likelihoodsProbabilitiesType == LikelihoodsProbabilitiesPL || likelihoodsProbabilitiesType == LikelihoodsProbabilitiesGL) {
        setHWEpriorsFromAFfromGT();
    }
    
    for (std::vector<std::string>::size_type i = 0; i < genotypeFields.size(); i++) {
       // std::cerr << "Here posToSpeciesMap.at(i): " << posToSpeciesMap.at(i) << std::endl;
        std::string species; try { species = posToSpeciesMap.at(i); } catch (const std::out_of_range& oor) {
            // std::cerr << "Here the species is not in the map" << std::endl;
            continue;
        }
       // std::cerr << genotypeFields[i] << std::endl;
        std::string thisLikelihoodsOrProbabilitiesString = split(genotypeFields[i], ':')[likelihoodsOrProbabilitiesTagPosition];
        if (thisLikelihoodsOrProbabilitiesString == "." || thisLikelihoodsOrProbabilitiesString == "0,0,0") continue;
        
        else {
            setAlleleProbCounts.at(species) += 2;
            std::vector<double> thisLikelihoodsOrProbabilities = splitToDouble(thisLikelihoodsOrProbabilitiesString,',');
            std::vector<double> thisProbabilities;
            switch (likelihoodsProbabilitiesType)
            {
                case LikelihoodsProbabilitiesPL:
                    transformFromPhred(thisLikelihoodsOrProbabilities);
                   // print_vector(thisLikelihoodsOrProbabilities, std::cerr);
                    thisProbabilities = probabilitiesFromLikelihoods(thisLikelihoodsOrProbabilities,species);
                    break;
                case LikelihoodsProbabilitiesGL: transformFromGL(thisLikelihoodsOrProbabilities);
                    thisProbabilities = probabilitiesFromLikelihoods(thisLikelihoodsOrProbabilities,species);
                    break;
                case LikelihoodsProbabilitiesGP:
                    thisProbabilities = thisLikelihoodsOrProbabilities;
                    break;
            }
            if (setAAFsFromLikelihoods.at(species) == -1) setAAFsFromLikelihoods.at(species) = 0;
            setAAFsFromLikelihoods.at(species) += getExpectedGenotype(thisProbabilities);
        }
    }
    
    for(std::map<string,double>::iterator it = setAAFsFromLikelihoods.begin(); it != setAAFsFromLikelihoods.end(); ++it) {
        if (setAAFsFromLikelihoods.at(it->first) != -1) {
            double AF = it->second/setAlleleProbCounts.at(it->first);
            it->second = AF;
            if (AAint == AncestralAlleleRef) {
                setDAFsFromLikelihoods.at(it->first) = AF;
            } else if (AAint == AncestralAlleleAlt) {
                setDAFsFromLikelihoods.at(it->first) = (1 - AF);
            }
        }
    }
     
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %ecx, %ebp
movq %rdx, 0xd0(%rsp)
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
movl 0x1d8(%rdi), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x510eb
movq 0x10(%rsp), %rdi
callq 0x50ec6
movq $0x0, 0x58(%rsp)
movq 0x8(%r15), %rax
cmpq (%r15), %rax
je 0x514e2
leaq 0xb0(%rsp), %rbx
movslq %ebp, %r13
movq 0x10(%rsp), %rax
leaq 0x98(%rax), %rcx
movq %rcx, 0xc0(%rsp)
addq $0x150, %rax            # imm = 0x150
movq %rax, 0x18(%rsp)
leaq 0xa0(%rsp), %r12
leaq 0x40(%rsp), %rbp
shlq $0x5, %r13
leaq 0x80(%rsp), %r14
movq %rbx, 0xa0(%rsp)
movq $0x0, 0xa8(%rsp)
movb $0x0, 0xb0(%rsp)
movq 0xd0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x519c2
movq %r12, %rdi
movq %rax, %rsi
callq 0x8270
movq 0x58(%rsp), %rsi
shlq $0x5, %rsi
addq (%r15), %rsi
movq %rbp, %rdi
movl $0x3a, %edx
callq 0x4d650
movq 0x40(%rsp), %rax
leaq 0x90(%rsp), %rcx
movq %rcx, 0x80(%rsp)
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x2ba06
movq %rbp, %rdi
callq 0x2e784
movq %r14, %rdi
leaq 0x87674(%rip), %rsi     # 0xd8845
callq 0x8160
testl %eax, %eax
je 0x5145e
movq %r14, %rdi
leaq 0x7f47f(%rip), %rsi     # 0xd0667
callq 0x8160
testl %eax, %eax
je 0x5145e
movq 0xc0(%rsp), %rdi
movq %r12, %rsi
callq 0x518f2
addl $0x2, (%rax)
movq %rbp, %rdi
movq %r14, %rsi
movl $0x2c, %edx
callq 0x4d604
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x10(%rsp), %rax
movl 0x1d8(%rax), %eax
cmpl $0x1, %eax
je 0x513ac
cmpl $0x2, %eax
je 0x512db
cmpl $0x3, %eax
jne 0x513b9
movq 0x40(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x7f0ce(%rip), %xmm0    # 0xd0330
divsd %xmm0, %xmm1
movsd 0x7f0ca(%rip), %xmm0    # 0xd0338
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x8(%rax), %xmm1
divsd 0x7f0a7(%rip), %xmm1    # 0xd0330
movsd 0x7f0a7(%rip), %xmm0    # 0xd0338
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movsd 0x10(%rax), %xmm1
divsd 0x7f083(%rip), %xmm1    # 0xd0330
movsd 0x7f083(%rip), %xmm0    # 0xd0338
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, 0x10(%rax)
leaq 0x60(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x50da0
jmp 0x51353
movq 0x40(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x7f04c(%rip), %xmm0    # 0xd0338
divsd %xmm0, %xmm1
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x8(%rax), %xmm1
movsd 0x7f02d(%rip), %xmm0    # 0xd0338
divsd %xmm0, %xmm1
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movsd 0x10(%rax), %xmm1
movsd 0x7f00d(%rip), %xmm0    # 0xd0338
divsd %xmm0, %xmm1
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, 0x10(%rax)
leaq 0x60(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x50da0
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rsi
movapd 0x60(%rsp), %xmm0
movapd %xmm0, 0x20(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
testq %rdi, %rdi
je 0x513b9
subq %rdi, %rsi
callq 0x8480
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x513b9
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
jmp 0x513b9
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x5211e
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x52202
movsd (%rax), %xmm0
ucomisd 0x7b346(%rip), %xmm0    # 0xcc718
jne 0x513ea
jp 0x513ea
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x52202
movq $0x0, (%rax)
movq 0x20(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xc8(%rsp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x52202
movsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm0
addsd 0xc8(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x51447
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x5145e
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x51483
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xa0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x514a0
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x58(%rsp), %rax
incq %rax
movq %rax, 0x58(%rsp)
movq 0x8(%r15), %rcx
subq (%r15), %rcx
sarq $0x5, %rcx
cmpq %rcx, %rax
jb 0x51144
jmp 0x514e2
movq %rax, 0x8(%rsp)
cmpl $0x1, %edx
jne 0x5164a
movq 0x8(%rsp), %rdi
callq 0x81c0
callq 0x8760
jmp 0x51483
movq 0x10(%rsp), %rax
movq 0x168(%rax), %r14
leaq 0x158(%rax), %rbx
cmpq %rbx, %r14
je 0x515b9
movq 0x10(%rsp), %rax
leaq 0x150(%rax), %r15
leaq 0x98(%rax), %r12
leaq 0x188(%rax), %r13
leaq 0x20(%r14), %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x52202
movsd (%rax), %xmm0
ucomisd 0x7b1e5(%rip), %xmm0    # 0xcc718
jne 0x51537
jnp 0x515a5
movsd 0x40(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x518f2
movsd 0x18(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%r14)
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
testl %eax, %eax
je 0x5158a
cmpl $0x1, %eax
jne 0x515a5
movsd 0x7b192(%rip), %xmm0    # 0xcc710
subsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x51590
movsd %xmm1, 0x18(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x52202
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r14, %rdi
callq 0x8310
movq %rax, %r14
cmpq %rbx, %rax
jne 0x51518
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x515da
jmp 0x515f2
jmp 0x515f2
jmp 0x515d3
movq %rax, 0x8(%rsp)
jmp 0x51625
movq %rax, 0x8(%rsp)
jmp 0x5164a
movq %rax, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x2e784
jmp 0x5164a
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5160e
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x51625
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x5164a
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xa0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x51667
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x8(%rsp), %rdi
callq 0x8840
nop