// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/process_vcf_utils.cpp
// Function: getFourSetVariantCounts(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&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
FourSetCounts getFourSetVariantCounts(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>& set4_loci, const std::string& AA) {
    FourSetCounts thisVariantCounts;
    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(set4_loci.begin(), set4_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != set4_loci.end()) { thisVariantCounts.set4AltCount++; }
            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(set4_loci.begin(), set4_loci.end(), i-NUM_NON_GENOTYPE_COLUMNS) != set4_loci.end()) { thisVariantCounts.set4AltCount++; }
            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 (AA == "ref") {
        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 (AA == "alt") {
        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 (AA == "N") {
    } else {
        std::cerr << "Error: Derived allele can only be \"ref\" or \"alt\"" << std::endl;
        exit(1);
    }
    
    return thisVariantCounts;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r12
movq %r8, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %rbp
movq %rdi, %rbx
xorl %eax, %eax
movl %eax, 0x20(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rdi)
movupd %xmm0, (%rdi)
movdqa 0x7d755(%rip), %xmm1    # 0xcc6d0
movdqu %xmm1, 0x28(%rdi)
movdqu %xmm1, 0x38(%rdi)
movdqu %xmm1, 0x48(%rdi)
movdqu %xmm1, 0x58(%rdi)
addq $0x68, %rdi
movupd %xmm0, 0x68(%rbx)
movupd %xmm0, 0x78(%rbx)
movupd %xmm0, 0x88(%rbx)
movupd %xmm0, 0x98(%rbx)
movupd %xmm0, 0xa8(%rbx)
movupd %xmm0, 0xb8(%rbx)
movupd %xmm0, 0xc8(%rbx)
movq $0x0, 0xd8(%rbx)
movq 0x8(%rsi), %rsi
subq (%rbp), %rsi
sarq $0x5, %rsi
addq $-0x9, %rsi
leaq 0x8(%rsp), %rdx
movl %eax, (%rdx)
movq %rdi, 0x30(%rsp)
callq 0x56106
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
cmpq $0x120, %rcx            # imm = 0x120
je 0x4f1a6
movl $0x48, %r14d
xorl %r13d, %r13d
leaq 0x8(%rsp), %r15
movq %r12, 0x28(%rsp)
movq (%rax,%r14,4), %rcx
cmpb $0x31, (%rcx)
jne 0x4f0d3
incl (%rbx)
movq 0x18(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
movq %r15, %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4f050
incl 0x4(%rbx)
movq 0x10(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
movq %r15, %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4f075
incl 0x8(%rbx)
movq 0x20(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
movq %r15, %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4f09a
incl 0xc(%rbx)
movq 0x28(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
movq %r15, %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4f0bf
incl 0x10(%rbx)
movq 0x30(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r13,4)
movq (%rbp), %rax
movq (%rax,%r14,4), %rcx
cmpb $0x31, 0x2(%rcx)
jne 0x4f183
incl (%rbx)
movq 0x18(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
movq %r15, %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4f104
incl 0x4(%rbx)
movq 0x10(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
movq %r15, %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4f129
incl 0x8(%rbx)
movq 0x20(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
movq %r15, %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4f14e
incl 0xc(%rbx)
movq 0x28(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
movq %r15, %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4f173
incl 0x10(%rbx)
movq 0x30(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r13,4)
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
addq $0x8, %r14
leaq 0x1(%r13), %rdx
addq $0xa, %r13
cmpq %rcx, %r13
movq %rdx, %r13
jne 0x4f01c
movq 0x70(%rsp), %r15
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %xmm1
movq 0x18(%rsp), %rax
movq 0x8(%rax), %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq (%rcx), %xmm1
movq (%rax), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
cvtdq2pd 0x4(%rbx), %xmm1
psubq %xmm2, %xmm0
movdqa %xmm0, %xmm2
psrad $0x2, %xmm2
movdqa 0x80f67(%rip), %xmm5    # 0xd0150
psrlq $0x2, %xmm0
movdqa %xmm0, %xmm3
pand %xmm5, %xmm3
movdqa 0x80f62(%rip), %xmm6    # 0xd0160
por %xmm6, %xmm3
psrlq $0x20, %xmm2
movdqa 0x80f61(%rip), %xmm7    # 0xd0170
por %xmm7, %xmm2
movapd 0x80f64(%rip), %xmm8    # 0xd0180
subpd %xmm8, %xmm2
addpd %xmm3, %xmm2
divpd %xmm2, %xmm1
movq 0x8(%r12), %xmm3
movq 0x20(%rsp), %r14
movq 0x8(%r14), %xmm2
punpcklqdq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0]
movq (%r12), %xmm3
movq (%r14), %xmm4
punpcklqdq %xmm3, %xmm4    # xmm4 = xmm4[0],xmm3[0]
psubq %xmm4, %xmm2
movdqa %xmm2, %xmm3
psrlq $0x2, %xmm3
shufps $0x88, %xmm3, %xmm0     # xmm0 = xmm0[0,2],xmm3[0,2]
andps 0x80f2a(%rip), %xmm0    # 0xd0190
movupd %xmm1, 0x28(%rbx)
movdqu 0x4(%rbx), %xmm1
psubd %xmm1, %xmm0
movdqu %xmm0, 0x14(%rbx)
cvtdq2pd 0xc(%rbx), %xmm0
psrad $0x2, %xmm2
pand %xmm5, %xmm3
por %xmm6, %xmm3
psrlq $0x20, %xmm2
por %xmm7, %xmm2
subpd %xmm8, %xmm2
addpd %xmm3, %xmm2
divpd %xmm2, %xmm0
movupd %xmm0, 0x38(%rbx)
leaq 0x7d533(%rip), %rsi     # 0xcc7e0
movq %r15, %rdi
callq 0x8160
testl %eax, %eax
je 0x4f311
leaq 0x8fcaf(%rip), %rsi     # 0xdef6f
movq %r15, %rdi
callq 0x8160
testl %eax, %eax
je 0x4f323
leaq 0x8de6c(%rip), %rsi     # 0xdd13f
movq %r15, %rdi
callq 0x8160
testl %eax, %eax
je 0x4f41d
movq 0xb2cfe(%rip), %rdi     # 0x101fe8
leaq 0x81233(%rip), %rsi     # 0xd0524
movl $0x30, %edx
callq 0x84e0
movq 0xb2ce6(%rip), %rdi     # 0x101fe8
callq 0x8200
movl $0x1, %edi
callq 0x8530
leaq 0x4(%rbx), %rdx
leaq 0x8(%rbx), %rsi
leaq 0xc(%rbx), %rax
leaq 0x10(%rbx), %rcx
jmp 0x4f333
leaq 0x14(%rbx), %rdx
leaq 0x20(%rbx), %rcx
leaq 0x1c(%rbx), %rax
leaq 0x18(%rbx), %rsi
movss (%rsi), %xmm0
movss (%rdx), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
movq 0x10(%rsp), %rsi
movq 0x8(%rsi), %xmm1
movq 0x18(%rsp), %rdx
movq 0x8(%rdx), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
movq (%rsi), %xmm1
movq (%rdx), %xmm3
punpcklqdq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0]
psubq %xmm3, %xmm2
movdqa %xmm2, %xmm1
psrad $0x2, %xmm1
psrlq $0x2, %xmm2
movdqa 0x80dd0(%rip), %xmm4    # 0xd0150
pand %xmm4, %xmm2
movdqa 0x80dd4(%rip), %xmm5    # 0xd0160
por %xmm5, %xmm2
psrlq $0x20, %xmm1
movdqa 0x80dd3(%rip), %xmm6    # 0xd0170
por %xmm6, %xmm1
movapd 0x80dd7(%rip), %xmm7    # 0xd0180
subpd %xmm7, %xmm1
addpd %xmm2, %xmm1
divpd %xmm1, %xmm0
movupd %xmm0, 0x48(%rbx)
movss (%rcx), %xmm0
movss (%rax), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
movq 0x8(%r12), %xmm1
movq 0x8(%r14), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
movq (%r12), %xmm1
movq (%r14), %xmm3
punpcklqdq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0]
psubq %xmm3, %xmm2
movdqa %xmm2, %xmm1
psrad $0x2, %xmm1
psrlq $0x2, %xmm2
pand %xmm4, %xmm2
por %xmm5, %xmm2
psrlq $0x20, %xmm1
por %xmm6, %xmm1
subpd %xmm7, %xmm1
addpd %xmm2, %xmm1
divpd %xmm1, %xmm0
movupd %xmm0, 0x58(%rbx)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4f441
jmp 0x4f441
jmp 0x4f441
jmp 0x4f441
jmp 0x4f441
jmp 0x4f441
jmp 0x4f441
jmp 0x4f441
jmp 0x4f441
movq %rax, %r14
movq %rbx, %rdi
callq 0x37580
movq %r14, %rdi
callq 0x8840