// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/process_vcf_fst.cpp
// Function: getVariantCountsForPBS(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&, ThreeSetCounts*, 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&)
void getVariantCountsForPBS(const std::vector<std::string>& fields, ThreeSetCounts* thisVariantCounts, const std::vector<size_t>& set1_loci, const std::vector<size_t>& set2_loci, const std::vector<size_t>& set3_loci) {
    
    int numSamples = (int)fields.size()-NUM_NON_GENOTYPE_COLUMNS;
    thisVariantCounts->individualsWithVariant.assign(numSamples,0);
    thisVariantCounts->missingGenotypesPerIndividual.assign(numSamples,false);
    thisVariantCounts->haplotypesWithVariant.assign(numSamples*2,0);
    
    thisVariantCounts->set1individualsWithVariant.assign(set1_loci.size(),0);
    thisVariantCounts->set2individualsWithVariant.assign(set2_loci.size(),0);
    thisVariantCounts->set3individualsWithVariant.assign(set3_loci.size(),0);
    int n1 = (int)(set1_loci.size()*2); int n2 = (int)(set2_loci.size()*2); int n3 = (int)(set3_loci.size()*2);
    thisVariantCounts->set1HaplotypeVariant.assign(n1,0); thisVariantCounts->set2HaplotypeVariant.assign(n2,0); thisVariantCounts->set3HaplotypeVariant.assign(n3,0);
    thisVariantCounts->set1_n_withoutMissing = n1; thisVariantCounts->set2_n_withoutMissing = n2; thisVariantCounts->set3_n_withoutMissing = n3;
    
    std::vector<std::string> altAlleles = split(fields[4], ',');
    thisVariantCounts->n_alt_alleles = (int)altAlleles.size();
    int alleleAsMissing = -1;
    for (int i = 0; i < (int)altAlleles.size(); i++) {
        if (altAlleles[i] == "*") {
            thisVariantCounts->n_alt_alleles = thisVariantCounts->n_alt_alleles - 1;
            alleleAsMissing = i + 1;
        }
        if (altAlleles[i].length() > 1) {
            thisVariantCounts->bIndel = true;
        }
    }
    
    if (thisVariantCounts->n_alt_alleles == 1) {
        int alt = (alleleAsMissing == 1) ? 1 : 2;
        
        int set1i = 0; int set2i = 0; int set3i = 0; int set1hapI = 0; int set2hapI = 0; int set3hapI = 0;
        std::vector<std::string> genotypes(fields.begin()+NUM_NON_GENOTYPE_COLUMNS,fields.end());
        //std::cerr << fields[0] << "\t" << fields[1] << "\tgenotypes.size()" << genotypes.size() << std::endl;
        for (const size_t i : set1_loci) {
            int v1int = genotypes[i][0] - '0'; int v2int = genotypes[i][2] - '0';
            if (v1int == alt) {
                thisVariantCounts->set1AltCount++; thisVariantCounts->set1individualsWithVariant[set1i]++;
                thisVariantCounts->set1HaplotypeVariant[set1hapI]++;
            } else if (genotypes[i][0] == '.' || v1int == alleleAsMissing) {
                //std::cerr << fields[0] << "\t" << fields[1] << "\t" << genotypes[i][0] << "\t" << i << std::endl;
                thisVariantCounts->missingGenotypesPerIndividual[i] = true;
                thisVariantCounts->set1_n_withoutMissing--;
            }
            if (v2int == alt) {
                thisVariantCounts->set1AltCount++; thisVariantCounts->set1individualsWithVariant[set1i]++;
                thisVariantCounts->set1HaplotypeVariant[set1hapI+1]++;
            } else if (genotypes[i][2] == '.' || v2int == alleleAsMissing) {
                thisVariantCounts->missingGenotypesPerIndividual[i] = true;
                //std::cerr << fields[0] << "\t" << fields[1] << "\t" << genotypes[i][2] << std::endl;
                thisVariantCounts->set1_n_withoutMissing--;
            }
            set1i++; set1hapI = set1hapI+2;
        } thisVariantCounts->set1AltAF = (double)thisVariantCounts->set1AltCount/thisVariantCounts->set1_n_withoutMissing;
        for (const size_t i : set2_loci) {
            int v1int = genotypes[i][0] - '0'; int v2int = genotypes[i][2] - '0';
            if (genotypes[i][0] - '0' == alt) {
                thisVariantCounts->set2AltCount++; thisVariantCounts->set2individualsWithVariant[set2i]++;
                thisVariantCounts->set2HaplotypeVariant[set2hapI]++;
            } else if (genotypes[i][0] == '.' || v1int == alleleAsMissing) {
                thisVariantCounts->missingGenotypesPerIndividual[i] = true;
                thisVariantCounts->set2_n_withoutMissing--;
            }
            if (genotypes[i][2] - '0' == alt) {
                thisVariantCounts->set2AltCount++; thisVariantCounts->set2individualsWithVariant[set2i]++;
                thisVariantCounts->set2HaplotypeVariant[set2hapI+1]++;
            } else if (genotypes[i][2] == '.' || v2int == alleleAsMissing) {
                thisVariantCounts->missingGenotypesPerIndividual[i] = true;
                thisVariantCounts->set2_n_withoutMissing--;
            }
            set2i++; set2hapI = set2hapI+2;
        } thisVariantCounts->set2AltAF = (double)thisVariantCounts->set2AltCount/thisVariantCounts->set2_n_withoutMissing;
        for (const size_t i : set3_loci) {
            int v1int = genotypes[i][0] - '0'; int v2int = genotypes[i][2] - '0';
            if (genotypes[i][0] - '0' == alt) {
                thisVariantCounts->set3AltCount++; thisVariantCounts->set2individualsWithVariant[set2i]++;
                thisVariantCounts->set3HaplotypeVariant[set2hapI]++;
            } else if (genotypes[i][0] == '.' || v1int == alleleAsMissing) {
                thisVariantCounts->missingGenotypesPerIndividual[i] = true;
                thisVariantCounts->set3_n_withoutMissing--;
            }
            if (genotypes[i][2] - '0' == alt) {
                thisVariantCounts->set3AltCount++; thisVariantCounts->set3individualsWithVariant[set2i]++;
                thisVariantCounts->set3HaplotypeVariant[set2hapI+1]++;
            } else if (genotypes[i][2] == '.' || v2int == alleleAsMissing) {
                thisVariantCounts->missingGenotypesPerIndividual[i] = true;
                thisVariantCounts->set3_n_withoutMissing--;
            }
            set3i++; set3hapI = set3hapI+2;
        } thisVariantCounts->set3AltAF = (double)thisVariantCounts->set3AltCount/thisVariantCounts->set3_n_withoutMissing;
        for (std::vector<std::string>::size_type i = 0; i != genotypes.size(); i++) {
            if (genotypes[i][0] - '0' == alt)
                thisVariantCounts->overall++;
            if (genotypes[i][2] - '0' == alt)
                thisVariantCounts->overall++;
        }
    }
    // std::cerr << "got here" << std::endl;
    /*if (fields[1] == "13433") {
     std::cerr << thisVariantCounts.set1Count << std::endl;
     std::cerr << thisVariantCounts.set2Count << std::endl;
     print_vector(thisVariantCounts.set1individualsWithVariant, std::cerr);
     print_vector(thisVariantCounts.set2individualsWithVariant, std::cerr);
     } */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, %r13
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %r12
subq (%rdi), %r12
movq %rsi, %rbx
shrq $0x5, %r12
leal -0x9(%r12), %eax
leaq 0x50(%rsi), %rdi
movslq %eax, %r14
xorl %eax, %eax
leaq 0x20(%rsp), %rdx
movl %eax, (%rdx)
movq %r14, %rsi
callq 0x56106
leaq 0xb0(%rbx), %rdi
movq %rdi, 0x18(%rsp)
movq %r14, %rsi
xorl %edx, %edx
callq 0x5680c
leaq 0xe8(%rbx), %rdi
leal -0x12(,%r12,2), %eax
movslq %eax, %rsi
xorl %r12d, %r12d
leaq 0x20(%rsp), %rax
movl %r12d, (%rax)
leaq 0x20(%rsp), %r14
movq %r14, %rdx
callq 0x56106
leaq 0x68(%rbx), %rdi
movq 0x8(%r13), %rsi
subq (%r13), %rsi
sarq $0x3, %rsi
movl %r12d, (%r14)
xorl %r12d, %r12d
leaq 0x20(%rsp), %r14
movq %r14, %rdx
callq 0x56106
movl $0x80, %eax
leaq (%rbx,%rax), %rdi
movq 0x8(%r15), %rsi
subq (%r15), %rsi
sarq $0x3, %rsi
movl %r12d, (%r14)
leaq 0x20(%rsp), %r14
movq %r14, %rdx
callq 0x56106
leaq 0x98(%rbx), %rdi
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movl %r12d, (%r14)
leaq 0x20(%rsp), %r14
movq %r14, %rdx
callq 0x56106
movq 0x8(%r13), %rax
movq %r13, 0x40(%rsp)
subq (%r13), %rax
shrq $0x2, %rax
andl $-0x2, %eax
movq 0x8(%r15), %r13
movq %r15, 0x48(%rsp)
subq (%r15), %r13
shrq $0x2, %r13
andl $-0x2, %r13d
movq 0x8(%rbp), %r15
movq %rbp, 0x50(%rsp)
subq (%rbp), %r15
shrq $0x2, %r15
andl $-0x2, %r15d
leaq 0x100(%rbx), %rdi
movslq %eax, %r12
xorl %eax, %eax
movl %eax, (%r14)
leaq 0x20(%rsp), %r14
movq %r12, %rsi
movq %r14, %rdx
callq 0x56106
leaq 0x118(%rbx), %rdi
movslq %r13d, %rbp
xorl %eax, %eax
movl %eax, (%r14)
leaq 0x20(%rsp), %r14
movq %rbp, %rsi
movq %r14, %rdx
callq 0x56106
leaq 0x130(%rbx), %rdi
movslq %r15d, %r13
xorl %eax, %eax
movl %eax, (%r14)
leaq 0x20(%rsp), %rdx
movq %r13, %rsi
callq 0x56106
movl %r12d, 0xdc(%rbx)
movl %ebp, 0xe0(%rbx)
movl %r13d, 0xe4(%rbx)
movq 0x8(%rsp), %rax
movl $0x80, %esi
addq (%rax), %rsi
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl $0x2c, %edx
callq 0x4d650
movq (%r14), %rdi
movq 0x8(%r14), %rax
subq %rdi, %rax
shrq $0x5, %rax
movl %eax, 0xd8(%rbx)
testl %eax, %eax
jle 0x8d448
leaq 0xdc(%rbx), %r12
leaq 0xe4(%rbx), %rax
movq %rax, 0x38(%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
xorl %r13d, %r13d
leaq 0x5388e(%rip), %r15     # 0xe074e
xorl %r14d, %r14d
addq %r13, %rdi
movq %r15, %rsi
callq 0x8160
testl %eax, %eax
jne 0x8cee0
decl 0xd8(%rbx)
leal 0x1(%r14), %eax
movl %eax, 0x4(%rsp)
movq 0x20(%rsp), %rdi
cmpq $0x2, 0x8(%rdi,%r13)
jb 0x8cef1
movb $0x1, 0x5(%rbx)
incq %r14
movq 0x28(%rsp), %rax
subq %rdi, %rax
shrq $0x5, %rax
cltq
addq $0x20, %r13
cmpq %rax, %r14
jl 0x8cec3
cmpl $0x1, 0xd8(%rbx)
jne 0x8d448
cmpl $0x1, 0x4(%rsp)
setne %r14b
movl $0x120, %esi            # imm = 0x120
movq 0x8(%rsp), %rax
addq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x60(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x97bfe
xorl %eax, %eax
movb %r14b, %al
incl %eax
movl %eax, 0x8(%rsp)
movq 0x40(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdi
movq 0x60(%rsp), %rax
cmpq %rdi, %rsi
je 0x8d0ce
xorl %r8d, %r8d
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
leaq 0x3f(%rcx), %rbp
xorl %r10d, %r10d
movq %rsi, 0x58(%rsp)
movq (%rsi,%r8), %rcx
movq %rcx, %rdx
shlq $0x5, %rdx
movq (%rax,%rdx), %r11
movsbl (%r11), %edx
leal -0x30(%rdx), %r14d
movsbl 0x2(%r11), %r13d
cmpl 0x8(%rsp), %r14d
jne 0x8cfbe
incl 0x8(%rbx)
movq 0x68(%rbx), %rdx
incl (%rdx,%r10,2)
movq 0x100(%rbx), %r14
addq %r8, %r14
movl $0x1, %edx
jmp 0x8d02c
cmpb $0x2e, %dl
je 0x8cfca
cmpl 0x4(%rsp), %r14d
jne 0x8d02f
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
movq 0x18(%rsp), %r14
addq (%r14), %rdx
movq %rcx, %r14
andq %rbp, %r14
movq %rbp, %rsi
movq %rdi, %rbp
movq %r12, %rdi
xorl %r12d, %r12d
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %r14
setbe %r12b
movl $0x1, %r14d
shlq %cl, %r14
orq %r14, -0x8(%rdx,%r12,8)
movq %rdi, %r12
movq %rbp, %rdi
movq %rsi, %rbp
movq 0x58(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %r14
addl %edx, (%r14)
addl $-0x30, %r13d
cmpl 0x8(%rsp), %r13d
jne 0x8d05a
incl 0x8(%rbx)
movq 0x68(%rbx), %rcx
incl (%rcx,%r10,2)
movq 0x100(%rbx), %rcx
addq %r8, %rcx
addq $0x4, %rcx
movl $0x1, %edx
jmp 0x8d0b3
cmpb $0x2e, 0x2(%r11)
je 0x8d068
cmpl 0x4(%rsp), %r13d
jne 0x8d0b5
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
movq 0x18(%rsp), %r11
addq (%r11), %rdx
movq %rcx, %r11
andq %rbp, %r11
xorl %r14d, %r14d
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %r11
setbe %r14b
movl $0x1, %r11d
shlq %cl, %r11
orq %r11, -0x8(%rdx,%r14,8)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r12, %rcx
addl %edx, (%rcx)
addq $0x2, %r10
leaq (%rsi,%r8), %rcx
addq $0x8, %rcx
addq $0x8, %r8
cmpq %rdi, %rcx
jne 0x8cf7f
cvtsi2sdl 0x8(%rbx), %xmm0
cvtsi2sdl 0xdc(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rbx)
movq 0x48(%rsp), %rcx
movq (%rcx), %r15
movq 0x8(%rcx), %r8
cmpq %r8, %r15
je 0x8d251
xorl %r9d, %r9d
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
leaq 0x3f(%rcx), %rbp
xorl %esi, %esi
xorl %r11d, %r11d
movq (%r15,%r11,8), %rcx
movq %rcx, %rdx
shlq $0x5, %rdx
movq (%rax,%rdx), %r14
movsbl (%r14), %edx
leal -0x30(%rdx), %r13d
movsbl 0x2(%r14), %r12d
cmpl 0x8(%rsp), %r13d
jne 0x8d14d
incl 0xc(%rbx)
movq 0x80(%rbx), %rdx
incl (%rdx,%r11,4)
movq 0x118(%rbx), %rdx
incl (%rdx,%r11,8)
jmp 0x8d1ad
cmpb $0x2e, %dl
je 0x8d159
cmpl 0x4(%rsp), %r13d
jne 0x8d1ad
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq 0xb0(%rbx), %rdx
movq %rcx, %r13
andq %rbp, %r13
xorl %r10d, %r10d
movq %r8, %rdi
movq %rbp, %r8
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
cmpq %rbp, %r13
movq %r8, %rbp
movq %rdi, %r8
setbe %r10b
movl $0x1, %r13d
shlq %cl, %r13
orq %r13, -0x8(%rdx,%r10,8)
decl 0xe0(%rbx)
movsbl 0x2(%r14), %edx
leal -0x30(%rdx), %r10d
cmpl 0x8(%rsp), %r10d
jne 0x8d1d9
incl 0xc(%rbx)
movq 0x80(%rbx), %rcx
incl (%rcx,%r11,4)
movq 0x118(%rbx), %rcx
incl 0x4(%rcx,%r11,8)
jmp 0x8d231
cmpb $0x2e, %dl
je 0x8d1e9
addl $-0x30, %r12d
cmpl 0x4(%rsp), %r12d
jne 0x8d231
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq 0xb0(%rbx), %rdx
movq %rcx, %r10
andq %rbp, %r10
xorl %r14d, %r14d
movabsq $-0x8000000000000000, %r12 # imm = 0x8000000000000000
cmpq %r12, %r10
setbe %r14b
movl $0x1, %r10d
shlq %cl, %r10
orq %r10, -0x8(%rdx,%r14,8)
decl 0xe0(%rbx)
incq %r11
addl $0x2, %esi
leaq (%r15,%r9), %rcx
addq $0x8, %rcx
addq $0x8, %r9
cmpq %r8, %rcx
jne 0x8d10f
movl %r11d, %edi
jmp 0x8d255
xorl %esi, %esi
xorl %edi, %edi
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xe0(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rbx)
movq 0x50(%rsp), %rcx
movq (%rcx), %r8
movq 0x8(%rcx), %r15
cmpq %r15, %r8
je 0x8d3eb
movl %esi, %r10d
orl $0x1, %esi
shlq $0x2, %r10
shlq $0x2, %rsi
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
leaq 0x3f(%rcx), %rbp
movq (%r8), %rcx
movq %rcx, %rdx
shlq $0x5, %rdx
movq (%rax,%rdx), %r13
movsbl (%r13), %edx
leal -0x30(%rdx), %r14d
movsbl 0x2(%r13), %r12d
cmpl 0x8(%rsp), %r14d
jne 0x8d2e3
incl 0x10(%rbx)
movq 0x80(%rbx), %rdx
incl (%rdx,%rdi,4)
movq 0x130(%rbx), %r14
addq %r10, %r14
movl $0x1, %edx
jmp 0x8d34e
cmpb $0x2e, %dl
je 0x8d2ef
cmpl 0x4(%rsp), %r14d
jne 0x8d351
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
movq 0x18(%rsp), %r11
addq (%r11), %rdx
movq %rcx, %r14
andq %rbp, %r14
xorl %r11d, %r11d
movq %rdi, %r9
movq %r10, %rdi
movq %rbp, %r10
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
cmpq %rbp, %r14
movq %r10, %rbp
movq %rdi, %r10
movq %r9, %rdi
setbe %r11b
movl $0x1, %r14d
shlq %cl, %r14
orq %r14, -0x8(%rdx,%r11,8)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %r14
addl %edx, (%r14)
movsbl 0x2(%r13), %edx
leal -0x30(%rdx), %r11d
cmpl 0x8(%rsp), %r11d
jne 0x8d37f
incl 0x10(%rbx)
movq 0x98(%rbx), %rcx
incl (%rcx,%rdi,4)
movq 0x130(%rbx), %rcx
addq %rsi, %rcx
movl $0x1, %edx
jmp 0x8d3dc
cmpb $0x2e, %dl
je 0x8d38f
addl $-0x30, %r12d
cmpl 0x4(%rsp), %r12d
jne 0x8d3de
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
movq 0x18(%rsp), %r11
addq (%r11), %rdx
movq %rcx, %r11
andq %rbp, %r11
xorl %r14d, %r14d
movabsq $-0x8000000000000000, %r12 # imm = 0x8000000000000000
cmpq %r12, %r11
setbe %r14b
movl $0x1, %r11d
shlq %cl, %r11
orq %r11, -0x8(%rdx,%r14,8)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %rcx
addl %edx, (%rcx)
addq $0x8, %r8
cmpq %r15, %r8
jne 0x8d2a2
xorps %xmm0, %xmm0
cvtsi2sdl 0x10(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xe4(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rbx)
movq 0x68(%rsp), %rcx
subq %rax, %rcx
je 0x8d43e
sarq $0x5, %rcx
movq (%rax), %rdx
movsbl (%rdx), %esi
addl $-0x30, %esi
cmpl 0x8(%rsp), %esi
jne 0x8d426
incl (%rbx)
movsbl 0x2(%rdx), %edx
addl $-0x30, %edx
cmpl 0x8(%rsp), %edx
jne 0x8d435
incl (%rbx)
addq $0x20, %rax
decq %rcx
jne 0x8d415
leaq 0x60(%rsp), %rdi
callq 0x2e784
leaq 0x20(%rsp), %rdi
callq 0x2e784
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2e784
movq %rbx, %rdi
callq 0x8840