// File: /workspace/github_cpp_makefile_star2_O3/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, %rax
movq %rdi, %r14
movq (%rsi), %rsi
movq %rax, 0x10(%rsp)
cmpq %rsi, 0x8(%rax)
je 0xa1f4
movslq %ecx, %rbp
xorl %ebx, %ebx
leaq 0x1490(%rsp), %r13
shlq $0x5, %rbp
xorl %r12d, %r12d
addq %rbx, %rsi
movq %r13, %rdi
movl $0x3a, %edx
callq 0x91c1
movq 0x1490(%rsp), %rax
leaq 0x118(%rsp), %rcx
movq %rcx, 0x108(%rsp)
movq (%rax,%rbp), %rsi
movq 0x8(%rax,%rbp), %rdx
addq %rsi, %rdx
leaq 0x108(%rsp), %r15
movq %r15, %rdi
callq 0xdf1c
movq %r13, %rdi
callq 0xd1ac
movq %r15, %rdi
leaq 0x37451(%rip), %rsi     # 0x4157e
callq 0x70f0
testl %eax, %eax
je 0xa894
movq %r15, %rsi
movq %r13, %r15
movq %r13, %rdi
movl $0x2c, %edx
callq 0x9b89
movq 0x1490(%rsp), %rdi
movq 0x1498(%rsp), %rax
subq %rdi, %rax
cmpq $0x10, %rax
jne 0xa8e9
movsd (%rdi), %xmm0
movsd 0x8(%rdi), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl 0x20(%rsp), %eax
jl 0xa199
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq 0x128(%r14), %rax
movsd %xmm0, (%rax,%r12,8)
movq 0x14a0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0xa1ce
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x7420
incq %r12
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %rbx
cmpq %rax, %r12
movq %r15, %r13
jb 0xa0d7
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x8, %rax
movq %rax, 0x38(%rsp)
cmpq %rax, %rcx
je 0xa882
leaq 0x140(%r14), %rax
movq %rax, 0x18(%rsp)
leaq 0x5e8(%r14), %rax
movq %rax, 0x30(%rsp)
leaq 0x648(%r14), %rax
movq %rax, 0x28(%rsp)
leaq 0x170(%r14), %rax
movq %rax, 0xa8(%rsp)
leaq 0x618(%r14), %rax
movq %rax, 0xa0(%rsp)
leaq 0x678(%r14), %rax
movq %rax, 0x100(%rsp)
leaq 0x1490(%rsp), %r12
leaq 0xb0(%rsp), %rbp
movq 0x40(%rcx), %rax
movq 0x48(%rcx), %r13
subq %rax, %r13
shrq $0x3, %r13
testl %r13d, %r13d
jle 0xa946
movq %rcx, 0x20(%rsp)
leaq 0x20(%rcx), %r15
cmpl $0x1, %r13d
movq %r15, 0x10(%rsp)
jne 0xa323
movslq (%rax), %rbx
movq 0x128(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
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 %r15, %rsi
callq 0xd3b4
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 %r15, %rsi
callq 0xd3b4
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0xa6ff
movq %r12, %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movl %r13d, %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
xorl %r12d, %r12d
movq 0x20(%rsp), %rax
movq 0x40(%rax), %rax
movslq (%rax,%r12,8), %rdx
shlq $0x3, %rdx
addq 0x128(%r14), %rdx
movq 0x88(%rsp), %rsi
cmpq 0x90(%rsp), %rsi
je 0xa38b
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x88(%rsp)
jmp 0xa398
leaq 0x80(%rsp), %rdi
callq 0xf47e
incq %r12
cmpq %r12, %rbx
jne 0xa34b
leaq 0xe8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xd408
movq 0xe8(%rsp), %rax
movq 0xf0(%rsp), %rcx
movq %rcx, %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %rax, %rcx
movq %r15, %r12
je 0xa3f7
cmpq $0x1, %rbx
movq %rbx, %rcx
adcq $0x0, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
addsd (%rax,%rdx,8), %xmm0
incq %rdx
cmpq %rdx, %rcx
jne 0xa3e8
jmp 0xa3fb
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xd3b4
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0xa443
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
leaq 0x108(%rsp), %rbx
movq %rbx, %rdi
callq 0xd488
movq %rbx, %rdi
callq 0x75a0
movl %eax, %eax
movq %rax, 0x1490(%rsp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, 0x1490(%rsp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0xa46a
movq $0x270, 0x2810(%rsp) # imm = 0x270
leal -0x1(%r13), %eax
movl $0x0, 0xb0(%rsp)
movl %eax, 0xb4(%rsp)
xorl %eax, %eax
movq %rax, 0x70(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movq %rax, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0xf55e
movq %r12, %rsi
movl %eax, %r12d
movq %rbp, %rdi
movq %rbp, %rdx
callq 0xf55e
movl %eax, %ebx
movslq %r12d, %rcx
movq 0x128(%r14), %rax
leaq (%rax,%rcx,8), %rdx
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0xa51b
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0xa52c
leaq 0x60(%rsp), %rdi
callq 0xf47e
movq 0x128(%r14), %rax
movslq %ebx, %rcx
leaq (%rax,%rcx,8), %rdx
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0xa552
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0xa55c
leaq 0x40(%rsp), %rdi
callq 0xf47e
decl %r13d
movq %r15, %r12
jne 0xa4cd
leaq 0xd0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xd408
movq 0xd0(%rsp), %rax
movq 0xd8(%rsp), %rcx
movq %rcx, %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %rax, %rcx
je 0xa5b9
cmpq $0x1, %rbx
movq %rbx, %rcx
adcq $0x0, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
addsd (%rax,%rdx,8), %xmm0
incq %rdx
cmpq %rdx, %rcx
jne 0xa5aa
jmp 0xa5bd
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xd3b4
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0xa605
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
leaq 0xb8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xd408
movq 0xb8(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq %rcx, %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %rax, %rcx
je 0xa656
cmpq $0x1, %rbx
movq %rbx, %rcx
adcq $0x0, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
addsd (%rax,%rdx,8), %xmm0
incq %rdx
cmpq %rdx, %rcx
jne 0xa647
jmp 0xa65a
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xd3b4
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xa6a2
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %r15
je 0xa6be
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xa6d5
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
leaq 0x108(%rsp), %rdi
callq 0x73d0
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xa6ff
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movl 0x4(%r14), %eax
cmpl $0x1, %eax
je 0xa796
testl %eax, %eax
movq 0x20(%rsp), %rbx
jne 0xa86c
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0xd3b4
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xa8(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd (%rax), %xmm0
jmp 0xa84c
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd (%rax), %xmm0
ucomisd 0x36ce1(%rip), %xmm0    # 0x41490
movq 0x20(%rsp), %rbx
jne 0xa7bc
jnp 0xa86c
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0xd3b4
movsd 0x36c9a(%rip), %xmm0    # 0x41470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xa8(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd 0x36c61(%rip), %xmm0    # 0x41470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd 0x36c28(%rip), %xmm0    # 0x41470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x100(%rsp), %rdi
movq %r15, %rsi
callq 0xd3b4
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, %rdi
callq 0x74d0
movq %rax, %rcx
cmpq 0x38(%rsp), %rax
jne 0xa270
addq $0x2818, %rsp           # imm = 0x2818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4d74d(%rip), %rdi     # 0x57fe8
leaq 0x36ca7(%rip), %rsi     # 0x41549
movl $0x27, %edx
callq 0x74b0
movq 0x108(%rsp), %rsi
movq 0x110(%rsp), %rdx
movq 0x4d725(%rip), %rdi     # 0x57fe8
callq 0x74b0
movq %rax, %rbx
leaq 0x36c9f(%rip), %rsi     # 0x41571
movl $0xe, %edx
movq %rax, %rdi
callq 0x74b0
movq %rbx, %rdi
callq 0x71b0
jmp 0xa93c
movq 0x4d6f8(%rip), %rdi     # 0x57fe8
leaq 0x36c89(%rip), %rsi     # 0x41580
movl $0x1f, %edx
callq 0x74b0
movq 0x108(%rsp), %rsi
movq 0x110(%rsp), %rdx
movq 0x4d6d0(%rip), %rdi     # 0x57fe8
callq 0x74b0
movq %rax, %rbx
leaq 0x36c4a(%rip), %rsi     # 0x41571
movl $0xe, %edx
movq %rax, %rdi
callq 0x74b0
movq %rbx, %rdi
callq 0x71b0
movl $0x1, %edi
callq 0x7510
leaq 0x36c53(%rip), %rdi     # 0x415a0
leaq 0x36c65(%rip), %rsi     # 0x415b9
leaq 0x36cfd(%rip), %rcx     # 0x41658
movl $0x123, %edx            # imm = 0x123
callq 0x7290
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0xaa56
movq 0xe0(%rsp), %rsi
jmp 0xa9a4
jmp 0xaab6
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xaa56
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xaa56
jmp 0xaa4c
jmp 0xaa4c
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0xaa91
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xaa91
movq %rax, %rbx
jmp 0xaa84
movq %rax, %rbx
movq 0x1490(%rsp), %rdi
testq %rdi, %rdi
je 0xaa2a
movq 0x14a0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xaa2a
jmp 0xaa27
jmp 0xaa53
movq %rax, %rbx
leaq 0x1490(%rsp), %rdi
callq 0xd1ac
jmp 0xaaae
movq %rax, %rbx
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0xaaae
movq 0x118(%rsp), %rsi
incq %rsi
jmp 0xaaa9
movq %rax, %rbx
jmp 0xaa91
jmp 0xaa53
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xaa6d
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xaa84
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
leaq 0x108(%rsp), %rdi
callq 0x73d0
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xaaae
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq %rbx, %rdi
callq 0x7740
movq %rax, %rdi
callq 0xd5b6