// File: millanek[P]Dsuite/Dsuite_utils.cpp
// Function: GeneralSetCounts::getAFsFromADtag(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<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<unsigned long, std::allocator<unsigned long>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::vector<unsigned long, std::allocator<unsigned long>>>>> const&, int, int)
void GeneralSetCounts::getAFsFromADtag(const std::vector<std::string>& genotypeFields, const std::map<string, std::vector<size_t>>& setsToPosMap, const int ADTagPosition, const int minDepth) {
    for (std::vector<std::string>::size_type i = 0; i < genotypeFields.size(); i++) {
          // std::cerr << genotypeFields[i] << std::endl;
           std::string thisADstring = split(genotypeFields[i], ':')[ADTagPosition];
           if (thisADstring == ".") {
               std::cerr << "The AD tag info appears to be missing: " << thisADstring << " ; Exiting ..." << std::endl;
               exit(1);
           }
           
           else {
               std::vector<double> ADs = splitToDouble(thisADstring,',');
               if (ADs.size() != 2) {
                   std::cerr << "This AD tag appears malformed: " << thisADstring << " ; Exiting ..." << std::endl;
                   exit(1);
               }
               
               int overallDepth = ADs[0] + ADs[1];
               if (overallDepth >= minDepth) {
                    individualPoolAAFs[i] = ADs[0]/(overallDepth);
               }
           }
       }
       
       for(std::map<string, std::vector<size_t>>::const_iterator it = setsToPosMap.begin(); it != setsToPosMap.end(); ++it) {
           int individualsInThisSet = (int) it->second.size();
           assert(individualsInThisSet > 0);
           if (individualsInThisSet == 1) {
               int pos = (int) it->second[0];
               setPoolAAFs.at(it->first) = individualPoolAAFs[pos];
           } else {
               std::vector<double> thisSetAFs;
               for (int i = 0; i < individualsInThisSet; i++) {
                   int pos = (int) it->second[i];
                   if (individualPoolAAFs[pos] != -1.0) thisSetAFs.push_back(individualPoolAAFs[pos]);
               }
               setPoolAAFs.at(it->first) = vector_average(thisSetAFs);
               
           }
           
           
           if (AAint == AncestralAlleleRef) {
               setPoolDAFs.at(it->first) = setPoolAAFs.at(it->first);
           } else if (AAint == AncestralAlleleAlt && setPoolAAFs.at(it->first) != -1.0) {
               setPoolDAFs.at(it->first) = (1 - setPoolAAFs.at(it->first));
           }
           
               
       }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10740
movq %rax, %rcx
movq -0xf0(%rbp), %rax
cmpq %rcx, %rax
jae 0xc13d
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x10720
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
movl $0x3a, %edx
callq 0xaef0
movq -0xf8(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x10b10
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x8250
jmp 0xbeeb
leaq -0x60(%rbp), %rdi
callq 0x10760
leaq 0x7c63b(%rip), %rsi     # 0x88536
leaq -0x48(%rbp), %rdi
callq 0x9ab0
movb %al, -0xf9(%rbp)
jmp 0xbf0c
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0xbf1b
jmp 0xbfb6
movq 0xb30ce(%rip), %rdi     # 0xbeff0
leaq 0x7c5d8(%rip), %rsi     # 0x88501
callq 0x8590
movq %rax, -0x108(%rbp)
jmp 0xbf37
movq -0x108(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x8520
movq %rax, -0x110(%rbp)
jmp 0xbf50
movq -0x110(%rbp), %rdi
leaq 0x7c5cb(%rip), %rsi     # 0x88529
callq 0x8590
movq %rax, -0x118(%rbp)
jmp 0xbf6c
movq -0x118(%rbp), %rdi
movq 0xb2fe6(%rip), %rsi     # 0xbef60
callq 0x85f0
jmp 0xbf81
movl $0x1, %edi
callq 0x86e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x10760
jmp 0xc56c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc12f
leaq -0x88(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0x2c, %edx
callq 0xbdd0
jmp 0xbfcd
leaq -0x88(%rbp), %rdi
callq 0x10e50
cmpq $0x2, %rax
je 0xc070
movq 0xb3006(%rip), %rdi     # 0xbeff0
leaq 0x7c547(%rip), %rsi     # 0x88538
callq 0x8590
movq %rax, -0x120(%rbp)
jmp 0xbfff
movq -0x120(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x8520
movq %rax, -0x128(%rbp)
jmp 0xc018
movq -0x128(%rbp), %rdi
leaq 0x7c503(%rip), %rsi     # 0x88529
callq 0x8590
movq %rax, -0x130(%rbp)
jmp 0xc034
movq -0x130(%rbp), %rdi
movq 0xb2f1e(%rip), %rsi     # 0xbef60
callq 0x85f0
jmp 0xc049
movl $0x1, %edi
callq 0x86e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x10930
jmp 0xc12f
leaq -0x88(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x107e0
movsd (%rax), %xmm0
movsd %xmm0, -0x138(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x107e0
movsd -0x138(%rbp), %xmm0
addsd (%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jl 0xc109
leaq -0x88(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x107e0
movq -0xe8(%rbp), %rdi
movsd (%rax), %xmm0
cvtsi2sdl -0x8c(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x140(%rbp)
addq $0x128, %rdi            # imm = 0x128
movq -0x28(%rbp), %rsi
callq 0x107e0
movsd -0x140(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x88(%rbp), %rdi
callq 0x10930
leaq -0x48(%rbp), %rdi
callq 0x8c08
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xbe81
leaq -0x48(%rbp), %rdi
callq 0x8c08
jmp 0xc56c
movq -0x18(%rbp), %rdi
callq 0x10e70
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10ed0
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x10ea0
testb $0x1, %al
jne 0xc179
jmp 0xc563
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq %rax, %rdi
addq $0x20, %rdi
callq 0x10f30
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jle 0xc1a2
jmp 0xc1c1
leaq 0x7c3af(%rip), %rdi     # 0x88558
leaq 0x7c3c1(%rip), %rsi     # 0x88571
movl $0xee, %edx
leaq 0x7c3c6(%rip), %rcx     # 0x88582
callq 0x83b0
cmpl $0x1, -0xa4(%rbp)
jne 0xc25c
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq %rax, %rdi
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10f50
movq -0xe8(%rbp), %rdi
movq (%rax), %rax
movl %eax, -0xa8(%rbp)
addq $0x128, %rdi            # imm = 0x128
movslq -0xa8(%rbp), %rsi
callq 0x107e0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x148(%rbp)
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x150(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq -0x150(%rbp), %rdi
movq %rax, %rsi
callq 0x10db0
movsd -0x148(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0xc3e9
leaq -0xc0(%rbp), %rdi
callq 0x10800
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jge 0xc330
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq %rax, %rdi
addq $0x20, %rdi
movslq -0xc4(%rbp), %rsi
callq 0x10f50
movq -0xe8(%rbp), %rdi
movq (%rax), %rax
movl %eax, -0xc8(%rbp)
addq $0x128, %rdi            # imm = 0x128
movslq -0xc8(%rbp), %rsi
callq 0x107e0
movsd (%rax), %xmm0
movsd 0x7c1f6(%rip), %xmm1    # 0x884c8
ucomisd %xmm1, %xmm0
jne 0xc2dc
jp 0xc2dc
jmp 0xc31a
movq -0xe8(%rbp), %rdi
addq $0x128, %rdi            # imm = 0x128
movslq -0xc8(%rbp), %rsi
callq 0x107e0
movq %rax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x10f70
jmp 0xc307
jmp 0xc31a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc3d8
jmp 0xc31c
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xc272
leaq -0xe0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x110a0
jmp 0xc345
leaq -0xe0(%rbp), %rdi
callq 0x10fe0
movsd %xmm0, -0x158(%rbp)
jmp 0xc35b
movq -0xe8(%rbp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x168(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq -0x168(%rbp), %rdi
movq %rax, %rsi
callq 0x10db0
movq %rax, -0x160(%rbp)
jmp 0xc393
movq -0x160(%rbp), %rax
movsd -0x158(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xe0(%rbp), %rdi
callq 0x10930
leaq -0xc0(%rbp), %rdi
callq 0x10930
jmp 0xc3e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x10930
leaq -0xc0(%rbp), %rdi
callq 0x10930
jmp 0xc56c
movq -0xe8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xc474
movq -0xe8(%rbp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x180(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq -0x180(%rbp), %rdi
movq %rax, %rsi
callq 0x10db0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x170(%rbp)
addq $0x170, %rax            # imm = 0x170
movq %rax, -0x178(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq -0x178(%rbp), %rdi
movq %rax, %rsi
callq 0x10db0
movsd -0x170(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0xc550
movq -0xe8(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0xc54e
movq -0xe8(%rbp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x188(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq -0x188(%rbp), %rdi
movq %rax, %rsi
callq 0x10db0
movsd (%rax), %xmm0
movsd 0x7c008(%rip), %xmm1    # 0x884c8
ucomisd %xmm1, %xmm0
jne 0xc4cd
jp 0xc4cd
jmp 0xc54e
movq -0xe8(%rbp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x1a0(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq -0x1a0(%rbp), %rdi
movq %rax, %rsi
callq 0x10db0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movsd 0x7bf9a(%rip), %xmm0    # 0x884a8
subsd (%rcx), %xmm0
movsd %xmm0, -0x190(%rbp)
addq $0x170, %rax            # imm = 0x170
movq %rax, -0x198(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10f00
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0x10db0
movsd -0x190(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0xc550
jmp 0xc552
leaq -0x98(%rbp), %rdi
callq 0x11190
jmp 0xc14d
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x8a50
nopw %cs:(%rax,%rax)