// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %r8, 0x70(%rsp)
movq %rcx, %r14
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi), %r13
subq (%rdi), %r13
shrq $0x5, %r13
leal -0x9(%r13), %eax
leaq 0x50(%rsi), %rdi
movslq %eax, %r15
leaq 0x40(%rsp), %rdx
andl $0x0, (%rdx)
movq %r15, %rsi
callq 0x44dfe
leaq 0xb0(%rbx), %rdi
xorl %r12d, %r12d
movq %rdi, 0x30(%rsp)
movq %r15, %rsi
xorl %edx, %edx
callq 0x452c4
leaq 0xe8(%rbx), %rdi
leal -0x12(,%r13,2), %eax
movslq %eax, %rsi
leaq 0x40(%rsp), %rax
andl $0x0, (%rax)
leaq 0x40(%rsp), %r15
movq %r15, %rdx
callq 0x44dfe
leaq 0x68(%rbx), %rdi
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
andl $0x0, (%r15)
leaq 0x40(%rsp), %r15
movq %r15, %rdx
callq 0x44dfe
movl $0x80, %eax
leaq (%rbx,%rax), %rdi
movq 0x8(%r14), %rsi
subq (%r14), %rsi
sarq $0x3, %rsi
andl $0x0, (%r15)
leaq 0x40(%rsp), %r15
movq %r15, %rdx
callq 0x44dfe
leaq 0x98(%rbx), %rdi
movq 0x70(%rsp), %r13
movq 0x8(%r13), %rsi
subq (%r13), %rsi
sarq $0x3, %rsi
andl $0x0, (%r15)
leaq 0x40(%rsp), %rdx
callq 0x44dfe
movq 0x8(%rbp), %rax
movq %rbp, 0x18(%rsp)
subq (%rbp), %rax
shrq $0x2, %rax
andl $-0x2, %eax
movq 0x8(%r14), %r15
movq %r14, 0x80(%rsp)
subq (%r14), %r15
shrq $0x2, %r15
movq 0x8(%r13), %r14
subq (%r13), %r14
andl $-0x2, %r15d
shrq $0x2, %r14
andl $-0x2, %r14d
leaq 0x100(%rbx), %rdi
movslq %eax, %rbp
leaq 0x40(%rsp), %rax
andl $0x0, (%rax)
leaq 0x40(%rsp), %rdx
movq %rbp, %rsi
callq 0x44dfe
leaq 0x118(%rbx), %rdi
movslq %r15d, %r13
leaq 0x40(%rsp), %rax
andl $0x0, (%rax)
leaq 0x40(%rsp), %r15
movq %r13, %rsi
movq %r15, %rdx
callq 0x44dfe
leaq 0x130(%rbx), %rdi
movslq %r14d, %r14
andl $0x0, (%r15)
leaq 0x40(%rsp), %rdx
movq %r14, %rsi
callq 0x44dfe
leaq 0xdc(%rbx), %rax
movq %rax, 0x28(%rsp)
movl %ebp, 0xdc(%rbx)
movl %r13d, 0xe0(%rbx)
movq 0x10(%rsp), %r13
leaq 0xe4(%rbx), %rax
movq %rax, 0x78(%rsp)
movl %r14d, 0xe4(%rbx)
movl $0x80, %esi
addq (%r13), %rsi
leaq 0x40(%rsp), %r14
pushq $0x2c
popq %rdx
movq %r14, %rdi
callq 0x40349
movq (%r14), %rdi
movq 0x8(%r14), %rax
movq %rax, %rcx
subq %rdi, %rcx
shrq $0x5, %rcx
movl %ecx, 0xd8(%rbx)
pushq $-0x1
popq %rcx
movl %ecx, 0xc(%rsp)
leaq 0x47132(%rip), %r15     # 0xb19a6
xorl %r14d, %r14d
subq %rdi, %rax
shrq $0x5, %rax
cltq
cmpq %rax, %r14
jge 0x6a8c1
addq %r12, %rdi
movq %r15, %rsi
callq 0x2193f
testb %al, %al
je 0x6a8a2
decl 0xd8(%rbx)
leal 0x1(%r14), %eax
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %rdi
cmpq $0x2, 0x8(%rdi,%r12)
jb 0x6a8b3
movb $0x1, 0x5(%rbx)
incq %r14
movq 0x48(%rsp), %rax
addq $0x20, %r12
jmp 0x6a877
cmpl $0x1, 0xd8(%rbx)
jne 0x6ac82
xorl %r14d, %r14d
cmpl $0x1, 0xc(%rsp)
setne %bpl
movl $0x120, %esi            # imm = 0x120
addq (%r13), %rsi
movq 0x8(%r13), %rdx
leaq 0x58(%rsp), %rdi
leaq 0x27(%rsp), %rcx
callq 0x70cd4
movb %bpl, %r14b
incl %r14d
movl %r14d, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x38(%rsp), %rax
addq %rbp, %rax
cmpq 0x18(%rsp), %rax
je 0x6a9f6
movq (%rax), %r13
movq 0x58(%rsp), %rax
movq %r13, %r15
shlq $0x5, %r15
movq (%rax,%r15), %rdx
movsbl (%rdx), %ecx
leal -0x30(%rcx), %eax
movsbl 0x2(%rdx), %r14d
cmpl 0x10(%rsp), %eax
jne 0x6a96c
incl 0x8(%rbx)
movq 0x68(%rbx), %rax
incl (%rax,%r12,2)
movq 0x100(%rbx), %rax
addq %rbp, %rax
pushq $0x1
jmp 0x6a98e
cmpb $0x2e, %cl
je 0x6a977
cmpl 0xc(%rsp), %eax
jne 0x6a991
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x439c0
orq %rdx, (%rax)
movq 0x28(%rsp), %rax
pushq $-0x1
popq %rcx
addl %ecx, (%rax)
addl $-0x30, %r14d
cmpl 0x10(%rsp), %r14d
jne 0x6a9b9
incl 0x8(%rbx)
movq 0x68(%rbx), %rax
incl (%rax,%r12,2)
movq 0x100(%rbx), %rax
addq %rbp, %rax
addq $0x4, %rax
pushq $0x1
jmp 0x6a9e6
movq 0x58(%rsp), %rax
movq (%rax,%r15), %rax
cmpb $0x2e, 0x2(%rax)
je 0x6a9cf
cmpl 0xc(%rsp), %r14d
jne 0x6a9e9
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x439c0
orq %rdx, (%rax)
movq 0x28(%rsp), %rax
pushq $-0x1
popq %rcx
addl %ecx, (%rax)
addq $0x2, %r12
addq $0x8, %rbp
jmp 0x6a91c
cvtsi2sdl 0x8(%rbx), %xmm0
cvtsi2sdl 0xdc(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rbx)
movq 0x80(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movq $0x0, 0x38(%rsp)
movq %rcx, 0x28(%rsp)
leaq (%rcx,%r13), %rax
cmpq 0x18(%rsp), %rax
je 0x6ab0d
movq (%rcx,%rbp,8), %r12
movq 0x58(%rsp), %rax
movq %r12, %r15
shlq $0x5, %r15
movq (%rax,%r15), %rax
movsbl (%rax), %edx
leal -0x30(%rdx), %ecx
movsbl 0x2(%rax), %r14d
cmpl 0x10(%rsp), %ecx
jne 0x6aa80
incl 0xc(%rbx)
movq 0x80(%rbx), %rcx
incl (%rcx,%rbp,4)
movq 0x118(%rbx), %rcx
incl (%rcx,%rbp,8)
jmp 0x6aaaa
cmpb $0x2e, %dl
je 0x6aa8b
cmpl 0xc(%rsp), %ecx
jne 0x6aaaa
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x439c0
orq %rdx, (%rax)
decl 0xe0(%rbx)
movq 0x58(%rsp), %rax
movq (%rax,%r15), %rax
movsbl 0x2(%rax), %eax
leal -0x30(%rax), %ecx
cmpl 0x10(%rsp), %ecx
jne 0x6aad1
incl 0xc(%rbx)
movq 0x80(%rbx), %rax
incl (%rax,%rbp,4)
movq 0x118(%rbx), %rax
incl 0x4(%rax,%rbp,8)
jmp 0x6aaf6
cmpb $0x2e, %al
je 0x6aae0
addl $-0x30, %r14d
cmpl 0xc(%rsp), %r14d
jne 0x6aaf6
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x439c0
orq %rdx, (%rax)
decl 0xe0(%rbx)
incq %rbp
addq $0x2, 0x38(%rsp)
addq $0x8, %r13
movq 0x28(%rsp), %rcx
jmp 0x6aa33
cvtsi2sdl 0xc(%rbx), %xmm0
cvtsi2sdl 0xe0(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rbx)
movq 0x70(%rsp), %rax
movq (%rax), %r12
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movl %ebp, %ebp
movq 0x38(%rsp), %rcx
andl $-0x2, %ecx
movq %rcx, 0x38(%rsp)
leaq 0x1(%rcx), %rax
shlq $0x2, %rax
movq %rax, 0x28(%rsp)
cmpq 0x18(%rsp), %r12
je 0x6ac25
movq (%r12), %r13
movq 0x58(%rsp), %rax
movq %r13, %r15
shlq $0x5, %r15
movq (%rax,%r15), %rax
movsbl (%rax), %edx
leal -0x30(%rdx), %ecx
movsbl 0x2(%rax), %r14d
cmpl 0x10(%rsp), %ecx
jne 0x6ab9e
incl 0x10(%rbx)
movq 0x80(%rbx), %rcx
incl (%rcx,%rbp,4)
movq 0x130(%rbx), %rcx
movq 0x38(%rsp), %rdx
incl (%rcx,%rdx,4)
jmp 0x6abc9
cmpb $0x2e, %dl
je 0x6aba9
cmpl 0xc(%rsp), %ecx
jne 0x6abc9
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x439c0
orq %rdx, (%rax)
movq 0x78(%rsp), %rax
decl (%rax)
movq 0x58(%rsp), %rax
movq (%rax,%r15), %rax
movsbl 0x2(%rax), %eax
leal -0x30(%rax), %ecx
cmpl 0x10(%rsp), %ecx
jne 0x6abf3
incl 0x10(%rbx)
movq 0x98(%rbx), %rax
incl (%rax,%rbp,4)
movq 0x130(%rbx), %rax
addq 0x28(%rsp), %rax
pushq $0x1
jmp 0x6ac19
cmpb $0x2e, %al
je 0x6ac02
addl $-0x30, %r14d
cmpl 0xc(%rsp), %r14d
jne 0x6ac1c
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x439c0
orq %rdx, (%rax)
movq 0x78(%rsp), %rax
pushq $-0x1
popq %rcx
addl %ecx, (%rax)
addq $0x8, %r12
jmp 0x6ab50
cvtsi2sdl 0x10(%rbx), %xmm0
cvtsi2sdl 0xe4(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rbx)
movq 0x58(%rsp), %rax
movq 0x60(%rsp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movl 0x10(%rsp), %edi
subq $0x1, %rcx
jb 0x6ac78
movq (%rax), %rdx
movsbl (%rdx), %esi
addl $-0x30, %esi
cmpl %edi, %esi
jne 0x6ac65
incl (%rbx)
movsbl 0x2(%rdx), %edx
addl $-0x30, %edx
cmpl %edi, %edx
jne 0x6ac72
incl (%rbx)
addq $0x20, %rax
jmp 0x6ac50
leaq 0x58(%rsp), %rdi
callq 0x28a08
leaq 0x40(%rsp), %rdi
callq 0x28a08
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x6acba
jmp 0x6acad
jmp 0x6acad
jmp 0x6acad
jmp 0x6acad
jmp 0x6acad
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x28a08
leaq 0x40(%rsp), %rdi
callq 0x28a08
movq %rbx, %rdi
callq 0x8870