// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %r9, %r13
movq %r8, %r12
movq %rcx, 0x10(%rsp)
movq %rdx, %r14
movq %rsi, %r15
xorl %eax, %eax
movl %eax, (%rdi)
movw $0x0, 0x4(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rdi)
movq %rax, 0x18(%rdi)
movdqa 0x7d23e(%rip), %xmm1    # 0xcc6d0
movdqu %xmm1, 0x20(%rdi)
movdqu %xmm1, 0x30(%rdi)
movdqu %xmm1, 0x40(%rdi)
leaq 0x50(%rdi), %rcx
movq %rax, 0xc0(%rdi)
movl %eax, 0xc8(%rdi)
movupd %xmm0, 0x50(%rdi)
movupd %xmm0, 0x60(%rdi)
movupd %xmm0, 0x70(%rdi)
movupd %xmm0, 0x80(%rdi)
movupd %xmm0, 0x90(%rdi)
movupd %xmm0, 0xa0(%rdi)
movupd %xmm0, 0xac(%rdi)
movupd %xmm0, 0xd0(%rdi)
movupd %xmm0, 0xe0(%rdi)
movupd %xmm0, 0xf0(%rdi)
movupd %xmm0, 0x100(%rdi)
movupd %xmm0, 0x110(%rdi)
movupd %xmm0, 0x120(%rdi)
movupd %xmm0, 0x130(%rdi)
movq %rdi, 0x8(%rsp)
movq %rax, 0x140(%rdi)
movq 0x8(%rsi), %rsi
subq (%r15), %rsi
sarq $0x5, %rsi
addq $-0x9, %rsi
movq %rsp, %rdx
movl %eax, (%rdx)
movq %rcx, 0x30(%rsp)
movq %rcx, %rdi
callq 0x56106
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
cmpq $0x120, %rcx            # imm = 0x120
movl $0x0, %edi
je 0x4f720
movq 0x8(%rsp), %rcx
addq $0x8, %rcx
movq %rcx, 0x18(%rsp)
xorl %ebx, %ebx
movl $0x48, %ebp
xorl %edi, %edi
movq %r14, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movq (%rax,%rbp,4), %rcx
cmpb $0x31, (%rcx)
jne 0x4f642
movq %rdi, %r15
movq 0x8(%rsp), %rax
incl (%rax)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %rbx, (%rsp)
movq %rsp, %rdx
callq 0x5706e
cmpq 0x8(%r14), %rax
movq 0x10(%rsp), %r14
je 0x4f5bf
movq 0x18(%rsp), %rcx
incl (%rcx)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %rbx, (%rsp)
movq %rsp, %rdx
callq 0x5706e
cmpq 0x8(%r14), %rax
je 0x4f5e0
movq 0x8(%rsp), %rax
incl 0xc(%rax)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %rbx, (%rsp)
movq %rsp, %rdx
callq 0x5706e
movq 0x28(%rsp), %r14
cmpq 0x8(%r12), %rax
je 0x4f609
movq 0x8(%rsp), %rax
incl 0x10(%rax)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %rbx, (%rsp)
movq %rsp, %rdx
callq 0x5706e
xorl %ecx, %ecx
cmpq 0x8(%r13), %rax
setne %cl
movq 0x30(%rsp), %rax
movq (%rax), %rax
incl (%rax,%rbx,4)
movq %r15, %rdi
addl %ecx, %edi
movq 0x20(%rsp), %r15
movq (%r15), %rax
movq (%rax,%rbp,4), %rcx
cmpb $0x31, 0x2(%rcx)
jne 0x4f6fd
movq %rdi, %r15
movq 0x8(%rsp), %rax
incl (%rax)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %rbx, (%rsp)
movq %rsp, %rdx
callq 0x5706e
cmpq 0x8(%r14), %rax
movq 0x10(%rsp), %rax
je 0x4f67b
movq 0x18(%rsp), %rcx
incl (%rcx)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
movq %rbx, (%rsp)
movq %rsp, %rdx
movq %rax, %r14
callq 0x5706e
cmpq 0x8(%r14), %rax
je 0x4f69f
movq 0x8(%rsp), %rax
incl 0xc(%rax)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %rbx, (%rsp)
movq %rsp, %rdx
callq 0x5706e
movq 0x28(%rsp), %r14
cmpq 0x8(%r12), %rax
je 0x4f6c8
movq 0x8(%rsp), %rax
incl 0x10(%rax)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %rbx, (%rsp)
movq %rsp, %rdx
callq 0x5706e
xorl %ecx, %ecx
cmpq 0x8(%r13), %rax
setne %cl
movq %r15, %rdi
addl %ecx, %edi
movq 0x30(%rsp), %rax
movq (%rax), %rax
incl (%rax,%rbx,4)
movq 0x20(%rsp), %r15
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
addq $0x8, %rbp
leaq 0x1(%rbx), %rdx
addq $0xa, %rbx
cmpq %rcx, %rbx
movq %rdx, %rbx
jne 0x4f583
movq 0x8(%r12), %rcx
subq (%r12), %rcx
movq %rcx, %rsi
shrq $0x2, %rsi
andl $-0x2, %esi
movq 0x8(%rsp), %rax
movl 0x10(%rax), %edx
subl %edx, %esi
movq 0x10(%rsp), %r8
movq 0x8(%r8), %xmm1
movq 0x8(%r14), %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq (%r8), %xmm1
movq (%r14), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
psubq %xmm2, %xmm0
movl %esi, 0x1c(%rax)
movdqa %xmm0, %xmm3
psrlq $0x2, %xmm3
pshufd $0xe8, %xmm3, %xmm1     # xmm1 = xmm3[0,2,2,3]
pand 0x809c3(%rip), %xmm1    # 0xd0140
movq 0x8(%rax), %xmm2
psubd %xmm2, %xmm1
cvtdq2pd %xmm2, %xmm2
pand 0x809be(%rip), %xmm3    # 0xd0150
por 0x809c6(%rip), %xmm3    # 0xd0160
psrad $0x2, %xmm0
psrlq $0x20, %xmm0
por 0x809c4(%rip), %xmm0    # 0xd0170
movq %xmm1, 0x14(%rax)
subpd 0x809c7(%rip), %xmm0    # 0xd0180
addpd %xmm3, %xmm0
divpd %xmm0, %xmm2
movupd %xmm2, 0x20(%rax)
xorps %xmm3, %xmm3
cvtsi2sd %edx, %xmm3
sarq $0x2, %rcx
movq %rcx, %xmm5
punpckldq 0x798d2(%rip), %xmm5 # xmm5 = xmm5[0],mem[0],xmm5[1],mem[1]
subpd 0x798da(%rip), %xmm5    # 0xc90c0
movapd %xmm5, %xmm4
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
addsd %xmm5, %xmm4
divsd %xmm4, %xmm3
movsd %xmm3, 0x30(%rax)
testl %edi, %edi
je 0x4f823
cmpl $0x1, %edi
je 0x4f82d
cmpl $0x2, %edi
jne 0x4f83c
cvtdq2pd %xmm1, %xmm1
divpd %xmm0, %xmm1
movupd %xmm1, 0x38(%rax)
xorps %xmm3, %xmm3
cvtsi2sd %esi, %xmm3
divsd %xmm4, %xmm3
jmp 0x4f828
movupd %xmm2, 0x38(%rax)
movsd %xmm3, 0x48(%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb27a5(%rip), %rdi     # 0x101fe8
leaq 0x80d0b(%rip), %rsi     # 0xd0555
movl $0x2f, %edx
callq 0x84e0
movq 0xb278d(%rip), %rdi     # 0x101fe8
callq 0x8200
movl $0x1, %edi
callq 0x8530
jmp 0x4f87c
jmp 0x4f87c
jmp 0x4f87c
jmp 0x4f87c
jmp 0x4f87c
jmp 0x4f87c
jmp 0x4f87c
jmp 0x4f87c
jmp 0x4f87c
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x36c6c
movq %r14, %rdi
callq 0x8840