// File: /workspace/github_cpp_makefile_star2_O2/BenLangmead[P]bowtie/./ebwt.h
// Function: Ebwt::countUpTo(SideLocus const&, int) const
inline TIndexOffU Ebwt::countUpTo(const SideLocus& l, int c) const {
	// Count occurrences of c in each 64-bit (using bit trickery);
	// Someday countInU64() and pop() functions should be
	// vectorized/SSE-ized in case that helps.
	TIndexOffU cCnt = 0;
	const uint8_t *side = l.side(this->_ebwt);
	int i = 0;
#if 1
    #ifdef POPCNT_CAPABILITY
    if ( _usePOPCNTinstruction) {
        for(; i + 7 < l._by; i += 8) {
            cCnt += countInU64<USE_POPCNT_INSTRUCTION>(c, *(uint64_t*)&side[i]);
        }
    }
    else {
        for(; i + 7 < l._by; i += 8) {
            cCnt += countInU64<USE_POPCNT_GENERIC>(c, *(uint64_t*)&side[i]);
        }
    }
    #else
    for(; i + 7 < l._by; i += 8) {
        cCnt += countInU64(c, *(uint64_t*)&side[i]);
    }
    #endif
#else
	for(; i + 2 < l._by; i += 2) {
		cCnt += cCntLUT_16b_4[c][*(uint16_t*)&side[i]];
	}
#endif
#ifdef SIXTY4_FORMAT
	// Calculate number of bit pairs to shift off the end
	const int bpShiftoff = 32 - (((l._by & 7) << 2) + l._bp);
	if(bpShiftoff < 32) {
		assert_lt(bpShiftoff, 32);
		const uint64_t sw = (*(uint64_t*)&side[i]) << (bpShiftoff << 1);

        #ifdef POPCNT_CAPABILITY
        if (_usePOPCNTinstruction) {
            cCnt += countInU64<USE_POPCNT_INSTRUCTION>(c, sw);
        }
        else {
            cCnt += countInU64<USE_POPCNT_GENERIC>(c, sw);
        }
        #else
		cCnt += countInU64(c, sw);
        #endif

		if(c == 0) cCnt -= bpShiftoff; // we turned these into As
	}
#else
	// Count occurences of c in the rest of the side (using LUT)
	for(; i < l._by; i++) {
		cCnt += cCntLUT_4[0][c][side[i]];
	}
	// Count occurences of c in the rest of the byte
	if(l._bp > 0) {
		cCnt += cCntLUT_4[(int)l._bp][c][side[i]];
	}
#endif
	return cCnt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movabsq $0x5555555555555555, %rbp # imm = 0x5555555555555555
movq 0xc8(%rdi), %r15
addq (%rsi), %r15
cmpb $0x0, (%rdi)
je 0x1734d
movswq 0x14(%r14), %rax
movslq %edx, %r12
xorl %r13d, %r13d
leaq 0x14de3(%rip), %rcx     # 0x2c100
xorl %ebx, %ebx
leaq 0x7(%r13), %rdx
cmpq %rax, %rdx
jge 0x1738e
movq (%rcx,%r12,8), %rdx
xorq (%r15,%r13), %rdx
movq %rdx, %rdi
shrq %rdi
andq %rbp, %rdx
andq %rdi, %rdx
popcntq %rdx, %rdi
movslq %edi, %rdx
addq %rdx, %rbx
addq $0x8, %r13
jmp 0x1731f
movslq %edx, %r12
xorl %r13d, %r13d
xorl %ebx, %ebx
leaq 0x7(%r13), %rcx
movswq 0x14(%r14), %rax
cmpq %rax, %rcx
jge 0x1738e
leaq 0x14d96(%rip), %rax     # 0x2c100
movq (%rax,%r12,8), %rdi
xorq (%r15,%r13), %rdi
movq %rdi, %rax
shrq %rax
andq %rbp, %rdi
andq %rax, %rdi
callq 0x173ec
cltq
addq %rax, %rbx
addq $0x8, %r13
jmp 0x17355
andl $-0x8, %r13d
shlq $0x8, %r12
leaq 0x1d183(%rip), %rcx     # 0x34520
addq %r12, %rcx
cmpq %rax, %r13
jge 0x173b6
movzbl (%r15,%r13), %edx
movzbl (%rdx,%rcx), %edx
addq %rdx, %rbx
incq %r13
jmp 0x173a0
movsbq 0x16(%r14), %rax
testq %rax, %rax
jle 0x173da
shlq $0xa, %rax
addq 0x1cc0d(%rip), %rax     # 0x33fd8
movzbl (%r15,%r13), %ecx
addq %r12, %rax
movzbl (%rcx,%rax), %eax
addq %rax, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq