// File: /workspace/github_cpp_makefile_star2_O1/millanek[P]evo/process_vcf_fst.cpp
// Function: getVariantCountsForFst(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&, SetCounts*, std::vector<unsigned long, std::allocator<unsigned long>> const&, std::vector<unsigned long, std::allocator<unsigned long>> const&)
void getVariantCountsForFst(const std::vector<std::string>& fields, SetCounts* thisVariantCounts, const std::vector<size_t>& set1_loci, const std::vector<size_t>& set2_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);
    int n1 = (int)(set1_loci.size()*2); int n2 = (int)(set2_loci.size()*2);
    thisVariantCounts->set1HaplotypeVariant.assign(n1,0);
    thisVariantCounts->set2HaplotypeVariant.assign(n2,0);
    thisVariantCounts->set1_n_withoutMissing = n1;
    thisVariantCounts->set2_n_withoutMissing = n2;
    
    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 = 1;

        if (alleleAsMissing == 1) alt = 2;

        int set1i = 0; int set2i = 0; int set1hapI = 0; int set2hapI = 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->set1Count++; 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 = thisVariantCounts->set1_n_withoutMissing - 1;
            }
            if (v2int == alt) {
                thisVariantCounts->set1Count++; 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 = thisVariantCounts->set1_n_withoutMissing - 1;
            }
            set1i++; set1hapI = set1hapI+2;
        }
        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->set2Count++; thisVariantCounts->set2individualsWithVariant[set2i]++;
                thisVariantCounts->set2HaplotypeVariant[set2hapI]++;
            } else if (genotypes[i][0] == '.' || v1int == alleleAsMissing) {
                thisVariantCounts->missingGenotypesPerIndividual[i] = true;
                thisVariantCounts->set2_n_withoutMissing = thisVariantCounts->set2_n_withoutMissing - 1;
            }
            if (genotypes[i][2] - '0' == alt) {
                thisVariantCounts->set2Count++; thisVariantCounts->set2individualsWithVariant[set2i]++;
                thisVariantCounts->set2HaplotypeVariant[set2hapI+1]++;
            } else if (genotypes[i][2] == '.' || v2int == alleleAsMissing) {
                thisVariantCounts->missingGenotypesPerIndividual[i] = true;
                thisVariantCounts->set2_n_withoutMissing = thisVariantCounts->set2_n_withoutMissing - 1;
            }
            set2i++; set2hapI = set2hapI+2;
        }
        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 $0x58, %rsp
