// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %r9, %r13
movq %r8, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
callq 0x43a92
leaq 0x68(%rbx), %rdi
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x5, %rsi
addq $-0x9, %rsi
leaq 0x8(%rsp), %rdx
andl $0x0, (%rdx)
movq %rdi, 0x48(%rsp)
movq %rbx, 0x30(%rsp)
callq 0x44dfe
leaq 0x4(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0xc(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
pushq $0x48
popq %r15
xorl %r14d, %r14d
leaq 0x8(%rsp), %rbx
movq %r13, 0x50(%rsp)
leaq 0x9(%r14), %rcx
movq (%rbp), %rax
movq 0x8(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %rdx, %rcx
je 0x418fc
movq (%rax,%r15,4), %rax
cmpb $0x31, (%rax)
jne 0x4183a
movq 0x30(%rsp), %rax
incl (%rax)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r14, 0x8(%rsp)
movq %rbx, %rdx
callq 0x45ac4
cmpq 0x8(%r12), %rax
movq 0x38(%rsp), %r13
je 0x417b6
movq 0x28(%rsp), %rax
incl (%rax)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r14, 0x8(%rsp)
movq %rbx, %rdx
callq 0x45ac4
cmpq 0x8(%r13), %rax
je 0x417d8
movq 0x20(%rsp), %rax
incl (%rax)
movq 0x40(%rsp), %r13
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r14, 0x8(%rsp)
movq %rbx, %rdx
callq 0x45ac4
cmpq 0x8(%r13), %rax
je 0x417ff
movq 0x18(%rsp), %rax
incl (%rax)
movq 0x50(%rsp), %r13
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r14, 0x8(%rsp)
movq %rbx, %rdx
callq 0x45ac4
cmpq 0x8(%r13), %rax
je 0x41826
movq 0x10(%rsp), %rax
incl (%rax)
movq 0x48(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r14,4)
movq (%rbp), %rax
movq (%rax,%r15,4), %rax
cmpb $0x31, 0x2(%rax)
jne 0x418f0
movq 0x30(%rsp), %rax
incl (%rax)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r14, 0x8(%rsp)
movq %rbx, %rdx
callq 0x45ac4
cmpq 0x8(%r12), %rax
movq 0x38(%rsp), %r13
je 0x41874
movq 0x28(%rsp), %rax
incl (%rax)
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r14, 0x8(%rsp)
movq %rbx, %rdx
callq 0x45ac4
cmpq 0x8(%r13), %rax
je 0x41896
movq 0x20(%rsp), %rax
incl (%rax)
movq 0x40(%rsp), %r13
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r14, 0x8(%rsp)
movq %rbx, %rdx
callq 0x45ac4
cmpq 0x8(%r13), %rax
je 0x418bd
movq 0x18(%rsp), %rax
incl (%rax)
movq 0x50(%rsp), %r13
movq (%r13), %rdi
movq 0x8(%r13), %rsi
movq %r14, 0x8(%rsp)
movq %rbx, %rdx
callq 0x45ac4
cmpq 0x8(%r13), %rax
je 0x418e4
movq 0x10(%rsp), %rax
incl (%rax)
movq 0x48(%rsp), %rax
movq (%rax), %rax
incl (%rax,%r14,4)
addq $0x8, %r15
incq %r14
jmp 0x4175d
movq 0x38(%rsp), %r15
movq 0x8(%r15), %xmm1
movq 0x8(%r12), %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq (%r15), %xmm1
movq (%r12), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
movq 0x30(%rsp), %rbx
cvtdq2pd 0x4(%rbx), %xmm1
psubq %xmm2, %xmm0
movdqa %xmm0, %xmm2
psrad $0x2, %xmm2
movdqa 0x5d710(%rip), %xmm5    # 0x9f050
psrlq $0x2, %xmm0
movdqa %xmm0, %xmm3
pand %xmm5, %xmm3
movdqa 0x5d70b(%rip), %xmm6    # 0x9f060
por %xmm6, %xmm3
psrlq $0x20, %xmm2
movdqa 0x5d70a(%rip), %xmm7    # 0x9f070
por %xmm7, %xmm2
movapd 0x5d70d(%rip), %xmm8    # 0x9f080
subpd %xmm8, %xmm2
addpd %xmm3, %xmm2
divpd %xmm2, %xmm1
movq 0x8(%r13), %xmm3
movq 0x40(%rsp), %r14
movq 0x8(%r14), %xmm2
punpcklqdq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0]
movq (%r13), %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 0x5d6d4(%rip), %xmm0    # 0x9f090
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 0x55cbd(%rip), %rsi     # 0x976c0
movq 0x90(%rsp), %rbp
movq %rbp, %rdi
callq 0x2193f
testb %al, %al
jne 0x41a57
leaq 0x6e7a9(%rip), %rsi     # 0xb01c7
movq %rbp, %rdi
callq 0x2193f
testb %al, %al
je 0x41b52
leaq 0x14(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x20(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x1c(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x18(%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %r15
movq 0x20(%rsp), %rax
movss (%rax), %xmm0
movq 0x28(%rsp), %rax
movss (%rax), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
movq 0x8(%r15), %xmm1
movq 0x8(%r12), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
movq (%r15), %xmm1
movq (%r12), %xmm3
punpcklqdq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0]
psubq %xmm3, %xmm2
movdqa %xmm2, %xmm1
psrad $0x2, %xmm1
psrlq $0x2, %xmm2
movdqa 0x5d5a6(%rip), %xmm4    # 0x9f050
pand %xmm4, %xmm2
movdqa 0x5d5aa(%rip), %xmm5    # 0x9f060
por %xmm5, %xmm2
psrlq $0x20, %xmm1
movdqa 0x5d5a9(%rip), %xmm6    # 0x9f070
por %xmm6, %xmm1
movapd 0x5d5ad(%rip), %xmm7    # 0x9f080
subpd %xmm7, %xmm1
addpd %xmm2, %xmm1
divpd %xmm1, %xmm0
movupd %xmm0, 0x48(%rbx)
movq 0x10(%rsp), %rax
movss (%rax), %xmm0
movq 0x18(%rsp), %rax
movss (%rax), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
movq 0x8(%r13), %xmm1
movq 0x8(%r14), %xmm2
punpcklqdq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0]
movq (%r13), %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)
jmp 0x41b65
leaq 0x6b2c6(%rip), %rsi     # 0xace1f
movq %rbp, %rdi
callq 0x2193f
testb %al, %al
je 0x41b77
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9b46a(%rip), %rdi     # 0xdcfe8
leaq 0x5d683(%rip), %rsi     # 0x9f208
callq 0x8480
movq %rax, %rdi
callq 0x8230
pushq $0x1
popq %rdi
callq 0x8540
jmp 0x41bac
jmp 0x41bac
jmp 0x41bac
jmp 0x41bac
jmp 0x41bac
jmp 0x41bac
jmp 0x41bac
jmp 0x41bac
jmp 0x41bac
movq %rax, %rbx
movq 0x30(%rsp), %rdi
callq 0x2f3a2
movq %rbx, %rdi
callq 0x8870