// File: /workspace/github_cpp_makefile_star2_O1/millanek[P]evo/process_vcf_utils.cpp
// Function: getThreeSetVariantCounts(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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
ThreeSetCounts getThreeSetVariantCounts(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::string& AA) {
    ThreeSetCounts 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++; }
            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++; }
            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.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);
    
    // 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);
    } 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);
    } 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, 0x30(%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
xorl %eax, %eax
movl %eax, (%rdi)
movb %al, 0x4(%rdi)
movb %al, 0x5(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rdi)
movq %rax, 0x18(%rdi)
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, 0x20(%rdi)
movq %rcx, 0x28(%rdi)
movq %rcx, 0x30(%rdi)
movq %rcx, 0x38(%rdi)
movq %rcx, 0x40(%rdi)
movq %rcx, 0x48(%rdi)
leaq 0x50(%rdi), %rdi
movq %rax, 0xc0(%rbx)
movl %eax, 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 %rax, 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
movl %eax, (%rdx)
movq %rdi, 0x28(%rsp)
callq 0x561e6
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
cmpq $0x120, %rcx            # imm = 0x120
je 0x51d87
leaq 0x8(%rbx), %rcx
movq %rcx, 0x18(%rsp)
movl $0x48, %r14d
xorl %r13d, %r13d
movq %r15, 0x20(%rsp)
movq (%rax,%r14,4), %rax
cmpb $0x31, (%rax)
jne 0x51cd6
incl (%rbx)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r12), %rax
je 0x51c82
movq 0x18(%rsp), %rax
incl (%rax)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movq %r13, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r15), %rax
je 0x51ca1
incl 0xc(%rbx)
movq 0x10(%rsp), %r15
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movq %r13, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r15), %rax
je 0x51cc5
incl 0x10(%rbx)
movq 0x28(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r13,4)
movq 0x20(%rsp), %r15
movq (%rbp), %rax
movq (%rax,%r14,4), %rax
cmpb $0x31, 0x2(%rax)
jne 0x51d60
incl (%rbx)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r13, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r12), %rax
je 0x51d0c
movq 0x18(%rsp), %rax
incl (%rax)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movq %r13, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r15), %rax
je 0x51d2b
incl 0xc(%rbx)
movq 0x10(%rsp), %r15
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movq %r13, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x56e90
cmpq 0x8(%r15), %rax
je 0x51d4f
incl 0x10(%rbx)
movq 0x28(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r13,4)
movq 0x20(%rsp), %r15
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
leaq 0x1(%r13), %rdx
addq $0xa, %r13
addq $0x8, %r14
cmpq %rcx, %r13
movq %rdx, %r13
jne 0x51c51
movq 0x8(%r12), %rsi
subq (%r12), %rsi
movq %rsi, %rax
shrq $0x2, %rax
andl $-0x2, %eax
movl 0x8(%rbx), %r8d
movl 0xc(%rbx), %ecx
subl %r8d, %eax
movl %eax, 0x14(%rbx)
movq 0x8(%r15), %rdx
subq (%r15), %rdx
movq %rdx, %rax
shrq $0x2, %rax
andl $-0x2, %eax
subl %ecx, %eax
movl %eax, 0x18(%rbx)
movq 0x10(%rsp), %r14
movq 0x8(%r14), %rax
subq (%r14), %rax
movq %rax, %r9
shrq $0x2, %r9
andl $-0x2, %r9d
movl 0x10(%rbx), %edi
subl %edi, %r9d
movl %r9d, 0x1c(%rbx)
cvtsi2sd %r8d, %xmm0
sarq $0x2, %rsi
movq %rsi, %xmm1
movq 0x783ac(%rip), %xmm3    # 0xca1a0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x783b0(%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, 0x20(%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
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, 0x28(%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, 0x30(%rbx)
leaq 0x7d6ae(%rip), %rsi     # 0xcf528
movq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0x8160
testl %eax, %eax
je 0x51ee7
leaq 0x96065(%rip), %rsi     # 0xe7ef7
movq %r13, %rdi
callq 0x8160
testl %eax, %eax
je 0x51f54
leaq 0x92ca6(%rip), %rsi     # 0xe4b4f
movq %r13, %rdi
callq 0x8160
testl %eax, %eax
je 0x52010
movq 0xb9128(%rip), %rdi     # 0x10afe8
leaq 0x85131(%rip), %rsi     # 0xd6ff8
movl $0x30, %edx
callq 0x84e0
movq 0xb9110(%rip), %rdi     # 0x10afe8
callq 0x8200
movl $0x1, %edi
callq 0x8530
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rbx), %xmm0
movq 0x8(%r12), %rax
subq (%r12), %rax
sarq $0x2, %rax
movq %rax, %xmm1
movq 0x78297(%rip), %xmm3    # 0xca1a0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x7829b(%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, 0x38(%rbx)
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rbx), %xmm0
leaq 0x10(%rbx), %rax
movq 0x8(%r15), %rcx
subq (%r15), %rcx
sarq $0x2, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
jmp 0x51fbf
xorps %xmm0, %xmm0
cvtsi2sdl 0x14(%rbx), %xmm0
movq 0x8(%r12), %rax
subq (%r12), %rax
sarq $0x2, %rax
movq %rax, %xmm1
movq 0x7822a(%rip), %xmm4    # 0xca1a0
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
movapd 0x7822e(%rip), %xmm3    # 0xca1b0
subpd %xmm3, %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
cvtsi2sdl 0x18(%rbx), %xmm0
leaq 0x1c(%rbx), %rax
movq 0x8(%r15), %rcx
subq (%r15), %rcx
sarq $0x2, %rcx
movq %rcx, %xmm1
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x40(%rbx)
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x2, %rax
movq %rax, %xmm1
punpckldq 0x781ad(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x781b5(%rip), %xmm1    # 0xca1b0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x48(%rbx)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x52030
jmp 0x52030
jmp 0x52030
jmp 0x52030
jmp 0x52030
jmp 0x52030
jmp 0x52030
movq %rax, %r14
movq %rbx, %rdi
callq 0x39a46
movq %r14, %rdi
callq 0x8840