// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %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 0x56106
leaq 0x20(%rbx), %rdi
movq %rdi, 0x38(%rsp)
movq %rbp, %rsi
xorl %edx, %edx
callq 0x5680c
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 0x56106
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 0x56106
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 0x56106
movq 0x8(%r13), %rax
movq %r13, 0x40(%rsp)
subq (%r13), %rax
shrq $0x2, %rax
andl $-0x2, %eax
movq 0x8(%r12), %r15
movq %r12, 0x48(%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 0x56106
leaq 0x78(%rbx), %rdi
movslq %r15d, %r15
movl %r13d, (%r14)
leaq 0x18(%rsp), %rdx
movq %r15, %rsi
callq 0x56106
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 0x4d650
movq (%r14), %rdi
movq 0x8(%r14), %rax
subq %rdi, %rax
shrq $0x5, %rax
movl %eax, 0xd0(%rbx)
testl %eax, %eax
jle 0x8d988
leaq 0xcc(%rbx), %rax
movq %rax, 0x30(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
leaq 0x53152(%rip), %rbp     # 0xe074e
xorl %r14d, %r14d
addq %r13, %rdi
movq %rbp, %rsi
callq 0x8160
testl %eax, %eax
jne 0x8d618
decl 0xd0(%rbx)
leal 0x1(%r14), %r15d
movq 0x18(%rsp), %rdi
cmpq $0x2, 0x8(%rdi,%r13)
jb 0x8d62c
movb $0x1, 0xd4(%rbx)
incq %r14
movq 0x20(%rsp), %rax
subq %rdi, %rax
shrq $0x5, %rax
cltq
addq $0x20, %r13
cmpq %rax, %r14
jl 0x8d5ff
cmpl $0x1, 0xd0(%rbx)
jne 0x8d988
xorl %ebp, %ebp
cmpl $0x1, %r15d
sete %r14b
movl $0x120, %esi            # imm = 0x120
addq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq 0x50(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x97bfe
movb %r14b, %bpl
incl %ebp
movq 0x40(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdi
movq 0x50(%rsp), %rax
cmpq %rdi, %rsi
je 0x8d7cf
xorl %r8d, %r8d
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
addq $0x3f, %rcx
movq %rcx, 0x8(%rsp)
xorl %r10d, %r10d
movq (%rsi,%r8), %rcx
movq %rcx, %r11
shlq $0x5, %r11
movq (%rax,%r11), %r11
movsbl (%r11), %r13d
leal -0x30(%r13), %r14d
movsbl 0x2(%r11), %r12d
cmpl %ebp, %r14d
jne 0x8d6ee
incl 0xc0(%rbx)
movq 0x90(%rbx), %r14
incl (%r14,%r10,2)
movq 0x60(%rbx), %r14
incl (%r14,%r8)
jmp 0x8d73e
cmpb $0x2e, %r13b
je 0x8d6f9
cmpl %r15d, %r14d
jne 0x8d73e
leaq 0x3f(%rcx), %r14
testq %rcx, %rcx
cmovnsq %rcx, %r14
sarq $0x6, %r14
shlq $0x3, %r14
addq 0x20(%rbx), %r14
movq %rcx, %r13
andq 0x8(%rsp), %r13
xorl %edx, %edx
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %r13
setbe %dl
movl $0x1, %r13d
shlq %cl, %r13
orq %r13, -0x8(%r14,%rdx,8)
decl 0xc8(%rbx)
addl $-0x30, %r12d
cmpl %ebp, %r12d
jne 0x8d763
incl 0xc0(%rbx)
movq 0x90(%rbx), %rcx
incl (%rcx,%r10,2)
movq 0x60(%rbx), %rcx
incl 0x4(%rcx,%r8)
jmp 0x8d7b6
cmpb $0x2e, 0x2(%r11)
je 0x8d76f
cmpl %r15d, %r12d
jne 0x8d7b6
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq 0x20(%rbx), %rdx
movq %rcx, %r11
andq 0x8(%rsp), %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)
decl 0xc8(%rbx)
addq $0x2, %r10
leaq (%rsi,%r8), %rcx
addq $0x8, %rcx
addq $0x8, %r8
cmpq %rdi, %rcx
jne 0x8d6b2
movq 0x48(%rsp), %rcx
movq (%rcx), %rsi
movq 0x8(%rcx), %rdi
cmpq %rdi, %rsi
je 0x8d94b
xorl %r8d, %r8d
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
addq $0x3f, %rcx
movq %rcx, 0x8(%rsp)
xorl %r10d, %r10d
movq (%rsi,%r8), %rcx
movq %rcx, %rdx
shlq $0x5, %rdx
movq (%rax,%rdx), %r12
movsbl (%r12), %r13d
leal -0x30(%r13), %r14d
movsbl 0x2(%r12), %r11d
cmpl %ebp, %r14d
jne 0x8d840
incl 0xc4(%rbx)
movq 0xa8(%rbx), %rdx
incl (%rdx,%r10,2)
movq 0x78(%rbx), %r14
addq %r8, %r14
movl $0x1, %r13d
jmp 0x8d89b
cmpb $0x2e, %r13b
je 0x8d84b
cmpl %r15d, %r14d
jne 0x8d89e
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
movq 0x38(%rsp), %r14
addq (%r14), %rdx
movq %rcx, %r14
andq 0x8(%rsp), %r14
xorl %r13d, %r13d
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %r14
setbe %r13b
movl $0x1, %r14d
shlq %cl, %r14
orq %r14, -0x8(%rdx,%r13,8)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq 0x30(%rsp), %r14
addl %r13d, (%r14)
movsbl 0x2(%r12), %r14d
leal -0x30(%r14), %edx
cmpl %ebp, %edx
jne 0x8d8d0
incl 0xc4(%rbx)
movq 0xa8(%rbx), %rcx
incl (%rcx,%r10,2)
movq 0x78(%rbx), %rcx
addq %r8, %rcx
addq $0x4, %rcx
movl $0x1, %r11d
jmp 0x8d92f
cmpb $0x2e, %r14b
je 0x8d8df
addl $-0x30, %r11d
cmpl %r15d, %r11d
jne 0x8d932
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
movq 0x38(%rsp), %r11
addq (%r11), %rdx
movq %rcx, %r11
andq 0x8(%rsp), %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, %r11d      # imm = 0xFFFFFFFF
movq 0x30(%rsp), %rcx
addl %r11d, (%rcx)
addq $0x2, %r10
leaq (%rsi,%r8), %rcx
addq $0x8, %rcx
addq $0x8, %r8
cmpq %rdi, %rcx
jne 0x8d7fd
movq 0x58(%rsp), %rcx
subq %rax, %rcx
je 0x8d97e
sarq $0x5, %rcx
movq (%rax), %rdx
movsbl (%rdx), %esi
addl $-0x30, %esi
cmpl %ebp, %esi
jne 0x8d968
incl (%rbx)
movsbl 0x2(%rdx), %edx
addl $-0x30, %edx
cmpl %ebp, %edx
jne 0x8d975
incl (%rbx)
addq $0x20, %rax
decq %rcx
jne 0x8d959
leaq 0x50(%rsp), %rdi
callq 0x2e784
leaq 0x18(%rsp), %rdi
callq 0x2e784
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2e784
movq %rbx, %rdi
callq 0x8840