// File: /workspace/github_cpp_makefile_star2_O3/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 0x9d16
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 0x91c1
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 0xdf1c
movq %r13, %rdi
callq 0xd1ac
movq %r15, %rdi
leaq 0x3791d(%rip), %rsi     # 0x4157e
callq 0x70f0
testl %eax, %eax
je 0x9f42
movq %r15, %rsi
movq %r13, %r15
movq %r13, %rdi
movl $0x2c, %edx
callq 0x9b89
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rax
subq %rdi, %rax
cmpq $0x10, %rax
jne 0x9f91
movsd (%rdi), %xmm0
movsd 0x8(%rdi), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl 0x8(%rsp), %eax
jl 0x9cc7
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 0x9cf0
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 0x9c17
movq 0x38(%rsp), %r12
movq 0x18(%r12), %r15
addq $0x8, %r12
cmpq %r12, %r15
je 0x9f33
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 0x9fe8
leaq 0x20(%r15), %r13
cmpl $0x1, %ebx
jne 0x9d94
movslq (%rax), %rax
movq 0x128(%r14), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd3b4
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x9eb2
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 0x376c1(%rip), %xmm0    # 0x41490
jne 0x9dd3
jnp 0x9dfc
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x9dee
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x9dfc
leaq (%rcx,%rax,8), %rdx
leaq 0x10(%rsp), %rdi
callq 0xf47e
incq %r12
cmpq %r12, %rbx
jne 0x9db3
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd408
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rcx, %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %rax, %rcx
movq %rbp, %r12
je 0x9e54
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 0x9e45
jmp 0x9e5d
xorpd %xmm0, %xmm0
movq 0x38(%rsp), %rbp
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd3b4
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x9e9b
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9eb2
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movl 0x4(%r14), %eax
cmpl $0x1, %eax
je 0x9ed0
testl %eax, %eax
jne 0x9f1f
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd3b4
movsd (%rax), %xmm0
jmp 0x9f02
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd3b4
movsd (%rax), %xmm0
ucomisd 0x375a9(%rip), %xmm0    # 0x41490
jne 0x9eeb
jnp 0x9f1f
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd3b4
movsd 0x37572(%rip), %xmm0    # 0x41470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0xd3b4
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
callq 0x74d0
movq %rax, %r15
cmpq %r12, %rax
jne 0x9d45
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4e09f(%rip), %rdi     # 0x57fe8
leaq 0x375f9(%rip), %rsi     # 0x41549
movl $0x27, %edx
callq 0x74b0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x4e07d(%rip), %rdi     # 0x57fe8
callq 0x74b0
movq %rax, %rbx
leaq 0x375f7(%rip), %rsi     # 0x41571
movl $0xe, %edx
movq %rax, %rdi
callq 0x74b0
movq %rbx, %rdi
callq 0x71b0
jmp 0x9fde
movq 0x4e050(%rip), %rdi     # 0x57fe8
leaq 0x375e1(%rip), %rsi     # 0x41580
movl $0x1f, %edx
callq 0x74b0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x4e02e(%rip), %rdi     # 0x57fe8
callq 0x74b0
movq %rax, %rbx
leaq 0x375a8(%rip), %rsi     # 0x41571
movl $0xe, %edx
movq %rax, %rdi
callq 0x74b0
movq %rbx, %rdi
callq 0x71b0
movl $0x1, %edi
callq 0x7510
leaq 0x375b1(%rip), %rdi     # 0x415a0
leaq 0x375c3(%rip), %rsi     # 0x415b9
leaq 0x375cd(%rip), %rcx     # 0x415ca
movl $0xee, %edx
callq 0x7290
jmp 0xa06e
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xa071
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xa071
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xa055
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xa055
jmp 0xa052
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xd1ac
jmp 0xa088
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa088
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0xa083
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa088
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq %rbx, %rdi
callq 0x7740