// File: /workspace/github_c_makefile_star2_O1/ToniWestbrook[P]paladin/bwt.c
// Function: bwt_2occ
void bwt_2occ(const bwt_t *bwt, bwtint_t k, bwtint_t l, ubyte_t c, bwtint_t *ok, bwtint_t *ol)
{
	bwtint_t _k, _l;
	_k = (k >= bwt->primary)? k-1 : k;
	_l = (l >= bwt->primary)? l-1 : l;
	if (_l/OCC_INTERVAL != _k/OCC_INTERVAL || k == (bwtint_t)(-1) || l == (bwtint_t)(-1)) {
		*ok = bwt_occ(bwt, k, c);
		*ol = bwt_occ(bwt, l, c);
	} else {
		bwtint_t m, n, i, j;
		uint32_t *p;
		if (k >= bwt->primary) --k;
		if (l >= bwt->primary) --l;
		//n = ((bwtint_t*)(p = bwt_occ_intv(bwt, k)))[c];
		n = ((bwtint_t*)(p = getOccInterval(bwt, k)))[c];
		p += sizeof(bwtint_t);
		// calculate *ok
		j = k >> 5 << 5;
		for (i = k/OCC_INTERVAL*OCC_INTERVAL; i < j; i += 32, p += 2)
			n += __occ_aux((uint64_t)p[0]<<32 | p[1], c);
		m = n;
		n += __occ_aux(((uint64_t)p[0]<<32 | p[1]) & ~((1ull<<((~k&31)<<1)) - 1), c);
		if (c == 0) n -= ~k&31; // corrected for the masked bits
		*ok = n;
		// calculate *ol
		j = l >> 5 << 5;
		for (; i < j; i += 32, p += 2)
			m += __occ_aux((uint64_t)p[0]<<32 | p[1], c);
		m += __occ_aux(((uint64_t)p[0]<<32 | p[1]) & ~((1ull<<((~l&31)<<1)) - 1), c);
		if (c == 0) m -= ~l&31; // corrected for the masked bits
		*ol = m;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %ecx, %ebp
movq %rdx, %r14
movq %rdi, %r12
movq (%rdi), %rax
cmpq %rax, %rsi
movq %rsi, %rcx
adcq $-0x1, %rcx
cmpq %rax, %rdx
adcq $-0x1, %rdx
cmpq $-0x1, %r14
je 0xf185
cmpq $-0x1, %rsi
je 0xf185
xorq %rcx, %rdx
cmpq $0x80, %rdx
jae 0xf185
cmpq %rax, %rsi
adcq $-0x1, %rsi
cmpq %rax, %r14
adcq $-0x1, %r14
leaq 0x7f(%rsi), %rcx
testq %rsi, %rsi
cmovnsq %rsi, %rcx
andq $-0x80, %rcx
leaq (%rcx,%rcx), %rdx
addq 0x120(%r12), %rdx
leaq (%rdx,%rcx), %rax
movzbl %bpl, %edi
movq (%rax,%rdi,8), %rax
addq %rcx, %rdx
addq $0x20, %rdx
movq %rsi, %rcx
andq $-0x20, %rcx
movq %rsi, %rdi
andq $-0x80, %rdi
cmpq %rcx, %rdi
jae 0xf09f
movl (%rdx), %r11d
movl 0x4(%rdx), %r10d
shlq $0x20, %r11
orq %r11, %r10
movq %r10, (%rsp)
xorl %r11d, %r11d
xorl %ebx, %ebx
xorl %r10d, %r10d
cmpb %bpl, (%rsp,%r11)
sete %r10b
addq %r10, %rbx
incq %r11
cmpq $0x8, %r11
jne 0xf07b
addq %rbx, %rax
addq $0x20, %rdi
addq $0x8, %rdx
jmp 0xf05f
movl (%rdx), %ecx
movl 0x4(%rdx), %r10d
shlq $0x20, %rcx
orq %rcx, %r10
notl %esi
andl $0x1f, %esi
movl %esi, %ecx
addl %esi, %ecx
shrq %cl, %r10
shlq %cl, %r10
movq %r10, (%rsp)
xorl %r11d, %r11d
xorl %ecx, %ecx
xorl %r10d, %r10d
cmpb %bpl, (%rsp,%r11)
sete %r10b
addq %r10, %rcx
incq %r11
cmpq $0x8, %r11
jne 0xf0c4
xorl %r10d, %r10d
testb %bpl, %bpl
cmoveq %rsi, %r10
movq %rax, %rsi
subq %r10, %rsi
addq %rcx, %rsi
movq %rsi, (%r8)
movq %r14, %rcx
andq $-0x20, %rcx
cmpq %rcx, %rdi
jae 0xf137
movl (%rdx), %esi
movl 0x4(%rdx), %r8d
shlq $0x20, %rsi
orq %rsi, %r8
movq %r8, (%rsp)
xorl %r8d, %r8d
xorl %esi, %esi
xorl %r10d, %r10d
cmpb %bpl, (%rsp,%r8)
sete %r10b
addq %r10, %rsi
incq %r8
cmpq $0x8, %r8
jne 0xf113
addq %rsi, %rax
addq $0x20, %rdi
addq $0x8, %rdx
jmp 0xf0f8
movl (%rdx), %ecx
movl 0x4(%rdx), %edx
shlq $0x20, %rcx
orq %rcx, %rdx
notl %r14d
andl $0x1f, %r14d
movl %r14d, %ecx
addl %r14d, %ecx
shrq %cl, %rdx
shlq %cl, %rdx
movq %rdx, (%rsp)
xorl %edx, %edx
xorl %ecx, %ecx
xorl %esi, %esi
cmpb %bpl, (%rsp,%rdx)
sete %sil
addq %rsi, %rcx
incq %rdx
cmpq $0x8, %rdx
jne 0xf15e
xorl %edx, %edx
testb %bpl, %bpl
cmoveq %r14, %rdx
subq %rdx, %rax
addq %rcx, %rax
jmp 0xf1d8
movq %r8, %rbx
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rsp, %r13
movq %rax, (%r13)
movq %r12, %rdi
movq %r13, %rdx
movq %r9, %r15
callq 0xedd1
movzbl %bpl, %ebp
shll $0x3, %ebp
movq (%rsp,%rbp), %rax
movq %rax, (%rbx)
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, (%r13)
movq %rsp, %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0xedd1
movq %r15, %r9
movq (%rsp,%rbp), %rax
movq %rax, (%r9)
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq