// File: /workspace/github_cpp_makefile_star2_O1/millanek[P]evo/process_vcf_utils.cpp
// Function: getThreeSetVariantCountsAA4(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::vector<unsigned long, std::allocator<unsigned long>> const&, std::vector<unsigned long, std::allocator<unsigned long>> const&, std::vector<unsigned long, std::allocator<unsigned long>> const&, std::vector<unsigned long, std::allocator<unsigned long>> const&)
ThreeSetCounts getThreeSetVariantCountsAA4(const std::vector<std::string>& fields, const std::vector<size_t>& set1_loci, const std::vector<size_t>& set2_loci, const std::vector<size_t>& set3_loci, const std::vector<size_t>& AA_loci) {
    ThreeSetCounts thisVariantCounts;
    int AAaltCount = 0;
    thisVariantCounts.individualsWithVariant.assign((fields.size()-NUM_NON_GENOTYPE_COLUMNS),0);
    // std::cerr << fields[0] << "\t" << fields[1] << std::endl;
    for (std::vector<std::string>::size_type i = NUM_NON_GENOTYPE_COLUMNS; i != fields.size(); i++) {
        if (fields[i][0] == '1') {
            thisVariantCounts.overall++;
            if (std::find(set1_loci.begin(), set1_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != set1_loci.end()) { thisVariantCounts.set1AltCount++; }
            if (std::find(set2_loci.begin(), set2_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != set2_loci.end()) { thisVariantCounts.set2AltCount++; }
            if (std::find(set3_loci.begin(), set3_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != set3_loci.end()) { thisVariantCounts.set3AltCount++; }
            if (std::find(AA_loci.begin(), AA_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != AA_loci.end()) { AAaltCount++; }
            thisVariantCounts.individualsWithVariant[i- NUM_NON_GENOTYPE_COLUMNS]++;
        }
        if (fields[i][2] == '1') {
            thisVariantCounts.overall++;
            if (std::find(set1_loci.begin(), set1_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != set1_loci.end()) { thisVariantCounts.set1AltCount++; }
            if (std::find(set2_loci.begin(), set2_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != set2_loci.end()) { thisVariantCounts.set2AltCount++; }
            if (std::find(set3_loci.begin(), set3_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != set3_loci.end()) { thisVariantCounts.set3AltCount++; }
            if (std::find(AA_loci.begin(), AA_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != AA_loci.end()) { AAaltCount++; }
            thisVariantCounts.individualsWithVariant[i-NUM_NON_GENOTYPE_COLUMNS]++;
        }
    }
    thisVariantCounts.set1RefCount = (int)(set1_loci.size() * 2) - thisVariantCounts.set1AltCount;
    thisVariantCounts.set2RefCount = (int)(set2_loci.size() * 2) - thisVariantCounts.set2AltCount;
    thisVariantCounts.set3RefCount = (int)(set3_loci.size() * 2) - thisVariantCounts.set3AltCount;
    //thisVariantCounts.set4RefCount = (int)(set4_loci.size() * 2) - thisVariantCounts.set4AltCount;
    
    thisVariantCounts.set1AltAF = (double)thisVariantCounts.set1AltCount/(set1_loci.size() * 2);
    thisVariantCounts.set2AltAF = (double)thisVariantCounts.set2AltCount/(set2_loci.size() * 2);
    thisVariantCounts.set3AltAF = (double)thisVariantCounts.set3AltCount/(set3_loci.size() * 2);
    //thisVariantCounts.set4AltAF = (double)thisVariantCounts.set4AltCount/(set4_loci.size() * 2);
    
    // Fill in derived allele frequencies if possible
    if (AAaltCount == 0) {
        thisVariantCounts.set1daAF = (double)thisVariantCounts.set1AltCount/(set1_loci.size() * 2);
        thisVariantCounts.set2daAF = (double)thisVariantCounts.set2AltCount/(set2_loci.size() * 2);
        thisVariantCounts.set3daAF = (double)thisVariantCounts.set3AltCount/(set3_loci.size() * 2);
       // thisVariantCounts.set4daAF = (double)thisVariantCounts.set4AltCount/(set4_loci.size() * 2);
    } else if (AAaltCount == 2) {
        thisVariantCounts.set1daAF = (double)thisVariantCounts.set1RefCount/(set1_loci.size() * 2);
        thisVariantCounts.set2daAF = (double)thisVariantCounts.set2RefCount/(set2_loci.size() * 2);
        thisVariantCounts.set3daAF = (double)thisVariantCounts.set3RefCount/(set3_loci.size() * 2);
        //thisVariantCounts.set4daAF = (double)thisVariantCounts.set4RefCount/(set4_loci.size() * 2);
    } else if (AAaltCount == 1) {
    } else {
        std::cerr << "Error: Outgroup can only be one individual here" << std::endl;
        exit(1);
    }
    
    return thisVariantCounts;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r13
movq %r8, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
xorl %ecx, %ecx
movl %ecx, (%rdi)
movb %cl, 0x4(%rdi)
movb %cl, 0x5(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rdi)
movq %rcx, 0x18(%rdi)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x20(%rdi)
movq %rax, 0x28(%rdi)
movq %rax, 0x30(%rdi)
movq %rax, 0x38(%rdi)
movq %rax, 0x40(%rdi)
movq %rax, 0x48(%rdi)
leaq 0x50(%rdi), %rdi
movq %rcx, 0xc0(%rbx)
movl %ecx, 0xc8(%rbx)
movupd %xmm0, 0x50(%rbx)
movupd %xmm0, 0x60(%rbx)
movupd %xmm0, 0x70(%rbx)
movupd %xmm0, 0x80(%rbx)
movupd %xmm0, 0x90(%rbx)
movupd %xmm0, 0xa0(%rbx)
movupd %xmm0, 0xac(%rbx)
movq %rcx, 0x140(%rbx)
movupd %xmm0, 0x130(%rbx)
movupd %xmm0, 0x120(%rbx)
movupd %xmm0, 0x110(%rbx)
movupd %xmm0, 0x100(%rbx)
movupd %xmm0, 0xf0(%rbx)
movupd %xmm0, 0xe0(%rbx)
movupd %xmm0, 0xd0(%rbx)
movq 0x8(%rsi), %rsi
subq (%rbp), %rsi
sarq $0x5, %rsi
addq $-0x9, %rsi
leaq 0x8(%rsp), %rdx
movq $0x0, 0x10(%rsp)
movl %ecx, (%rdx)
movq %rdi, 0x40(%rsp)
movq %rbx, 0x18(%rsp)
callq 0x561e6
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
cmpq $0x120, %rcx            # imm = 0x120
je 0x5289a
leaq 0x8(%rbx), %rcx
movq %rcx, 0x30(%rsp)
xorl %r15d, %r15d
movl $0x48, %r14d
movq $0x0, 0x10(%rsp)
movq %r13, 0x38(%rsp)
movq (%rax,%r14,4), %rax
cmpb $0x31, (%rax)
jne 0x527a9
incl (%rbx)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r12), %rax
movq 0x28(%rsp), %r13
je 0x52720
movq 0x30(%rsp), %rcx
incl (%rcx)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r13), %rax
movq 0x20(%rsp), %rax
je 0x52745
incl 0xc(%rbx)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
movq %rax, %rbx
callq 0x56e90
movq 0x38(%rsp), %r13
cmpq 0x8(%rbx), %rax
movq 0x18(%rsp), %rbx
je 0x52771
incl 0x10(%rbx)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
xorl %ecx, %ecx
cmpq 0x8(%r13), %rax
setne %cl
movq 0x10(%rsp), %rax
addl %ecx, %eax
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r15,4)
movq (%rbp), %rax
movq (%rax,%r14,4), %rax
cmpb $0x31, 0x2(%rax)
jne 0x52873
incl (%rbx)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r12), %rax
movq 0x28(%rsp), %rax
je 0x527e8
movq 0x30(%rsp), %rcx
incl (%rcx)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
movq %rax, %r13
callq 0x56e90
cmpq 0x8(%r13), %rax
movq 0x20(%rsp), %rax
je 0x5280f
incl 0xc(%rbx)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
movq %rax, %rbx
callq 0x56e90
movq 0x38(%rsp), %r13
cmpq 0x8(%rbx), %rax
movq 0x18(%rsp), %rbx
je 0x5283b
incl 0x10(%rbx)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
xorl %ecx, %ecx
cmpq 0x8(%r13), %rax
setne %cl
movq 0x10(%rsp), %rax
addl %ecx, %eax
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r15,4)
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
leaq 0x1(%r15), %rdx
addq $0xa, %r15
addq $0x8, %r14
cmpq %rcx, %r15
movq %rdx, %r15
jne 0x526e6
movq 0x8(%r12), %r9
subq (%r12), %r9
movq %r9, %rax
shrq $0x2, %rax
andl $-0x2, %eax
movl 0x8(%rbx), %r11d
movl 0xc(%rbx), %edi
subl %r11d, %eax
movl %eax, 0x14(%rbx)
movq 0x28(%rsp), %rcx
movq 0x8(%rcx), %r8
subq (%rcx), %r8
movq %r8, %rcx
shrq $0x2, %rcx
andl $-0x2, %ecx
subl %edi, %ecx
movl %ecx, 0x18(%rbx)
movq 0x20(%rsp), %rdx
movq 0x8(%rdx), %rsi
subq (%rdx), %rsi
movq %rsi, %rdx
shrq $0x2, %rdx
andl $-0x2, %edx
movl 0x10(%rbx), %r10d
subl %r10d, %edx
movl %edx, 0x1c(%rbx)
cvtsi2sd %r11d, %xmm1
sarq $0x2, %r9
movq %r9, %xmm2
movq 0x77895(%rip), %xmm4    # 0xca1a0
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
movapd 0x77899(%rip), %xmm6    # 0xca1b0
subpd %xmm6, %xmm2
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
addsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rbx)
cvtsi2sd %edi, %xmm3
sarq $0x2, %r8
movq %r8, %xmm5
punpckldq %xmm4, %xmm5    # xmm5 = xmm5[0],xmm4[0],xmm5[1],xmm4[1]
subpd %xmm6, %xmm5
movapd %xmm5, %xmm2
unpckhpd %xmm5, %xmm2            # xmm2 = xmm2[1],xmm5[1]
addsd %xmm5, %xmm2
divsd %xmm2, %xmm3
movsd %xmm3, 0x28(%rbx)
xorps %xmm5, %xmm5
cvtsi2sd %r10d, %xmm5
sarq $0x2, %rsi
movq %rsi, %xmm7
punpckldq %xmm4, %xmm7    # xmm7 = xmm7[0],xmm4[0],xmm7[1],xmm4[1]
subpd %xmm6, %xmm7
movapd %xmm7, %xmm4
unpckhpd %xmm7, %xmm4            # xmm4 = xmm4[1],xmm7[1]
addsd %xmm7, %xmm4
divsd %xmm4, %xmm5
movsd %xmm5, 0x30(%rbx)
movq 0x10(%rsp), %rsi
testl %esi, %esi
je 0x529c8
cmpl $0x1, %esi
je 0x529d7
cmpl $0x2, %esi
jne 0x529e9
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, 0x40(%rbx)
xorps %xmm5, %xmm5
cvtsi2sd %edx, %xmm5
divsd %xmm4, %xmm5
jmp 0x529d2
movsd %xmm1, 0x38(%rbx)
movsd %xmm3, 0x40(%rbx)
movsd %xmm5, 0x48(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb85f8(%rip), %rdi     # 0x10afe8
leaq 0x84632(%rip), %rsi     # 0xd7029
movl $0x2f, %edx
callq 0x84e0
movq 0xb85e0(%rip), %rdi     # 0x10afe8
callq 0x8200
movl $0x1, %edi
callq 0x8530
jmp 0x52a29
jmp 0x52a29
jmp 0x52a29
jmp 0x52a29
jmp 0x52a29
jmp 0x52a29
jmp 0x52a29
jmp 0x52a29
jmp 0x52a29
movq %rax, %r14
movq 0x18(%rsp), %rdi
callq 0x39a46
movq %r14, %rdi
callq 0x8840