// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r8d, 0x8(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %rax
movq %rdi, %r14
movq (%rsi), %rsi
movq %rax, 0x40(%rsp)
cmpq %rsi, 0x8(%rax)
je 0x9d00
movslq %ecx, %rbx
xorl %ebp, %ebp
leaq 0x48(%rsp), %r13
shlq $0x5, %rbx
xorl %r12d, %r12d
addq %rbp, %rsi
movq %r13, %rdi
movl $0x3a, %edx
callq 0x91a9
movq 0x48(%rsp), %rax
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax,%rbx), %rsi
movq 0x8(%rax,%rbx), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0xdfb6
movq %r13, %rdi
callq 0xd250
movq %r15, %rdi
leaq 0x368e3(%rip), %rsi     # 0x4052e
callq 0x70f0
testl %eax, %eax
je 0x9f45
movq %r15, %rsi
movq %r13, %r15
movq %r13, %rdi
movl $0x2c, %edx
callq 0x9b73
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rax
subq %rdi, %rax
cmpq $0x10, %rax
jne 0x9f94
movsd (%rdi), %xmm0
movsd 0x8(%rdi), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl 0x8(%rsp), %eax
jl 0x9cb1
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq 0x128(%r14), %rax
movsd %xmm0, (%rax,%r12,8)
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x9cda
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x7420
incq %r12
movq 0x40(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %rbp
cmpq %rax, %r12
movq %r15, %r13
jb 0x9c01
movq 0x38(%rsp), %r12
movq 0x18(%r12), %r15
addq $0x8, %r12
cmpq %r12, %r15
je 0x9f36
leaq 0x140(%r14), %rbp
leaq 0x170(%r14), %rax
movq %rax, 0x40(%rsp)
movq %rbp, 0x38(%rsp)
movq 0x40(%r15), %rax
movq 0x48(%r15), %rbx
subq %rax, %rbx
shrq $0x3, %rbx
testl %ebx, %ebx
jle 0x9feb
leaq 0x20(%r15), %r13
cmpl $0x1, %ebx
jne 0x9d7e
movslq (%rax), %rax
movq 0x128(%r14), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd44e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x9eb5
movq %r12, %rbp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
xorl %r12d, %r12d
movq 0x40(%r15), %rax
movslq (%rax,%r12,8), %rax
movq 0x128(%r14), %rcx
movsd (%rcx,%rax,8), %xmm0
ucomisd 0x366d7(%rip), %xmm0    # 0x40490
jne 0x9dbd
jnp 0x9de6
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x9dd8
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x9de6
leaq (%rcx,%rax,8), %rdx
leaq 0x10(%rsp), %rdi
callq 0xf2ce
incq %r12
cmpq %r12, %rbx
jne 0x9d9d
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd4a2
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rcx, %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %rax, %rcx
movq %rbp, %r12
je 0x9e3e
cmpq $0x1, %rbx
movq %rbx, %rcx
adcq $0x0, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movq 0x38(%rsp), %rbp
addsd (%rax,%rdx,8), %xmm0
incq %rdx
cmpq %rdx, %rcx
jne 0x9e2f
jmp 0x9e47
xorpd %xmm0, %xmm0
movq 0x38(%rsp), %rbp
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd44e
movq %rbx, %xmm0
punpckldq 0x3666b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x36673(%rip), %xmm0    # 0x404e0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x9e9e
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9eb5
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movl 0x4(%r14), %eax
cmpl $0x1, %eax
je 0x9ed3
testl %eax, %eax
jne 0x9f22
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd44e
movsd (%rax), %xmm0
jmp 0x9f05
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd44e
movsd (%rax), %xmm0
ucomisd 0x365a6(%rip), %xmm0    # 0x40490
jne 0x9eee
jnp 0x9f22
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd44e
movsd 0x3656f(%rip), %xmm0    # 0x40470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0xd44e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
callq 0x74d0
movq %rax, %r15
cmpq %r12, %rax
jne 0x9d2f
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4d09c(%rip), %rdi     # 0x56fe8
leaq 0x365a6(%rip), %rsi     # 0x404f9
movl $0x27, %edx
callq 0x74b0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x4d07a(%rip), %rdi     # 0x56fe8
callq 0x74b0
movq %rax, %rbx
leaq 0x365a4(%rip), %rsi     # 0x40521
movl $0xe, %edx
movq %rax, %rdi
callq 0x74b0
movq %rbx, %rdi
callq 0x71b0
jmp 0x9fe1
movq 0x4d04d(%rip), %rdi     # 0x56fe8
leaq 0x3658e(%rip), %rsi     # 0x40530
movl $0x1f, %edx
callq 0x74b0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x4d02b(%rip), %rdi     # 0x56fe8
callq 0x74b0
movq %rax, %rbx
leaq 0x36555(%rip), %rsi     # 0x40521
movl $0xe, %edx
movq %rax, %rdi
callq 0x74b0
movq %rbx, %rdi
callq 0x71b0
movl $0x1, %edi
callq 0x7510
leaq 0x3655e(%rip), %rdi     # 0x40550
leaq 0x36570(%rip), %rsi     # 0x40569
leaq 0x3657a(%rip), %rcx     # 0x4057a
movl $0xee, %edx
callq 0x7290
jmp 0xa071
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xa074
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xa074
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xa058
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xa058
jmp 0xa055
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xd250
jmp 0xa08b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa08b
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0xa086
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa08b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq %rbx, %rdi
callq 0x7740
nop