// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %r8, %rbp
movq %rcx, %r12
movq %rdx, %r13
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi), %r14
subq (%rdi), %r14
movq %rsi, %rbx
shrq $0x5, %r14
leal -0x9(%r14), %eax
leaq 0x50(%rsi), %rdi
movslq %eax, %r15
xorl %eax, %eax
leaq 0x20(%rsp), %rdx
movl %eax, (%rdx)
movq %r15, %rsi
callq 0x561e6
leaq 0xb0(%rbx), %rdi
movq %rdi, 0x40(%rsp)
movq %r15, %rsi
xorl %edx, %edx
callq 0x56642
leaq 0xe8(%rbx), %rdi
leal -0x12(,%r14,2), %eax
movslq %eax, %rsi
xorl %r14d, %r14d
leaq 0x20(%rsp), %rax
movl %r14d, (%rax)
leaq 0x20(%rsp), %r15
movq %r15, %rdx
callq 0x561e6
leaq 0x68(%rbx), %rdi
movq 0x8(%r13), %rsi
subq (%r13), %rsi
sarq $0x3, %rsi
movl %r14d, (%r15)
xorl %r15d, %r15d
leaq 0x20(%rsp), %r14
movq %r14, %rdx
callq 0x561e6
movl $0x80, %eax
leaq (%rbx,%rax), %rdi
movq 0x8(%r12), %rsi
subq (%r12), %rsi
sarq $0x3, %rsi
movl %r15d, (%r14)
leaq 0x20(%rsp), %r14
movq %r14, %rdx
callq 0x561e6
leaq 0x98(%rbx), %rdi
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movl %r15d, (%r14)
leaq 0x20(%rsp), %rdx
callq 0x561e6
movq 0x8(%r13), %rax
movq %r13, 0x8(%rsp)
subq (%r13), %rax
shrq $0x2, %rax
andl $-0x2, %eax
movq 0x8(%r12), %r13
movq %r12, 0x60(%rsp)
subq (%r12), %r13
shrq $0x2, %r13
andl $-0x2, %r13d
movq 0x8(%rbp), %r15
movq %rbp, 0x38(%rsp)
subq (%rbp), %r15
shrq $0x2, %r15
andl $-0x2, %r15d
leaq 0x100(%rbx), %rdi
movslq %eax, %r14
xorl %eax, %eax
leaq 0x20(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x20(%rsp), %r12
movq %r14, %rsi
movq %r12, %rdx
callq 0x561e6
leaq 0x118(%rbx), %rdi
movslq %r13d, %rbp
xorl %eax, %eax
movl %eax, (%r12)
leaq 0x20(%rsp), %r12
movq %rbp, %rsi
movq %r12, %rdx
callq 0x561e6
leaq 0x130(%rbx), %rdi
movslq %r15d, %r13
xorl %eax, %eax
movl %eax, (%r12)
leaq 0x20(%rsp), %rdx
movq %r13, %rsi
callq 0x561e6
movl %r14d, 0xdc(%rbx)
movl %ebp, 0xe0(%rbx)
movl %r13d, 0xe4(%rbx)
movq 0x10(%rsp), %r13
movl $0x80, %esi
addq (%r13), %rsi
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl $0x2c, %edx
callq 0x50624
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x5, %rax
movl %eax, 0xd8(%rbx)
movq (%r14), %rdi
movq 0x8(%r14), %rax
subq %rdi, %rax
shrq $0x5, %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jle 0x8d5b5
xorl %r14d, %r14d
leaq 0x5c16e(%rip), %r15     # 0xe96d6
xorl %r12d, %r12d
addq %r14, %rdi
movq %r15, %rsi
callq 0x8160
testl %eax, %eax
jne 0x8d585
decl 0xd8(%rbx)
leal 0x1(%r12), %ebp
movq 0x20(%rsp), %rax
cmpq $0x2, 0x8(%rax,%r14)
jb 0x8d596
movb $0x1, 0x5(%rbx)
incq %r12
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
subq %rdi, %rax
shrq $0x5, %rax
cltq
addq $0x20, %r14
cmpq %rax, %r12
jl 0x8d56b
cmpl $0x1, 0xd8(%rbx)
jne 0x8dae7
xorl %r14d, %r14d
cmpl $0x1, %ebp
setne %r15b
movl $0x120, %esi            # imm = 0x120
addq (%r13), %rsi
movq 0x8(%r13), %rdx
leaq 0x48(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
callq 0x98644
movb %r15b, %r14b
incl %r14d
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x8(%rax), %rsi
cmpq %rsi, %rdx
je 0x8d764
leaq 0xdc(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %r8
xorl %r9d, %r9d
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
addq $0x3f, %rax
movq %rax, 0x8(%rsp)
xorl %r11d, %r11d
movq (%rdx,%r9), %rcx
movq %rcx, %rax
shlq $0x5, %rax
movq (%r8,%rax), %r15
movsbl (%r15), %r13d
leal -0x30(%r13), %eax
movsbl 0x2(%r15), %r12d
cmpl %r14d, %eax
jne 0x8d66a
incl 0x8(%rbx)
movq 0x68(%rbx), %rax
incl (%rax,%r11,2)
movq 0x100(%rbx), %r13
addq %r9, %r13
movl $0x1, %eax
jmp 0x8d6c2
cmpb $0x2e, %r13b
je 0x8d674
cmpl %ebp, %eax
jne 0x8d6c6
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
movq 0x40(%rsp), %rdi
addq (%rdi), %rax
movq %rcx, %r13
andq 0x8(%rsp), %r13
xorl %edi, %edi
movabsq $-0x8000000000000000, %r10 # imm = 0x8000000000000000
cmpq %r10, %r13
setbe %dil
movl $0x1, %r13d
shlq %cl, %r13
orq %r13, -0x8(%rax,%rdi,8)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %r13
addl %eax, (%r13)
addl $-0x30, %r12d
cmpl %r14d, %r12d
jne 0x8d6ef
incl 0x8(%rbx)
movq 0x68(%rbx), %rax
incl (%rax,%r11,2)
movq 0x100(%rbx), %rax
addq %r9, %rax
addq $0x4, %rax
movl $0x1, %ecx
jmp 0x8d749
cmpb $0x2e, 0x2(%r15)
je 0x8d6fb
cmpl %ebp, %r12d
jne 0x8d74b
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
movq 0x40(%rsp), %rdi
addq (%rdi), %rax
movq %rcx, %rdi
andq 0x8(%rsp), %rdi
xorl %r15d, %r15d
movabsq $-0x8000000000000000, %r10 # imm = 0x8000000000000000
cmpq %r10, %rdi
setbe %r15b
movl $0x1, %edi
shlq %cl, %rdi
orq %rdi, -0x8(%rax,%r15,8)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rax
addl %ecx, (%rax)
addq $0x2, %r11
leaq (%rdx,%r9), %rax
addq $0x8, %rax
addq $0x8, %r9
cmpq %rsi, %rax
jne 0x8d62d
cvtsi2sdl 0x8(%rbx), %xmm0
cvtsi2sdl 0xdc(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rbx)
movq 0x60(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdi
cmpq %rdi, %rsi
movl %ebp, 0x10(%rsp)
je 0x8d8eb
xorl %r8d, %r8d
movq 0x48(%rsp), %r9
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
addq $0x3f, %rax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
xorl %r11d, %r11d
movq (%rsi,%r11,8), %rcx
movq %rcx, %rax
shlq $0x5, %rax
movq (%r9,%rax), %r12
movsbl (%r12), %r13d
leal -0x30(%r13), %eax
movsbl 0x2(%r12), %r15d
cmpl %r14d, %eax
jne 0x8d7f1
incl 0xc(%rbx)
movq 0x80(%rbx), %rax
incl (%rax,%r11,4)
movq 0x118(%rbx), %rax
incl (%rax,%r11,8)
jmp 0x8d849
cmpb $0x2e, %r13b
je 0x8d7fb
cmpl %ebp, %eax
jne 0x8d849
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0xb0(%rbx), %rax
movq %rcx, %r13
andq 0x8(%rsp), %r13
xorl %r10d, %r10d
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
cmpq %rbp, %r13
movl 0x10(%rsp), %ebp
setbe %r10b
movl $0x1, %r13d
shlq %cl, %r13
orq %r13, -0x8(%rax,%r10,8)
decl 0xe0(%rbx)
movsbl 0x2(%r12), %eax
leal -0x30(%rax), %r10d
cmpl %r14d, %r10d
jne 0x8d874
incl 0xc(%rbx)
movq 0x80(%rbx), %rax
incl (%rax,%r11,4)
movq 0x118(%rbx), %rax
incl 0x4(%rax,%r11,8)
jmp 0x8d8cb
cmpb $0x2e, %al
je 0x8d881
addl $-0x30, %r15d
cmpl %ebp, %r15d
jne 0x8d8cb
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0xb0(%rbx), %rax
movq %rcx, %r10
andq 0x8(%rsp), %r10
xorl %r15d, %r15d
movabsq $-0x8000000000000000, %r12 # imm = 0x8000000000000000
cmpq %r12, %r10
setbe %r15b
movl $0x1, %r10d
shlq %cl, %r10
orq %r10, -0x8(%rax,%r15,8)
decl 0xe0(%rbx)
incq %r11
addl $0x2, %edx
leaq (%rsi,%r8), %rax
addq $0x8, %rax
addq $0x8, %r8
cmpq %rdi, %rax
jne 0x8d7b3
movl %r11d, %esi
jmp 0x8d8ef
xorl %edx, %edx
xorl %esi, %esi
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xe0(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rbx)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %r8
cmpq %r8, %rdi
je 0x8da87
leaq 0xe4(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %r10
movl %edx, %r11d
orl $0x1, %edx
shlq $0x2, %r11
shlq $0x2, %rdx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
addq $0x3f, %rax
movq %rax, 0x38(%rsp)
movq (%rdi), %rcx
movq %rcx, %rax
shlq $0x5, %rax
movq (%r10,%rax), %r13
movsbl (%r13), %eax
leal -0x30(%rax), %r9d
movsbl 0x2(%r13), %r12d
cmpl %r14d, %r9d
jne 0x8d991
incl 0x10(%rbx)
movq 0x80(%rbx), %rax
incl (%rax,%rsi,4)
movq 0x130(%rbx), %r9
addq %r11, %r9
movl $0x1, %eax
jmp 0x8d9ed
cmpb $0x2e, %al
je 0x8d99a
cmpl %ebp, %r9d
jne 0x8d9f0
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
movq 0x40(%rsp), %r9
addq (%r9), %rax
movq %rcx, %r9
andq 0x38(%rsp), %r9
xorl %r15d, %r15d
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
cmpq %rbp, %r9
movl 0x10(%rsp), %ebp
setbe %r15b
movl $0x1, %r9d
shlq %cl, %r9
orq %r9, -0x8(%rax,%r15,8)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %r9
addl %eax, (%r9)
movsbl 0x2(%r13), %eax
leal -0x30(%rax), %r9d
cmpl %r14d, %r9d
jne 0x8da1c
incl 0x10(%rbx)
movq 0x98(%rbx), %rax
incl (%rax,%rsi,4)
movq 0x130(%rbx), %rcx
addq %rdx, %rcx
movl $0x1, %eax
jmp 0x8da78
cmpb $0x2e, %al
je 0x8da29
addl $-0x30, %r12d
cmpl %ebp, %r12d
jne 0x8da7a
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
movq 0x40(%rsp), %r9
addq (%r9), %rax
movq %rcx, %r9
andq 0x38(%rsp), %r9
xorl %r15d, %r15d
movabsq $-0x8000000000000000, %r12 # imm = 0x8000000000000000
cmpq %r12, %r9
setbe %r15b
movl $0x1, %r9d
shlq %cl, %r9
orq %r9, -0x8(%rax,%r15,8)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rcx
addl %eax, (%rcx)
addq $0x8, %rdi
cmpq %r8, %rdi
jne 0x8d952
xorps %xmm0, %xmm0
cvtsi2sdl 0x10(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xe4(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rbx)
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
subq %rax, %rcx
je 0x8dadd
sarq $0x5, %rcx
movq (%rax), %rdx
movsbl (%rdx), %esi
addl $-0x30, %esi
cmpl %r14d, %esi
jne 0x8dac6
incl (%rbx)
movsbl 0x2(%rdx), %edx
addl $-0x30, %edx
cmpl %r14d, %edx
jne 0x8dad4
incl (%rbx)
addq $0x20, %rax
decq %rcx
jne 0x8dab6
leaq 0x48(%rsp), %rdi
callq 0x3123c
leaq 0x20(%rsp), %rdi
callq 0x3123c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3123c
movq %rbx, %rdi
callq 0x8840