// File: /workspace/github_cpp_makefile_star2_O1/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 0x54293
movq 0x10(%rsp), %rdi
callq 0x5406e
movq $0x0, 0x58(%rsp)
movq 0x8(%r15), %rax
cmpq (%r15), %rax
je 0x5468a
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 0x54b56
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 0x50624
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 0x2e45c
movq %rbp, %rdi
callq 0x3123c
movq %r14, %rdi
leaq 0x8beec(%rip), %rsi     # 0xe0265
callq 0x8160
testl %eax, %eax
je 0x54606
movq %r14, %rdi
leaq 0x82dab(%rip), %rsi     # 0xd713b
callq 0x8160
testl %eax, %eax
je 0x54606
movq 0xc0(%rsp), %rdi
movq %r12, %rsi
callq 0x54a86
addl $0x2, (%rax)
movq %rbp, %rdi
movq %r14, %rsi
movl $0x2c, %edx
callq 0x505d8
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x10(%rsp), %rax
movl 0x1d8(%rax), %eax
cmpl $0x1, %eax
je 0x54554
cmpl $0x2, %eax
je 0x54483
cmpl $0x3, %eax
jne 0x54561
movq 0x40(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x82a96(%rip), %xmm0    # 0xd6ea0
divsd %xmm0, %xmm1
movsd 0x82a92(%rip), %xmm0    # 0xd6ea8
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x8(%rax), %xmm1
divsd 0x82a6f(%rip), %xmm1    # 0xd6ea0
movsd 0x82a6f(%rip), %xmm0    # 0xd6ea8
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movsd 0x10(%rax), %xmm1
divsd 0x82a4b(%rip), %xmm1    # 0xd6ea0
movsd 0x82a4b(%rip), %xmm0    # 0xd6ea8
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 0x53f46
jmp 0x544fb
movq 0x40(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x82a14(%rip), %xmm0    # 0xd6ea8
divsd %xmm0, %xmm1
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x8(%rax), %xmm1
movsd 0x829f5(%rip), %xmm0    # 0xd6ea8
divsd %xmm0, %xmm1
callq 0x8830
movq 0x40(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movsd 0x10(%rax), %xmm1
movsd 0x829d5(%rip), %xmm0    # 0xd6ea8
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 0x53f46
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
movupd 0x68(%rsp), %xmm0
movupd %xmm0, 0x28(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
testq %rdi, %rdi
je 0x5453b
subq %rdi, %rsi
callq 0x8480
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x54561
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
jmp 0x54561
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x55112
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x551e8
movsd (%rax), %xmm0
ucomisd 0x7aece(%rip), %xmm0    # 0xcf448
jne 0x54592
jp 0x54592
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x551e8
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 0x551e8
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 0x545ef
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x54606
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x5462b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xa0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x54648
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 0x542ec
jmp 0x5468a
movq %rax, 0x8(%rsp)
cmpl $0x1, %edx
jne 0x547f2
movq 0x8(%rsp), %rdi
callq 0x81c0
callq 0x8760
jmp 0x5462b
movq 0x10(%rsp), %rax
movq 0x168(%rax), %r14
leaq 0x158(%rax), %rbx
cmpq %rbx, %r14
je 0x54761
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 0x551e8
movsd (%rax), %xmm0
ucomisd 0x7ad6d(%rip), %xmm0    # 0xcf448
jne 0x546df
jnp 0x5474d
movsd 0x40(%r14), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x54a86
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 0x54732
cmpl $0x1, %eax
jne 0x5474d
movsd 0x7ad1a(%rip), %xmm0    # 0xcf440
subsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x54738
movsd %xmm1, 0x18(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x551e8
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r14, %rdi
callq 0x8310
movq %rax, %r14
cmpq %rbx, %rax
jne 0x546c0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x54782
jmp 0x5479a
jmp 0x5479a
jmp 0x5477b
movq %rax, 0x8(%rsp)
jmp 0x547cd
movq %rax, 0x8(%rsp)
jmp 0x547f2
movq %rax, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x3123c
jmp 0x547f2
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x547b6
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x547cd
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x547f2
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xa0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x5480f
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x8(%rsp), %rdi
callq 0x8840
nop