movq %rcx, %r12
movq %rdx, %r13
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %r15
subq (%rdi), %r15
movq %rsi, %rbx
shrq $0x5, %r15
leal -0x9(%r15), %eax
leaq 0x8(%rsi), %rdi
movslq %eax, %rbp
xorl %eax, %eax
leaq 0x18(%rsp), %r14
movl %eax, (%r14)
movq %rbp, %rsi
movq %r14, %rdx
callq 0x561e6
leaq 0x20(%rbx), %rdi
movq %rdi, 0x30(%rsp)
movq %rbp, %rsi
xorl %edx, %edx
callq 0x56642
leaq 0x48(%rbx), %rdi
leal -0x12(,%r15,2), %eax
movslq %eax, %rsi
xorl %ebp, %ebp
movl %ebp, (%r14)
leaq 0x18(%rsp), %r14
movq %r14, %rdx
callq 0x561e6
leaq 0x90(%rbx), %rdi
movq 0x8(%r13), %rsi
subq (%r13), %rsi
sarq $0x3, %rsi
movl %ebp, (%r14)
xorl %ebp, %ebp
leaq 0x18(%rsp), %r14
movq %r14, %rdx
callq 0x561e6
leaq 0xa8(%rbx), %rdi
movq 0x8(%r12), %rsi
subq (%r12), %rsi
sarq $0x3, %rsi
movl %ebp, (%r14)
leaq 0x18(%rsp), %r14
movq %r14, %rdx
callq 0x561e6
movq 0x8(%r13), %rax
movq %r13, 0x38(%rsp)
subq (%r13), %rax
shrq $0x2, %rax
andl $-0x2, %eax
movq 0x8(%r12), %r15
movq %r12, 0x10(%rsp)
subq (%r12), %r15
movq 0x8(%rsp), %r12
shrq $0x2, %r15
andl $-0x2, %r15d
leaq 0x60(%rbx), %rdi
movslq %eax, %rbp
xorl %r13d, %r13d
movl %r13d, (%r14)
leaq 0x18(%rsp), %r14
movq %rbp, %rsi
movq %r14, %rdx
callq 0x561e6
leaq 0x78(%rbx), %rdi
movslq %r15d, %r15
movl %r13d, (%r14)
leaq 0x18(%rsp), %rdx
movq %r15, %rsi
callq 0x561e6
movl %ebp, 0xc8(%rbx)
movl %r15d, 0xcc(%rbx)
movq (%r12), %rsi
subq $-0x80, %rsi
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movl $0x2c, %edx
callq 0x50624
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x5, %rax
movl %eax, 0xd0(%rbx)
movq (%r14), %rdi
movq 0x8(%r14), %rax
subq %rdi, %rax
shrq $0x5, %rax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %eax, %eax
jle 0x8dce5
xorl %r15d, %r15d
leaq 0x5ba40(%rip), %rbp     # 0xe96d6
xorl %r13d, %r13d
addq %r15, %rdi
movq %rbp, %rsi
callq 0x8160
testl %eax, %eax
jne 0x8dcb2
decl 0xd0(%rbx)
leal 0x1(%r13), %r14d
movq 0x18(%rsp), %rax
cmpq $0x2, 0x8(%rax,%r15)
jb 0x8dcc6
movb $0x1, 0xd4(%rbx)
incq %r13
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
subq %rdi, %rax
shrq $0x5, %rax
cltq
addq $0x20, %r15
cmpq %rax, %r13
jl 0x8dc99
cmpl $0x1, 0xd0(%rbx)
jne 0x8e045
xorl %ebp, %ebp
cmpl $0x1, %r14d
sete %r15b
movl $0x120, %esi            # imm = 0x120
addq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq 0x40(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x98644
movb %r15b, %bpl
incl %ebp
movq 0x38(%rsp), %rax
movq (%rax), %rdx
movq 0x8(%rax), %rsi
cmpq %rsi, %rdx
je 0x8de81
movq 0x40(%rsp), %rdi
xorl %r8d, %r8d
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
leaq 0x3f(%rax), %r13
xorl %r10d, %r10d
movq %rsi, 0x8(%rsp)
movq (%rdx,%r8), %rcx
movq %rcx, %rax
shlq $0x5, %rax
movq (%rdi,%rax), %r11
movsbl (%r11), %eax
leal -0x30(%rax), %r12d
movsbl 0x2(%r11), %r15d
cmpl %ebp, %r12d
jne 0x8dd8d
incl 0xc0(%rbx)
movq 0x90(%rbx), %rax
incl (%rax,%r10,2)
movq 0x60(%rbx), %rax
incl (%rax,%r8)
jmp 0x8ddf2
cmpb $0x2e, %al
je 0x8dd96
cmpl %r14d, %r12d
jne 0x8ddf2
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x20(%rbx), %rax
movq %rcx, %r12
andq %r13, %r12
movq %rdi, %rsi
movl %r14d, %edi
movq %r13, %r14
xorl %r13d, %r13d
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %r12
setbe %r13b
movl $0x1, %r12d
shlq %cl, %r12
orq %r12, -0x8(%rax,%r13,8)
movq %r14, %r13
movl %edi, %r14d
movq %rsi, %rdi
movq 0x8(%rsp), %rsi
decl 0xc8(%rbx)
addl $-0x30, %r15d
cmpl %ebp, %r15d
jne 0x8de17
incl 0xc0(%rbx)
movq 0x90(%rbx), %rax
incl (%rax,%r10,2)
movq 0x60(%rbx), %rax
incl 0x4(%rax,%r8)
jmp 0x8de68
cmpb $0x2e, 0x2(%r11)
je 0x8de23
cmpl %r14d, %r15d
jne 0x8de68
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x20(%rbx), %rax
movq %rcx, %r11
andq %r13, %r11
xorl %r15d, %r15d
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %r11
setbe %r15b
movl $0x1, %r11d
shlq %cl, %r11
orq %r11, -0x8(%rax,%r15,8)
decl 0xc8(%rbx)
addq $0x2, %r10
leaq (%rdx,%r8), %rax
addq $0x8, %rax
addq $0x8, %r8
cmpq %rsi, %rax
jne 0x8dd51
movq 0x10(%rsp), %rax
movq (%rax), %rdx
movq 0x8(%rax), %rsi
cmpq %rsi, %rdx
je 0x8e003
leaq 0xcc(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %r8
xorl %r9d, %r9d
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
addq $0x3f, %rax
movq %rax, 0x10(%rsp)
xorl %r11d, %r11d
movq (%rdx,%r9), %rcx
movq %rcx, %rax
shlq $0x5, %rax
movq (%r8,%rax), %r12
movsbl (%r12), %eax
leal -0x30(%rax), %r13d
movsbl 0x2(%r12), %r15d
cmpl %ebp, %r13d
jne 0x8df02
incl 0xc4(%rbx)
movq 0xa8(%rbx), %rax
incl (%rax,%r11,2)
movq 0x78(%rbx), %r13
addq %r9, %r13
movl $0x1, %eax
jmp 0x8df59
cmpb $0x2e, %al
je 0x8df0b
cmpl %r14d, %r13d
jne 0x8df5d
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
movq 0x30(%rsp), %rdi
addq (%rdi), %rax
movq %rcx, %r13
andq 0x10(%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 0x8(%rsp), %r13
addl %eax, (%r13)
movsbl 0x2(%r12), %eax
leal -0x30(%rax), %edi
cmpl %ebp, %edi
jne 0x8df8d
incl 0xc4(%rbx)
movq 0xa8(%rbx), %rax
incl (%rax,%r11,2)
movq 0x78(%rbx), %rax
addq %r9, %rax
addq $0x4, %rax
movl $0x1, %ecx
jmp 0x8dfe8
cmpb $0x2e, %al
je 0x8df9a
addl $-0x30, %r15d
cmpl %r14d, %r15d
jne 0x8dfea
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
movq 0x30(%rsp), %rdi
addq (%rdi), %rax
movq %rcx, %rdi
andq 0x10(%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 0x8(%rsp), %rax
addl %ecx, (%rax)
addq $0x2, %r11
leaq (%rdx,%r9), %rax
addq $0x8, %rax
addq $0x8, %r9
cmpq %rsi, %rax
jne 0x8dec0
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
subq %rax, %rcx
je 0x8e03b
sarq $0x5, %rcx
movq (%rax), %rdx
movsbl (%rdx), %esi
addl $-0x30, %esi
cmpl %ebp, %esi
jne 0x8e025
incl (%rbx)
movsbl 0x2(%rdx), %edx
addl $-0x30, %edx
cmpl %ebp, %edx
jne 0x8e032
incl (%rbx)
addq $0x20, %rax
decq %rcx
jne 0x8e016
leaq 0x40(%rsp), %rdi
callq 0x3123c
leaq 0x18(%rsp), %rdi
callq 0x3123c
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x3123c
movq %rbx, %rdi
callq 0x8840