// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]Dsuite/Dsuite_utils.cpp
// Function: GeneralSetCountsWithSplits::getAFsFromADtagWithSplits(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 GeneralSetCountsWithSplits::getAFsFromADtagWithSplits(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];
            setPoolAAFsplit1.at(it->first) = individualPoolAAFs[pos];
            setPoolAAFsplit2.at(it->first) = individualPoolAAFs[pos];
        } else {
            std::vector<double> thisSetAFs;
            for (int i = 0; i < individualsInThisSet; i++) {
                int pos = (int) it->second[i];
                thisSetAFs.push_back(individualPoolAAFs[pos]);
            }
            setPoolAAFs.at(it->first) = vector_average(thisSetAFs);
            
            // Take care of the splits by random sampling with replacement:
            std::random_device rd;     // only used once to initialise (seed) engine
            std::mt19937 rng(rd());    // random-number engine used (Mersenne-Twister in this case)
            std::uniform_int_distribution<int> uni(0,(individualsInThisSet - 1)); // guaranteed unbiased
            
            std::vector<double> thisSetAFsplit1; std::vector<double> thisSetAFsplit2;
            for (int i = 0; i < individualsInThisSet; i++) {
                int random_pos_s1 = uni(rng);
                int random_pos_s2 = uni(rng);
                thisSetAFsplit1.push_back(individualPoolAAFs[random_pos_s1]);
                thisSetAFsplit2.push_back(individualPoolAAFs[random_pos_s2]);
            }
            setPoolAAFsplit1.at(it->first) = vector_average(thisSetAFsplit1);
            setPoolAAFsplit2.at(it->first) = vector_average(thisSetAFsplit2);
            
        }
        
        if (AAint == AncestralAlleleRef) {
            setPoolDAFs.at(it->first) = setPoolAAFs.at(it->first);
            setPoolDAFsplit1.at(it->first) = setPoolAAFsplit1.at(it->first);
            setPoolDAFsplit2.at(it->first) = setPoolAAFsplit2.at(it->first);
        } else if (AAint == AncestralAlleleAlt && setPoolAAFs.at(it->first) != -1.0) {
            setPoolDAFs.at(it->first) = (1 - setPoolAAFs.at(it->first));
            setPoolDAFsplit1.at(it->first) = (1 - setPoolAAFsplit1.at(it->first));
            setPoolDAFsplit2.at(it->first) = (1 - setPoolAAFsplit2.at(it->first));
        }
            
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2818, %rsp           # imm = 0x2818
movl %r8d, 0x20(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %r15
movq %rdi, 0x40(%rsp)
movslq %ecx, %r14
xorl %ebx, %ebx
leaq 0x108(%rsp), %r12
shlq $0x5, %r14
leaq 0x1490(%rsp), %r13
xorl %ebp, %ebp
movq (%r15), %rsi
movq 0x8(%r15), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %rbp
jae 0x95a4
addq %rbx, %rsi
movq %r12, %rdi
pushq $0x3a
popq %rdx
callq 0x88f1
movq 0x108(%rsp), %rsi
addq %r14, %rsi
movq %r13, %rdi
callq 0x7590
movq %r12, %rdi
callq 0xb80c
movq %r13, %rdi
leaq 0x2d00e(%rip), %rsi     # 0x3652e
callq 0x813d
testb %al, %al
jne 0x9a6c
movq %r12, %rdi
movq %r13, %rsi
pushq $0x2c
popq %rdx
callq 0x90aa
movq 0x108(%rsp), %rax
movq 0x110(%rsp), %rcx
subq %rax, %rcx
cmpq $0x10, %rcx
jne 0x9aa8
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl 0x20(%rsp), %eax
jl 0x9588
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq 0x40(%rsp), %rax
movq 0x128(%rax), %rax
movsd %xmm0, (%rax,%rbp,8)
movq %r12, %rdi
callq 0xc17e
movq %r13, %rdi
callq 0x7898
incq %rbp
addq $0x20, %rbx
jmp 0x94d6
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x8, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rdx
leaq 0x140(%rdx), %rax
movq %rax, 0x18(%rsp)
leaq 0x5e8(%rdx), %rax
movq %rax, 0x30(%rsp)
leaq 0x648(%rdx), %rax
movq %rax, 0x28(%rsp)
leaq 0x170(%rdx), %rax
movq %rax, 0x50(%rsp)
leaq 0x618(%rdx), %rax
movq %rax, 0x48(%rsp)
movq %rdx, %r14
leaq 0x678(%rdx), %rax
movq %rax, 0xb8(%rsp)
leaq 0x58(%rsp), %rbp
cmpq 0x38(%rsp), %rcx
je 0x9a5a
movq 0x40(%rcx), %rax
movq 0x48(%rcx), %rbx
subq %rax, %rbx
shrq $0x3, %rbx
testl %ebx, %ebx
jle 0x9aea
movq %rcx, 0x20(%rsp)
leaq 0x20(%rcx), %r12
cmpl $0x1, %ebx
movq %r12, 0x10(%rsp)
jne 0x96cd
movslq (%rax), %rbx
movq %r14, %r15
movq 0x128(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x128(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x128(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x98e9
movq %rbp, %r13
andq $0x0, 0xb0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xa0(%rsp)
movl %ebx, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0x9721
movq 0x20(%rsp), %rax
movq 0x40(%rax), %rax
movslq (%rax,%rbp,8), %rsi
shlq $0x3, %rsi
addq 0x128(%r14), %rsi
leaq 0xa0(%rsp), %rdi
callq 0xb9de
incq %rbp
jmp 0x96f2
leaq 0xf0(%rsp), %r15
movq %r15, %rdi
leaq 0xa0(%rsp), %rsi
callq 0xba2e
movq %r15, %rdi
callq 0xba00
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xb998
movq %r13, %rbp
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
callq 0xc17e
leaq 0x1490(%rsp), %r15
movq %r15, %rdi
callq 0xba7c
movq %r15, %rdi
callq 0x75a0
movl %eax, %esi
leaq 0x108(%rsp), %rdi
callq 0xd712
leal -0x1(%rbx), %eax
andl $0x0, 0x58(%rsp)
movl %eax, 0x5c(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x80(%rsp)
andq $0x0, 0x90(%rsp)
movapd %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
subl $0x1, %ebx
jb 0x9820
movq %rbp, %rdi
leaq 0x108(%rsp), %r12
movq %r12, %rsi
callq 0xbad2
movl %eax, %r15d
movq %rbp, %rdi
movq %r12, %rsi
callq 0xbad2
movl %eax, %ebp
movslq %r15d, %rsi
shlq $0x3, %rsi
addq 0x128(%r14), %rsi
leaq 0x80(%rsp), %rdi
callq 0xb9de
movslq %ebp, %rsi
shlq $0x3, %rsi
addq 0x128(%r14), %rsi
leaq 0x60(%rsp), %rdi
callq 0xb9de
movq %r13, %rbp
jmp 0x97c0
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
callq 0xba2e
movq %rbx, %rdi
callq 0xba00
movsd %xmm0, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, %rdi
callq 0xc17e
leaq 0xc0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xba2e
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
callq 0xba00
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, %rdi
callq 0xc17e
leaq 0x60(%rsp), %rdi
callq 0xc17e
leaq 0x80(%rsp), %rdi
callq 0xc17e
leaq 0x1490(%rsp), %rdi
callq 0xbada
leaq 0xa0(%rsp), %rdi
callq 0xc17e
movq %r14, %r15
movq 0x10(%rsp), %r12
movl 0x4(%r15), %eax
cmpl $0x1, %eax
je 0x997a
testl %eax, %eax
movq 0x20(%rsp), %rbx
jne 0x9a4a
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0xb998
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd (%rax), %xmm0
jmp 0x9a2a
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xb998
movsd (%rax), %xmm0
ucomisd 0x2cafd(%rip), %xmm0    # 0x36490
movq 0x20(%rsp), %rbx
jne 0x99a0
jnp 0x9a4a
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0xb998
movsd 0x2cab6(%rip), %xmm0    # 0x36470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd 0x2ca80(%rip), %xmm0    # 0x36470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd 0x2ca4a(%rip), %xmm0    # 0x36470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0xb998
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, %rdi
callq 0x74b0
movq %rax, %rcx
jmp 0x960e
addq $0x2818, %rsp           # imm = 0x2818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x47575(%rip), %rdi     # 0x50fe8
leaq 0x2ca7f(%rip), %rsi     # 0x364f9
callq 0x7400
leaq 0x1490(%rsp), %rsi
movq %rax, %rdi
callq 0x73c0
leaq 0x2ca8b(%rip), %rsi     # 0x36521
movq %rax, %rdi
callq 0x7400
movq %rax, %rdi
callq 0x71e0
jmp 0x9ae2
movq 0x47539(%rip), %rdi     # 0x50fe8
leaq 0x2ca7a(%rip), %rsi     # 0x36530
callq 0x7400
leaq 0x1490(%rsp), %rsi
movq %rax, %rdi
callq 0x73c0
leaq 0x2ca4f(%rip), %rsi     # 0x36521
movq %rax, %rdi
callq 0x7400
movq %rax, %rdi
callq 0x71e0
pushq $0x1
popq %rdi
callq 0x74f0
leaq 0x2ca5f(%rip), %rdi     # 0x36550
leaq 0x2ca71(%rip), %rsi     # 0x36569
leaq 0x2cb09(%rip), %rcx     # 0x36608
movl $0x123, %edx            # imm = 0x123
callq 0x72b0
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
jmp 0x9b21
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0xc17e
jmp 0x9b87
jmp 0x9b7f
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0xc17e
jmp 0x9bab
jmp 0x9b7f
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0xc17e
jmp 0x9b6e
jmp 0x9b6b
jmp 0x9b84
movq %rax, %rbx
jmp 0x9b9e
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0xb80c
jmp 0x9bb8
movq %rax, %rbx
leaq 0x1490(%rsp), %rdi
callq 0x7898
jmp 0x9bb8
jmp 0x9b84
movq %rax, %rbx
jmp 0x9bab
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xc17e
leaq 0x80(%rsp), %rdi
callq 0xc17e
leaq 0x1490(%rsp), %rdi
callq 0xbada
leaq 0xa0(%rsp), %rdi
callq 0xc17e
movq %rbx, %rdi
callq 0x7750