// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
movq %r8, %r13
movq %rcx, 0x20(%rsp)
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %rbx
xorl %eax, %eax
movl %eax, 0x20(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rdi)
movupd %xmm0, (%rdi)
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, 0x28(%rdi)
movq %rcx, 0x30(%rdi)
movq %rcx, 0x38(%rdi)
movq %rcx, 0x40(%rdi)
movq %rcx, 0x48(%rdi)
movq %rcx, 0x50(%rdi)
movq %rcx, 0x58(%rdi)
movq %rcx, 0x60(%rdi)
leaq 0x68(%rdi), %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 0x561e6
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
cmpq $0x120, %rcx            # imm = 0x120
movq %r14, 0x10(%rsp)
je 0x522b7
movl $0x48, %r15d
xorl %r12d, %r12d
movq %r13, 0x28(%rsp)
movq (%rax,%r15,4), %rax
cmpb $0x31, (%rax)
jne 0x521dd
incl (%rbx)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r12, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r14), %rax
je 0x5215e
incl 0x4(%rbx)
movq 0x20(%rsp), %r14
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r12, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r14), %rax
je 0x52182
incl 0x8(%rbx)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r12, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
movq 0x10(%rsp), %r14
cmpq 0x8(%r13), %rax
je 0x521a7
incl 0xc(%rbx)
movq 0x18(%rsp), %r13
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r12, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r13), %rax
je 0x521cc
incl 0x10(%rbx)
movq 0x30(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r12,4)
movq 0x28(%rsp), %r13
movq (%rbp), %rax
movq (%rax,%r15,4), %rax
cmpb $0x31, 0x2(%rax)
jne 0x5228f
incl (%rbx)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r12, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r14), %rax
je 0x52210
incl 0x4(%rbx)
movq 0x20(%rsp), %r14
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r12, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r14), %rax
je 0x52234
incl 0x8(%rbx)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r12, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
movq 0x10(%rsp), %r14
cmpq 0x8(%r13), %rax
je 0x52259
incl 0xc(%rbx)
movq 0x18(%rsp), %r13
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r12, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r13), %rax
je 0x5227e
incl 0x10(%rbx)
movq 0x30(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r12,4)
movq 0x28(%rsp), %r13
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
leaq 0x1(%r12), %rdx
addq $0xa, %r12
addq $0x8, %r15
cmpq %rcx, %r12
movq %rdx, %r12
jne 0x52130
movq 0x8(%r14), %r8
subq (%r14), %r8
movq 0x70(%rsp), %r14
movq %r8, %rax
shrq $0x2, %rax
andl $-0x2, %eax
movl 0x4(%rbx), %r10d
movl 0x8(%rbx), %edx
subl %r10d, %eax
movl %eax, 0x14(%rbx)
movq 0x20(%rsp), %r12
movq 0x8(%r12), %rsi
subq (%r12), %rsi
movq %rsi, %rax
shrq $0x2, %rax
andl $-0x2, %eax
subl %edx, %eax
movl %eax, 0x18(%rbx)
movq 0x8(%r13), %rcx
subq (%r13), %rcx
movq %rcx, %rax
shrq $0x2, %rax
andl $-0x2, %eax
movl 0xc(%rbx), %r9d
subl %r9d, %eax
movl %eax, 0x1c(%rbx)
movq 0x18(%rsp), %r15
movq 0x8(%r15), %rax
subq (%r15), %rax
movq %rax, %r11
shrq $0x2, %r11
andl $-0x2, %r11d
movl 0x10(%rbx), %edi
subl %edi, %r11d
movl %r11d, 0x20(%rbx)
cvtsi2sd %r10d, %xmm0
sarq $0x2, %r8
movq %r8, %xmm1
movq 0x77e56(%rip), %xmm3    # 0xca1a0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x77e5a(%rip), %xmm4    # 0xca1b0
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd %xmm0, 0x28(%rbx)
sarq $0x2, %rsi
movq %rsi, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm4, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, 0x30(%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
sarq $0x2, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x38(%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
sarq $0x2, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x40(%rbx)
leaq 0x7d12a(%rip), %rsi     # 0xcf528
movq %r14, %rdi
callq 0x8160
testl %eax, %eax
je 0x52462
leaq 0x95ae6(%rip), %rsi     # 0xe7ef7
movq %r14, %rdi
callq 0x8160
testl %eax, %eax
je 0x52474
leaq 0x9272b(%rip), %rsi     # 0xe4b4f
movq %r14, %rdi
callq 0x8160
testl %eax, %eax
je 0x5256c
movq 0xb8bad(%rip), %rdi     # 0x10afe8
leaq 0x84bb6(%rip), %rsi     # 0xd6ff8
movl $0x30, %edx
callq 0x84e0
movq 0xb8b95(%rip), %rdi     # 0x10afe8
callq 0x8200
movl $0x1, %edi
callq 0x8530
leaq 0x4(%rbx), %rsi
leaq 0x8(%rbx), %rdx
leaq 0xc(%rbx), %rcx
leaq 0x10(%rbx), %rax
jmp 0x52484
leaq 0x14(%rbx), %rsi
leaq 0x18(%rbx), %rdx
leaq 0x1c(%rbx), %rcx
leaq 0x20(%rbx), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rsi), %xmm0
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
subq (%rdi), %rsi
sarq $0x2, %rsi
movq %rsi, %xmm1
movq 0x77cf8(%rip), %xmm3    # 0xca1a0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x77cfc(%rip), %xmm4    # 0xca1b0
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x48(%rbx)
xorps %xmm0, %xmm0
cvtsi2sdl (%rdx), %xmm0
movq 0x8(%r12), %rdx
subq (%r12), %rdx
sarq $0x2, %rdx
movq %rdx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x50(%rbx)
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx), %xmm0
movq 0x8(%r13), %rcx
subq (%r13), %rcx
sarq $0x2, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x58(%rbx)
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movq 0x8(%r15), %rax
subq (%r15), %rax
sarq $0x2, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x60(%rbx)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x52590
jmp 0x52590
jmp 0x52590
jmp 0x52590
jmp 0x52590
jmp 0x52590
jmp 0x52590
jmp 0x52590
jmp 0x52590
movq %rax, %r14
movq %rbx, %rdi
callq 0x3a430
movq %r14, %rdi
callq 0x8840