// File: 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
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x120(%rbp)
cmpl $0x3, 0x1d8(%rax)
je 0x826ae
movq -0x120(%rbp), %rax
cmpl $0x2, 0x1d8(%rax)
jne 0x826ba
movq -0x120(%rbp), %rdi
callq 0x82340
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3ffd0
movq %rax, %rcx
movq -0x128(%rbp), %rax
cmpq %rcx, %rax
jae 0x82ad6
leaq -0x48(%rbp), %rdi
callq 0xa820
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x83390
movq %rax, -0x130(%rbp)
jmp 0x82708
movq -0x130(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xa060
jmp 0x8271a
jmp 0x82769
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x82ac8
movq -0x50(%rbp), %rdi
callq 0xa210
movq %rax, -0x60(%rbp)
movl $0x4, -0x64(%rbp)
callq 0xaa20
jmp 0x82753
jmp 0x82a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x82ac8
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x52960
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
movl $0x3a, %edx
callq 0x7bbe0
jmp 0x8278c
movslq -0x1c(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x3d940
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0xa250
jmp 0x827ad
leaq -0xa0(%rbp), %rdi
callq 0x3dfa0
leaq 0xc1f64(%rip), %rsi     # 0x144724
leaq -0x88(%rbp), %rdi
callq 0x2d770
movb %al, -0x131(%rbp)
jmp 0x827d4
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x82807
jmp 0x827e0
leaq 0xb8c44(%rip), %rsi     # 0x13b42b
leaq -0x88(%rbp), %rdi
callq 0x2d770
movb %al, -0x132(%rbp)
jmp 0x827fb
movb -0x132(%rbp), %al
testb $0x1, %al
jne 0x82807
jmp 0x82841
movl $0x4, -0x64(%rbp)
jmp 0x82a89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3dfa0
jmp 0x82ac8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x82abc
movq -0x120(%rbp), %rdi
addq $0x98, %rdi
leaq -0x48(%rbp), %rsi
callq 0x83190
movq %rax, -0x140(%rbp)
jmp 0x82861
movq -0x140(%rbp), %rax
movl (%rax), %ecx
addl $0x2, %ecx
movl %ecx, (%rax)
leaq -0xb8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movl $0x2c, %edx
callq 0x7bb60
jmp 0x82889
leaq -0xd0(%rbp), %rdi
callq 0x48410
movq -0x120(%rbp), %rax
movl 0x1d8(%rax), %eax
movl %eax, -0x144(%rbp)
subl $0x1, %eax
je 0x8299f
jmp 0x828b3
movl -0x144(%rbp), %eax
subl $0x2, %eax
je 0x82950
jmp 0x828c4
movl -0x144(%rbp), %eax
subl $0x3, %eax
jne 0x829b6
jmp 0x828d5
leaq -0xb8(%rbp), %rdi
callq 0x81ef0
jmp 0x828e3
movq -0x120(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x82100
jmp 0x82903
leaq -0xd0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x84540
leaq -0xe8(%rbp), %rdi
callq 0x3ecb0
jmp 0x829b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3ecb0
leaq -0xb8(%rbp), %rdi
callq 0x3ecb0
jmp 0x82abc
leaq -0xb8(%rbp), %rdi
callq 0x82020
jmp 0x8295e
movq -0x120(%rbp), %rsi
leaq -0x100(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x82100
jmp 0x8297e
leaq -0xd0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x84540
leaq -0x100(%rbp), %rdi
callq 0x3ecb0
jmp 0x829b6
leaq -0xd0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x84570
jmp 0x829b4
jmp 0x829b6
movq -0x120(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
leaq -0x48(%rbp), %rsi
callq 0x847c0
movq %rax, -0x150(%rbp)
jmp 0x829d6
movq -0x150(%rbp), %rax
movsd (%rax), %xmm0
movsd 0xb0cd7(%rip), %xmm1    # 0x1336c0
ucomisd %xmm1, %xmm0
jne 0x82a1f
jp 0x82a1f
movq -0x120(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
leaq -0x48(%rbp), %rsi
callq 0x847c0
movq %rax, -0x158(%rbp)
jmp 0x82a11
movq -0x158(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq -0xd0(%rbp), %rdi
callq 0x81e90
movq -0x120(%rbp), %rdi
movsd %xmm0, -0x168(%rbp)
addq $0x150, %rdi            # imm = 0x150
leaq -0x48(%rbp), %rsi
callq 0x847c0
movq %rax, -0x160(%rbp)
jmp 0x82a53
movq -0x160(%rbp), %rax
movsd -0x168(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
leaq -0xd0(%rbp), %rdi
callq 0x3ecb0
leaq -0xb8(%rbp), %rdi
callq 0x3ecb0
movl $0x0, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xac88
leaq -0x48(%rbp), %rdi
callq 0xac88
movl -0x64(%rbp), %eax
testl %eax, %eax
je 0x82aa9
jmp 0x82aa7
jmp 0x82aab
jmp 0x82aab
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x826c2
leaq -0x88(%rbp), %rdi
callq 0xac88
leaq -0x48(%rbp), %rdi
callq 0xac88
jmp 0x82cd7
movq -0x120(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x84460
movq %rax, -0x108(%rbp)
movq -0x120(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x844c0
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x84490
testb $0x1, %al
jne 0x82b26
jmp 0x82cce
movq -0x120(%rbp), %rax
addq $0x150, %rax            # imm = 0x150
movq %rax, -0x170(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x844f0
movq -0x170(%rbp), %rdi
movq %rax, %rsi
callq 0x847c0
movsd (%rax), %xmm0
movsd 0xb0b5f(%rip), %xmm1    # 0x1336c0
ucomisd %xmm1, %xmm0
jne 0x82b6e
jp 0x82b6e
jmp 0x82cbb
leaq -0x108(%rbp), %rdi
callq 0x844f0
movq %rax, %rcx
movq -0x120(%rbp), %rax
movsd 0x20(%rcx), %xmm0
movsd %xmm0, -0x180(%rbp)
addq $0x98, %rax
movq %rax, -0x188(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x844f0
movq -0x188(%rbp), %rdi
movq %rax, %rsi
callq 0x83190
movsd -0x180(%rbp), %xmm0
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x118(%rbp)
movsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x178(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x844f0
movsd -0x178(%rbp), %xmm0
movq %rax, %rcx
movq -0x120(%rbp), %rax
movsd %xmm0, 0x20(%rcx)
cmpl $0x0, 0x4(%rax)
jne 0x82c57
movq -0x120(%rbp), %rax
movsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x190(%rbp)
addq $0x188, %rax            # imm = 0x188
movq %rax, -0x198(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x844f0
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0x847c0
movsd -0x190(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x82cb9
movq -0x120(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x82cb7
movq -0x120(%rbp), %rax
movsd 0xaf645(%rip), %xmm0    # 0x1322b8
subsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x1a0(%rbp)
addq $0x188, %rax            # imm = 0x188
movq %rax, -0x1a8(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x844f0
movq -0x1a8(%rbp), %rdi
movq %rax, %rsi
callq 0x847c0
movsd -0x1a0(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x82cb9
jmp 0x82cbb
jmp 0x82cbd
leaq -0x108(%rbp), %rdi
callq 0x84510
jmp 0x82af0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0xab50