// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movl %ecx, %ebp
movq %rdx, (%rsp)
movq %rsi, %r13
movq %rdi, %r14
movl 0x1d8(%rdi), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x43201
movq %r14, %rdi
callq 0x42fec
movslq %ebp, %rbx
leaq 0x98(%r14), %rax
movq %rax, 0x28(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x150(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
leaq 0x58(%rsp), %rbp
leaq 0x78(%rsp), %r14
shlq $0x5, %rbx
leaq 0x90(%rsp), %r12
leaq 0xb0(%rsp), %r15
movq %rbx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq 0x8(%r13), %rcx
subq (%r13), %rcx
sarq $0x5, %rcx
cmpq %rcx, %rax
jae 0x43458
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
andq $0x0, 0x60(%rsp)
movb $0x0, 0x68(%rsp)
movq (%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x437e4
movq %rbp, %rdi
movq %rax, %rsi
callq 0x82a0
movq 0x20(%rsp), %rsi
shlq $0x5, %rsi
addq (%r13), %rsi
movq %r14, %rdi
pushq $0x3a
popq %rdx
callq 0x40349
movq 0x78(%rsp), %rsi
addq %rbx, %rsi
movq %r12, %rdi
callq 0x8600
movq %r14, %rdi
callq 0x28a08
movq %r12, %rdi
leaq 0x64f82(%rip), %rsi     # 0xa824a
callq 0x2193f
testb %al, %al
jne 0x4341b
movq %r12, %rdi
leaq 0x5c06c(%rip), %rsi     # 0x9f34b
callq 0x2193f
testb %al, %al
jne 0x4341b
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x43738
addl $0x2, (%rax)
movq %r14, %rdi
movq %r12, %rsi
pushq $0x2c
popq %rdx
callq 0x4030c
andq $0x0, 0x40(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq 0x8(%rsp), %rax
movl 0x1d8(%rax), %eax
cmpl $0x1, %eax
je 0x4338e
cmpl $0x2, %eax
je 0x43354
cmpl $0x3, %eax
jne 0x4339b
movq %r14, %rdi
callq 0x42e06
movq %r15, %rbx
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x42ed4
jmp 0x43372
movq %r14, %rdi
callq 0x42e73
movq %r15, %rbx
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x42ed4
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x46554
movq %rbx, %rdi
callq 0x2b43c
movq 0x18(%rsp), %rbx
jmp 0x4339b
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x43e60
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x43f2a
movsd (%rax), %xmm0
ucomisd 0x54244(%rip), %xmm0    # 0x975f8
jne 0x433c9
jp 0x433c9
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x43f2a
andq $0x0, (%rax)
movq 0x30(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x43f2a
movsd 0x50(%rsp), %xmm0
addsd %xmm0, %xmm0
addsd 0x48(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
leaq 0x30(%rsp), %rdi
callq 0x2b43c
movq %r14, %rdi
callq 0x2b43c
movq %r12, %rdi
callq 0x8978
movq %rbp, %rdi
callq 0x8978
movq 0x20(%rsp), %rax
incq %rax
jmp 0x43246
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4356c
movq %rbx, %rdi
callq 0x81d0
callq 0x8780
movq 0x18(%rsp), %rbx
jmp 0x43423
movq 0x8(%rsp), %rbp
movq 0x168(%rbp), %r12
leaq 0x158(%rbp), %rbx
leaq 0x188(%rbp), %r14
movq 0x10(%rsp), %r15
cmpq %rbx, %r12
je 0x43515
leaq 0x20(%r12), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x43f2a
movsd (%rax), %xmm0
ucomisd 0x5415c(%rip), %xmm0    # 0x975f8
jne 0x434a0
jnp 0x43505
movsd 0x40(%r12), %xmm0
movsd %xmm0, (%rsp)
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x43738
movsd (%rsp), %xmm1
cvtsi2sdl (%rax), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%r12)
movl 0x4(%rbp), %eax
testl %eax, %eax
je 0x434ec
cmpl $0x1, %eax
jne 0x43505
movsd 0x5410f(%rip), %xmm0    # 0x975f0
subsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
jmp 0x434f1
movsd %xmm1, (%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x43f2a
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r12, %rdi
callq 0x8340
movq %rax, %r12
jmp 0x43477
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x43569
jmp 0x43534
jmp 0x43534
jmp 0x4352f
movq %rax, %rbx
jmp 0x4354b
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2b43c
leaq 0x78(%rsp), %rdi
callq 0x2b43c
leaq 0x90(%rsp), %rdi
callq 0x8978
jmp 0x4356c
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x28a08
jmp 0x4356c
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x8978
movq %rbx, %rdi
callq 0x8870