// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
xorl %eax, %eax
movl %eax, (%rdi)
movw $0x0, 0x4(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rdi)
movq %rax, 0x18(%rdi)
movapd 0x7dbf4(%rip), %xmm1    # 0xcc6d0
movupd %xmm1, 0x20(%rdi)
movupd %xmm1, 0x30(%rdi)
movupd %xmm1, 0x40(%rdi)
addq $0x50, %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)
movupd %xmm0, 0xd0(%rbx)
movupd %xmm0, 0xe0(%rbx)
movupd %xmm0, 0xf0(%rbx)
movupd %xmm0, 0x100(%rbx)
movupd %xmm0, 0x110(%rbx)
movupd %xmm0, 0x120(%rbx)
movupd %xmm0, 0x130(%rbx)
movq %rax, 0x140(%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 0x56106
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
cmpq $0x120, %rcx            # imm = 0x120
je 0x4ecf8
leaq 0x8(%rbx), %rcx
movq %rcx, 0x18(%rsp)
movl $0x48, %r13d
xorl %r15d, %r15d
movq %r14, 0x20(%rsp)
movq (%rax,%r13,4), %rcx
cmpb $0x31, (%rcx)
jne 0x4ec4b
incl (%rbx)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4ebef
movq 0x18(%rsp), %rax
incl (%rax)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x5706e
cmpq 0x8(%r14), %rax
je 0x4ec0e
incl 0xc(%rbx)
movq 0x10(%rsp), %r14
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x5706e
cmpq 0x8(%r14), %rax
je 0x4ec32
incl 0x10(%rbx)
movq 0x28(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r15,4)
movq (%rbp), %rax
movq (%rax,%r13,4), %rcx
movq 0x20(%rsp), %r14
cmpb $0x31, 0x2(%rcx)
jne 0x4ecd5
incl (%rbx)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x5706e
cmpq 0x8(%r12), %rax
je 0x4ec7d
movq 0x18(%rsp), %rax
incl (%rax)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x5706e
cmpq 0x8(%r14), %rax
je 0x4ec9c
incl 0xc(%rbx)
movq 0x10(%rsp), %r14
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %r15, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x5706e
cmpq 0x8(%r14), %rax
je 0x4ecc0
incl 0x10(%rbx)
movq 0x28(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r15,4)
movq (%rbp), %rax
movq 0x20(%rsp), %r14
movq 0x8(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
addq $0x8, %r13
leaq 0x1(%r15), %rdx
addq $0xa, %r15
cmpq %rcx, %r15
movq %rdx, %r15
jne 0x4ebba
movq 0x10(%rsp), %r15
movq 0x8(%r15), %rax
subq (%r15), %rax
movq %rax, %rdx
shrq $0x2, %rdx
andl $-0x2, %edx
movl 0x10(%rbx), %ecx
subl %ecx, %edx
movq 0x8(%r14), %xmm1
movq 0x8(%r12), %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq (%r14), %xmm1
movq (%r12), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
psubq %xmm2, %xmm0
movl %edx, 0x1c(%rbx)
movq 0x8(%rbx), %xmm1
movdqa %xmm0, %xmm2
psrlq $0x2, %xmm2
pshufd $0xe8, %xmm2, %xmm3     # xmm3 = xmm2[0,2,2,3]
pand 0x813eb(%rip), %xmm3    # 0xd0140
psubd %xmm1, %xmm3
movq %xmm3, 0x14(%rbx)
cvtdq2pd %xmm1, %xmm1
pand 0x813e6(%rip), %xmm2    # 0xd0150
psrad $0x2, %xmm0
por 0x813e9(%rip), %xmm2    # 0xd0160
psrlq $0x20, %xmm0
por 0x813ec(%rip), %xmm0    # 0xd0170
subpd 0x813f4(%rip), %xmm0    # 0xd0180
addpd %xmm2, %xmm0
divpd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
sarq $0x2, %rax
movq %rax, %xmm2
punpckldq 0x7a304(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
movupd %xmm1, 0x20(%rbx)
subpd 0x7a307(%rip), %xmm2    # 0xc90c0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rbx)
leaq 0x7da0b(%rip), %rsi     # 0xcc7e0
movq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0x8160
testl %eax, %eax
je 0x4ee3e
leaq 0x90182(%rip), %rsi     # 0xdef6f
movq %r13, %rdi
callq 0x8160
testl %eax, %eax
je 0x4ee50
leaq 0x8e33f(%rip), %rsi     # 0xdd13f
movq %r13, %rdi
callq 0x8160
testl %eax, %eax
je 0x4ef08
movq 0xb31d1(%rip), %rdi     # 0x101fe8
leaq 0x81706(%rip), %rsi     # 0xd0524
movl $0x30, %edx
callq 0x84e0
movq 0xb31b9(%rip), %rdi     # 0x101fe8
callq 0x8200
movl $0x1, %edi
callq 0x8530
leaq 0x10(%rbx), %rcx
leaq 0xc(%rbx), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rbx), %xmm0
jmp 0x4ee60
leaq 0x18(%rbx), %rax
leaq 0x1c(%rbx), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl 0x14(%rbx), %xmm0
movq 0x8(%r12), %rdx
subq (%r12), %rdx
sarq $0x2, %rdx
movq %rdx, %xmm1
punpckldq 0x7a236(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x7a23e(%rip), %xmm1    # 0xc90c0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x38(%rbx)
movss (%rcx), %xmm0
movss (%rax), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
movq 0x8(%r15), %xmm1
movq 0x8(%r14), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
movq (%r15), %xmm1
movq (%r14), %xmm3
punpcklqdq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0]
psubq %xmm3, %xmm2
movdqa %xmm2, %xmm1
psrlq $0x2, %xmm2
pand 0x81277(%rip), %xmm2    # 0xd0150
psrad $0x2, %xmm1
por 0x8127a(%rip), %xmm2    # 0xd0160
psrlq $0x20, %xmm1
por 0x8127d(%rip), %xmm1    # 0xd0170
subpd 0x81285(%rip), %xmm1    # 0xd0180
addpd %xmm2, %xmm1
divpd %xmm1, %xmm0
movupd %xmm0, 0x40(%rbx)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4ef28
jmp 0x4ef28
jmp 0x4ef28
jmp 0x4ef28
jmp 0x4ef28
jmp 0x4ef28
jmp 0x4ef28
movq %rax, %r14
movq %rbx, %rdi
callq 0x36c6c
movq %r14, %rdi
callq 0x8840