// File: 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
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x150(%rbp)
movq %rdi, %rax
movq %rax, -0x158(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
callq 0x50ee0
movq -0x150(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x148(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3ffd0
movq -0x148(%rbp), %rdi
movq %rax, %rsi
addq $-0x9, %rsi
movl $0x0, -0x38(%rbp)
leaq -0x38(%rbp), %rdx
callq 0x838d0
jmp 0x7e118
movq $0x9, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3ffd0
movq %rax, %rcx
movq -0x160(%rbp), %rax
cmpq %rcx, %rax
je 0x7e58e
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x52960
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa670
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0x7e35e
movq -0x150(%rbp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
callq 0x83b30
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x83b60
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
addq $-0x9, %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x83ae0
movq %rax, -0x168(%rbp)
jmp 0x7e1b9
movq -0x168(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
callq 0x83b60
movq %rax, -0x78(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x83aa0
testb $0x1, %al
jne 0x7e1e4
jmp 0x7e213
movq -0x150(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x7e213
movq -0x150(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x51170
jmp 0x7ea2a
movq -0x20(%rbp), %rdi
callq 0x83b30
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
callq 0x83b60
movq %rax, -0x90(%rbp)
movq -0x50(%rbp), %rax
addq $-0x9, %rax
movq %rax, -0x98(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x83ae0
movq %rax, -0x170(%rbp)
jmp 0x7e265
movq -0x170(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rdi
callq 0x83b60
movq %rax, -0xa0(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x83aa0
testb $0x1, %al
jne 0x7e296
jmp 0x7e2a6
movq -0x150(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rdi
callq 0x83b30
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x83b60
movq %rax, -0xb8(%rbp)
movq -0x50(%rbp), %rax
addq $-0x9, %rax
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x83ae0
movq %rax, -0x178(%rbp)
jmp 0x7e2f8
movq -0x178(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x83b60
movq %rax, -0xc8(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x83aa0
testb $0x1, %al
jne 0x7e32f
jmp 0x7e33f
movq -0x150(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x150(%rbp), %rdi
addq $0x50, %rdi
movq -0x50(%rbp), %rsi
subq $0x9, %rsi
callq 0x4d100
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x52960
movq %rax, %rdi
movl $0x2, %esi
callq 0xa670
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0x7e57b
movq -0x150(%rbp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
callq 0x83b30
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x83b60
movq %rax, -0xe0(%rbp)
movq -0x50(%rbp), %rax
addq $-0x9, %rax
movq %rax, -0xe8(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x83ae0
movq %rax, -0x180(%rbp)
jmp 0x7e3e3
movq -0x180(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x83b60
movq %rax, -0xf0(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x83aa0
testb $0x1, %al
jne 0x7e41a
jmp 0x7e42a
movq -0x150(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rdi
callq 0x83b30
movq %rax, -0x100(%rbp)
movq -0x20(%rbp), %rdi
callq 0x83b60
movq %rax, -0x108(%rbp)
movq -0x50(%rbp), %rax
addq $-0x9, %rax
movq %rax, -0x110(%rbp)
movq -0x100(%rbp), %rdi
movq -0x108(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x83ae0
movq %rax, -0x188(%rbp)
jmp 0x7e47c
movq -0x188(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x83b60
movq %rax, -0x118(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x83aa0
testb $0x1, %al
jne 0x7e4b3
jmp 0x7e4c3
movq -0x150(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rdi
callq 0x83b30
movq %rax, -0x128(%rbp)
movq -0x28(%rbp), %rdi
callq 0x83b60
movq %rax, -0x130(%rbp)
movq -0x50(%rbp), %rax
addq $-0x9, %rax
movq %rax, -0x138(%rbp)
movq -0x128(%rbp), %rdi
movq -0x130(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x83ae0
movq %rax, -0x190(%rbp)
jmp 0x7e515
movq -0x190(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x28(%rbp), %rdi
callq 0x83b60
movq %rax, -0x140(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x83aa0
testb $0x1, %al
jne 0x7e54c
jmp 0x7e55c
movq -0x150(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x150(%rbp), %rdi
addq $0x50, %rdi
movq -0x50(%rbp), %rsi
subq $0x9, %rsi
callq 0x4d100
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x7e57d
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x7e120
movq -0x18(%rbp), %rdi
callq 0x83b90
movq %rax, %rcx
movq -0x150(%rbp), %rax
addl %ecx, %ecx
movl 0x8(%rax), %edx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x20(%rbp), %rdi
callq 0x83b90
movq %rax, %rcx
movq -0x150(%rbp), %rax
addl %ecx, %ecx
movl 0xc(%rax), %edx
subl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rdi
callq 0x83b90
movq %rax, %rcx
movq -0x150(%rbp), %rax
addl %ecx, %ecx
movl 0x10(%rax), %edx
subl %edx, %ecx
movl %ecx, 0x1c(%rax)
cvtsi2sdl 0x8(%rax), %xmm0
movsd %xmm0, -0x1d0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x83b90
movsd -0x1d0(%rbp), %xmm0
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
movaps 0xafb44(%rip), %xmm2    # 0x12e160
movaps %xmm2, -0x1c0(%rbp)
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xafb41(%rip), %xmm2    # 0x12e170
movaps %xmm2, -0x1b0(%rbp)
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rax)
cvtsi2sdl 0xc(%rax), %xmm0
movsd %xmm0, -0x1c8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x83b90
movsd -0x1c8(%rbp), %xmm0
movaps -0x1c0(%rbp), %xmm3
movaps -0x1b0(%rbp), %xmm2
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rax)
cvtsi2sdl 0x10(%rax), %xmm0
movsd %xmm0, -0x1a0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x83b90
movaps -0x1c0(%rbp), %xmm3
movaps -0x1b0(%rbp), %xmm2
movsd -0x1a0(%rbp), %xmm0
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rax)
movq -0x30(%rbp), %rdi
leaq 0xb507b(%rip), %rsi     # 0x133788
callq 0x2d770
movb %al, -0x191(%rbp)
jmp 0x7e71a
movb -0x191(%rbp), %al
testb $0x1, %al
jne 0x7e729
jmp 0x7e852
movq -0x150(%rbp), %rax
cvtsi2sdl 0x8(%rax), %xmm0
movsd %xmm0, -0x210(%rbp)
movq -0x18(%rbp), %rdi
callq 0x83b90
movsd -0x210(%rbp), %xmm0
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
movaps 0xaf9f9(%rip), %xmm2    # 0x12e160
movaps %xmm2, -0x200(%rbp)
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xaf9f6(%rip), %xmm2    # 0x12e170
movaps %xmm2, -0x1f0(%rbp)
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rax)
cvtsi2sdl 0xc(%rax), %xmm0
movsd %xmm0, -0x208(%rbp)
movq -0x20(%rbp), %rdi
callq 0x83b90
movsd -0x208(%rbp), %xmm0
movaps -0x200(%rbp), %xmm3
movaps -0x1f0(%rbp), %xmm2
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rax)
cvtsi2sdl 0x10(%rax), %xmm0
movsd %xmm0, -0x1d8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x83b90
movaps -0x200(%rbp), %xmm3
movaps -0x1f0(%rbp), %xmm2
movsd -0x1d8(%rbp), %xmm0
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rax)
jmp 0x7ea04
movq -0x30(%rbp), %rdi
leaq 0xce0e6(%rip), %rsi     # 0x14c943
callq 0x2d770
movb %al, -0x211(%rbp)
jmp 0x7e86a
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0x7e879
jmp 0x7e99f
movq -0x150(%rbp), %rax
cvtsi2sdl 0x14(%rax), %xmm0
movsd %xmm0, -0x250(%rbp)
movq -0x18(%rbp), %rdi
callq 0x83b90
movsd -0x250(%rbp), %xmm0
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
movaps 0xaf8a9(%rip), %xmm2    # 0x12e160
movaps %xmm2, -0x240(%rbp)
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xaf8a6(%rip), %xmm2    # 0x12e170
movaps %xmm2, -0x230(%rbp)
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rax)
cvtsi2sdl 0x18(%rax), %xmm0
movsd %xmm0, -0x248(%rbp)
movq -0x20(%rbp), %rdi
callq 0x83b90
movsd -0x248(%rbp), %xmm0
movaps -0x240(%rbp), %xmm3
movaps -0x230(%rbp), %xmm2
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rax)
cvtsi2sdl 0x1c(%rax), %xmm0
movsd %xmm0, -0x220(%rbp)
movq -0x28(%rbp), %rdi
callq 0x83b90
movaps -0x240(%rbp), %xmm3
movaps -0x230(%rbp), %xmm2
movsd -0x220(%rbp), %xmm0
movq %rax, %rcx
movq -0x150(%rbp), %rax
addq %rcx, %rcx
movq %rcx, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rax)
jmp 0x7ea02
movq -0x30(%rbp), %rdi
leaq 0xcabf7(%rip), %rsi     # 0x1495a1
callq 0x2d770
movb %al, -0x251(%rbp)
jmp 0x7e9b7
movb -0x251(%rbp), %al
testb $0x1, %al
jne 0x7e9c3
jmp 0x7e9c5
jmp 0x7ea00
movq 0x11a624(%rip), %rdi    # 0x198ff0
leaq 0xbc915(%rip), %rsi     # 0x13b2e8
callq 0xa5c0
movq %rax, -0x260(%rbp)
jmp 0x7e9e1
movq -0x260(%rbp), %rdi
movq 0x11a599(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x7e9f6
movl $0x1, %edi
callq 0xa700
jmp 0x7ea02
jmp 0x7ea04
movb $0x1, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
jne 0x7ea1a
movq -0x150(%rbp), %rdi
callq 0x51170
movq -0x158(%rbp), %rax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0xab50
nopw %cs:(%rax,%rax)