// File: /workspace/github_cpp_makefile_star2_O2/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, (%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movslq %ecx, %rax
xorl %ebx, %ebx
leaq 0x48(%rsp), %r12
shlq $0x5, %rax
movq %rax, 0x10(%rsp)
leaq 0x20(%rsp), %r13
xorl %ebp, %ebp
movq (%r15), %rsi
movq 0x8(%r15), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %rbp
jae 0x91e0
addq %rbx, %rsi
movq %r12, %rdi
pushq $0x3a
popq %rdx
callq 0x88f1
movq 0x48(%rsp), %rsi
addq 0x10(%rsp), %rsi
movq %r13, %rdi
callq 0x7590
movq %r12, %rdi
callq 0xb80c
movq %r13, %rdi
leaq 0x2d3c6(%rip), %rsi     # 0x3652e
callq 0x813d
testb %al, %al
jne 0x93ab
movq %r12, %rdi
movq %r13, %rsi
pushq $0x2c
popq %rdx
callq 0x90aa
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
subq %rax, %rcx
cmpq $0x10, %rcx
jne 0x93e4
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl (%rsp), %eax
jl 0x91c4
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq 0x128(%r14), %rax
movsd %xmm0, (%rax,%rbp,8)
movq %r12, %rdi
callq 0xc17e
movq %r13, %rdi
callq 0x7898
incq %rbp
addq $0x20, %rbx
jmp 0x911f
movq 0x18(%rsp), %r15
movq 0x18(%r15), %r12
addq $0x8, %r15
leaq 0x140(%r14), %rax
movq %rax, (%rsp)
leaq 0x170(%r14), %rax
movq %rax, 0x40(%rsp)
leaq 0x60(%rsp), %rbp
leaq 0x20(%rsp), %r13
movq %r15, 0x18(%rsp)
cmpq %r15, %r12
je 0x939c
movq %rbp, %rbx
movq 0x40(%r12), %rax
movq 0x48(%r12), %rbp
subq %rax, %rbp
shrq $0x3, %rbp
testl %ebp, %ebp
jle 0x9423
leaq 0x20(%r12), %rsi
cmpl $0x1, %ebp
movq %rsi, 0x10(%rsp)
jne 0x9277
movslq (%rax), %rax
movq 0x128(%r14), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%rsp), %rdi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, %rbp
jmp 0x9310
andq $0x0, 0x30(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0x92c7
movq 0x40(%r12), %rax
movslq (%rax,%r15,8), %rax
movq 0x128(%r14), %rcx
movsd (%rcx,%rax,8), %xmm0
ucomisd 0x2d1de(%rip), %xmm0    # 0x36490
jne 0x92b6
jnp 0x92c2
leaq (%rcx,%rax,8), %rsi
movq %r13, %rdi
callq 0xb9de
incq %r15
jmp 0x9290
movq %rbx, %rbp
movq %rbx, %rdi
movq %r13, %rsi
callq 0xba2e
movq %rbp, %rdi
callq 0xba00
movsd %xmm0, 0x8(%rsp)
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xb998
movq 0x18(%rsp), %r15
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbp, %rdi
callq 0xc17e
movq %r13, %rdi
callq 0xc17e
movl 0x4(%r14), %eax
cmpl $0x1, %eax
je 0x9334
testl %eax, %eax
jne 0x938c
movq (%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0xb998
movsd (%rax), %xmm0
jmp 0x936f
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xb998
movsd (%rax), %xmm0
ucomisd 0x2d142(%rip), %xmm0    # 0x36490
jne 0x9352
jnp 0x938c
movq (%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0xb998
movsd 0x2d105(%rip), %xmm0    # 0x36470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r12, %rdi
callq 0x74b0
movq %rax, %r12
jmp 0x9213
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x47c36(%rip), %rdi     # 0x50fe8
leaq 0x2d140(%rip), %rsi     # 0x364f9
callq 0x7400
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x73c0
leaq 0x2d14f(%rip), %rsi     # 0x36521
movq %rax, %rdi
callq 0x7400
movq %rax, %rdi
callq 0x71e0
jmp 0x941b
movq 0x47bfd(%rip), %rdi     # 0x50fe8
leaq 0x2d13e(%rip), %rsi     # 0x36530
callq 0x7400
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x73c0
leaq 0x2d116(%rip), %rsi     # 0x36521
movq %rax, %rdi
callq 0x7400
movq %rax, %rdi
callq 0x71e0
pushq $0x1
popq %rdi
callq 0x74f0
leaq 0x2d126(%rip), %rdi     # 0x36550
leaq 0x2d138(%rip), %rsi     # 0x36569
leaq 0x2d142(%rip), %rcx     # 0x3657a
movl $0xee, %edx
callq 0x72b0
jmp 0x9482
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xc17e
jmp 0x9485
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xc17e
jmp 0x9476
jmp 0x9473
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xb80c
jmp 0x948f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x7898
jmp 0x948f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xc17e
movq %rbx, %rdi
callq 0x7750
nop