// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %rax
movq %rdi, %r14
movq (%rsi), %rsi
movq %rax, 0x18(%rsp)
cmpq %rsi, 0x8(%rax)
je 0xa1f8
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 0x91a9
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 0xdfb6
movq %r13, %rdi
callq 0xd250
movq %r15, %rdi
leaq 0x363fd(%rip), %rsi     # 0x4052e
callq 0x70f0
testl %eax, %eax
je 0xa8e8
movq %r15, %rsi
movq %r13, %r15
movq %r13, %rdi
movl $0x2c, %edx
callq 0x9b73
movq 0x1490(%rsp), %rdi
movq 0x1498(%rsp), %rax
subq %rdi, %rax
cmpq $0x10, %rax
jne 0xa93d
movsd (%rdi), %xmm0
movsd 0x8(%rdi), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cmpl 0x8(%rsp), %eax
jl 0xa19d
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 0xa1d2
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x7420
incq %r12
movq 0x18(%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 0xa0db
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x8, %rax
movq %rax, 0x38(%rsp)
cmpq %rax, %rcx
je 0xa8d6
leaq 0x140(%r14), %rax
movq %rax, 0x20(%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), %r15
leaq 0xb0(%rsp), %rbp
movq 0x40(%rcx), %rax
movq 0x48(%rcx), %rbx
subq %rax, %rbx
shrq $0x3, %rbx
testl %ebx, %ebx
jle 0xa99a
movq %rcx, 0x8(%rsp)
leaq 0x20(%rcx), %r12
cmpl $0x1, %ebx
movq %r12, 0x18(%rsp)
jne 0xa32a
movslq (%rax), %rbx
movq 0x128(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x128(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x128(%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x8(%rsp), %rbx
jmp 0xa75b
xorpd %xmm0, %xmm0
movapd %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movl %ebx, %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
movslq (%rax,%r13,8), %rdx
shlq $0x3, %rdx
addq 0x128(%r14), %rdx
movq 0x88(%rsp), %rsi
cmpq 0x90(%rsp), %rsi
je 0xa390
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x88(%rsp)
jmp 0xa39d
leaq 0x80(%rsp), %rdi
callq 0xf2ce
incq %r13
cmpq %r13, %r12
jne 0xa350
leaq 0xe8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xd4a2
movq 0xe8(%rsp), %rax
movq 0xf0(%rsp), %rcx
movq %rcx, %r12
subq %rax, %r12
sarq $0x3, %r12
cmpq %rax, %rcx
leaq 0x108(%rsp), %r13
je 0xa401
cmpq $0x1, %r12
movq %r12, %rcx
adcq $0x0, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
addsd (%rax,%rdx,8), %xmm0
incq %rdx
cmpq %rdx, %rcx
jne 0xa3f2
jmp 0xa405
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xd44e
movq %r12, %xmm0
punpckldq 0x360a9(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x360b1(%rip), %xmm0    # 0x404e0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0xa466
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq %r13, %rdi
callq 0xd522
movq %r13, %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 0xa485
movq $0x270, 0x2810(%rsp) # imm = 0x270
leal -0x1(%rbx), %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)
cmpl $0x2, %ebx
movl $0x1, %r13d
cmovgel %ebx, %r13d
movq %rbp, %rdi
movq %r15, %rbx
movq %r15, %rsi
movq %rbp, %rdx
callq 0xf3ae
movl %eax, %r12d
movq %rbp, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0xf3ae
movl %eax, %ebx
movslq %r12d, %rdx
shlq $0x3, %rdx
addq 0x128(%r14), %rdx
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0xa545
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0xa54f
leaq 0x60(%rsp), %rdi
callq 0xf2ce
movslq %ebx, %rdx
shlq $0x3, %rdx
addq 0x128(%r14), %rdx
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0xa57c
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0xa586
leaq 0x40(%rsp), %rdi
callq 0xf2ce
decl %r13d
jne 0xa4f4
leaq 0xd0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xd4a2
leaq 0x108(%rsp), %r12
movq 0xd0(%rsp), %rax
movq 0xd8(%rsp), %rcx
movq %rcx, %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %rax, %rcx
je 0xa5e8
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 0xa5d9
jmp 0xa5ec
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xd44e
movq %rbx, %xmm0
punpckldq 0x35ec2(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x35eca(%rip), %xmm0    # 0x404e0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0xa64d
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
leaq 0xb8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xd4a2
movq 0xb8(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq %rcx, %rbx
subq %rax, %rbx
sarq $0x3, %rbx
cmpq %rax, %rcx
je 0xa69e
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 0xa68f
jmp 0xa6a2
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xd44e
movq %rbx, %xmm0
punpckldq 0x35e0c(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x35e14(%rip), %xmm0    # 0x404e0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xa703
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %rbx
je 0xa71f
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xa736
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq %r12, %rdi
callq 0x73d0
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xa75b
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movl 0x4(%r14), %eax
cmpl $0x1, %eax
je 0xa7ed
testl %eax, %eax
jne 0xa8c0
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
callq 0xd44e
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xa0(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd (%rax), %xmm0
jmp 0xa8a0
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xd44e
movsd (%rax), %xmm0
ucomisd 0x35c88(%rip), %xmm0    # 0x40490
jne 0xa810
jnp 0xa8c0
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
callq 0xd44e
movsd 0x35c46(%rip), %xmm0    # 0x40470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x35c0d(%rip), %xmm0    # 0x40470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xa0(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x35bd4(%rip), %xmm0    # 0x40470
subsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x100(%rsp), %rdi
movq %r12, %rsi
callq 0xd44e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, %rdi
callq 0x74d0
movq %rax, %rcx
cmpq 0x38(%rsp), %rax
jne 0xa274
addq $0x2818, %rsp           # imm = 0x2818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4c6f9(%rip), %rdi     # 0x56fe8
leaq 0x35c03(%rip), %rsi     # 0x404f9
movl $0x27, %edx
callq 0x74b0
movq 0x108(%rsp), %rsi
movq 0x110(%rsp), %rdx
movq 0x4c6d1(%rip), %rdi     # 0x56fe8
callq 0x74b0
movq %rax, %rbx
leaq 0x35bfb(%rip), %rsi     # 0x40521
movl $0xe, %edx
movq %rax, %rdi
callq 0x74b0
movq %rbx, %rdi
callq 0x71b0
jmp 0xa990
movq 0x4c6a4(%rip), %rdi     # 0x56fe8
leaq 0x35be5(%rip), %rsi     # 0x40530
movl $0x1f, %edx
callq 0x74b0
movq 0x108(%rsp), %rsi
movq 0x110(%rsp), %rdx
movq 0x4c67c(%rip), %rdi     # 0x56fe8
callq 0x74b0
movq %rax, %rbx
leaq 0x35ba6(%rip), %rsi     # 0x40521
movl $0xe, %edx
movq %rax, %rdi
callq 0x74b0
movq %rbx, %rdi
callq 0x71b0
movl $0x1, %edi
callq 0x7510
leaq 0x35baf(%rip), %rdi     # 0x40550
leaq 0x35bc1(%rip), %rsi     # 0x40569
leaq 0x35c59(%rip), %rcx     # 0x40608
movl $0x123, %edx            # imm = 0x123
callq 0x7290
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0xaaaa
movq 0xe0(%rsp), %rsi
jmp 0xa9f8
jmp 0xab0a
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xaaaa
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xaaaa
jmp 0xaaa0
jmp 0xaaa0
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0xaae5
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xaae5
movq %rax, %rbx
jmp 0xaad8
movq %rax, %rbx
movq 0x1490(%rsp), %rdi
testq %rdi, %rdi
je 0xaa7e
movq 0x14a0(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
jmp 0xaa7e
jmp 0xaa7b
jmp 0xaaa7
movq %rax, %rbx
leaq 0x1490(%rsp), %rdi
callq 0xd250
jmp 0xab02
movq %rax, %rbx
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0xab02
movq 0x118(%rsp), %rsi
incq %rsi
jmp 0xaafd
movq %rax, %rbx
jmp 0xaae5
jmp 0xaaa7
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xaac1
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xaad8
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
leaq 0x108(%rsp), %rdi
callq 0x73d0
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xab02
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x7420
movq %rbx, %rdi
callq 0x7740
movq %rax, %rdi
callq 0xd650