// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
callq 0x439fa
leaq 0x50(%rbx), %rdi
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x5, %rsi
addq $-0x9, %rsi
leaq 0x8(%rsp), %rdx
andl $0x0, (%rdx)
movq %rdi, 0x28(%rsp)
movq %rbx, 0x10(%rsp)
callq 0x44dfe
leaq 0xc(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x10(%rbx), %rax
movq %rax, 0x18(%rsp)
pushq $0x48
popq %r13
xorl %ebx, %ebx
leaq 0x9(%rbx), %rcx
movq (%rbp), %rax
movq 0x8(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %rdx, %rcx
je 0x4147b
movq (%rax,%r13,4), %rax
cmpb $0x31, (%rax)
jne 0x413ea
movq 0x10(%rsp), %rax
incl (%rax)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %rbx, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x45ac4
cmpq 0x8(%r12), %rax
je 0x41391
movq 0x10(%rsp), %rax
incl 0x8(%rax)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %rbx, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x45ac4
cmpq 0x8(%r14), %rax
je 0x413b4
movq 0x20(%rsp), %rax
incl (%rax)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movq %rbx, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x45ac4
cmpq 0x8(%r15), %rax
je 0x413d7
movq 0x18(%rsp), %rax
incl (%rax)
movq 0x28(%rsp), %rax
movq (%rax), %rax
incl (%rax,%rbx,4)
movq (%rbp), %rax
movq (%rax,%r13,4), %rax
cmpb $0x31, 0x2(%rax)
jne 0x4146f
movq 0x10(%rsp), %rax
incl (%rax)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %rbx, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x45ac4
cmpq 0x8(%r12), %rax
je 0x4141e
movq 0x10(%rsp), %rax
incl 0x8(%rax)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq %rbx, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x45ac4
cmpq 0x8(%r14), %rax
je 0x41441
movq 0x20(%rsp), %rax
incl (%rax)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movq %rbx, 0x8(%rsp)
leaq 0x8(%rsp), %rdx
callq 0x45ac4
cmpq 0x8(%r15), %rax
je 0x41464
movq 0x18(%rsp), %rax
incl (%rax)
movq 0x28(%rsp), %rax
movq (%rax), %rax
incl (%rax,%rbx,4)
addq $0x8, %r13
incq %rbx
jmp 0x4133a
movq 0x8(%r15), %rax
subq (%r15), %rax
movq %rax, %rdx
shrq $0x2, %rdx
andl $-0x2, %edx
movq 0x10(%rsp), %rbx
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 0x5db68(%rip), %xmm3    # 0x9f040
psubd %xmm1, %xmm3
movq %xmm3, 0x14(%rbx)
cvtdq2pd %xmm1, %xmm1
pand 0x5db63(%rip), %xmm2    # 0x9f050
psrad $0x2, %xmm0
por 0x5db66(%rip), %xmm2    # 0x9f060
psrlq $0x20, %xmm0
por 0x5db69(%rip), %xmm0    # 0x9f070
subpd 0x5db71(%rip), %xmm0    # 0x9f080
addpd %xmm2, %xmm0
divpd %xmm0, %xmm1
cvtsi2sd %ecx, %xmm0
sarq $0x2, %rax
movq %rax, %xmm2
punpckldq 0x50d14(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
movupd %xmm1, 0x20(%rbx)
subpd 0x50d17(%rip), %xmm2    # 0x92250
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rbx)
leaq 0x5616b(%rip), %rsi     # 0x976c0
movq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0x2193f
testb %al, %al
je 0x41587
cvtsi2sdl 0x8(%rbx), %xmm0
movq 0x8(%r12), %rax
subq (%r12), %rax
sarq $0x2, %rax
movq %rax, %xmm1
punpckldq 0x50cbb(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
jmp 0x415cf
leaq 0x6ec39(%rip), %rsi     # 0xb01c7
movq %r13, %rdi
callq 0x2193f
testb %al, %al
je 0x41669
cvtsi2sdl 0x14(%rbx), %xmm0
leaq 0x18(%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%r12), %rax
subq (%r12), %rax
sarq $0x2, %rax
movq %rax, %xmm1
punpckldq 0x50c7a(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
leaq 0x1c(%rbx), %rax
movq %rax, 0x18(%rsp)
subpd 0x50c79(%rip), %xmm1    # 0x92250
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x38(%rbx)
movq 0x18(%rsp), %rax
movss (%rax), %xmm0
movq 0x20(%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(%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 0x5da18(%rip), %xmm2    # 0x9f050
psrad $0x2, %xmm1
por 0x5da1b(%rip), %xmm2    # 0x9f060
psrlq $0x20, %xmm1
por 0x5da1e(%rip), %xmm1    # 0x9f070
subpd 0x5da26(%rip), %xmm1    # 0x9f080
addpd %xmm2, %xmm1
divpd %xmm1, %xmm0
movupd %xmm0, 0x40(%rbx)
jmp 0x4167c
leaq 0x6b7af(%rip), %rsi     # 0xace1f
movq %r13, %rdi
callq 0x2193f
testb %al, %al
je 0x4168e
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9b953(%rip), %rdi     # 0xdcfe8
leaq 0x5db6c(%rip), %rsi     # 0x9f208
callq 0x8480
movq %rax, %rdi
callq 0x8230
pushq $0x1
popq %rdi
callq 0x8540
jmp 0x416bf
jmp 0x416bf
jmp 0x416bf
jmp 0x416bf
jmp 0x416bf
jmp 0x416bf
jmp 0x416bf
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x2eb64
movq %rbx, %rdi
callq 0x8870