// File: /workspace/github_c_makefile_star2_O3/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
movq %r9, %rbx
movl %ecx, %ebp
movq %rdx, %r12
movq %rdi, %r15
movq (%rdi), %rax
cmpq %rax, %rsi
movq %rsi, %r14
adcq $-0x1, %r14
cmpq %rax, %rdx
movq %rdx, %rax
adcq $-0x1, %rax
cmpq $-0x1, %rdx
je 0xf4e3
cmpq $-0x1, %rsi
je 0xf4e3
movq %rax, %rcx
xorq %r14, %rcx
cmpq $0x80, %rcx
jae 0xf4e3
leaq 0x7f(%r14), %rcx
testq %r14, %r14
cmovnsq %r14, %rcx
andq $-0x80, %rcx
leaq (%rcx,%rcx), %rsi
addq 0x120(%r15), %rsi
leaq (%rsi,%rcx), %rdx
movzbl %bpl, %r9d
movq (%rdx,%r9,8), %rdx
addq %rcx, %rsi
addq $0x20, %rsi
movq %r14, %rcx
andq $-0x20, %rcx
movq %r14, %rdi
andq $-0x80, %rdi
cmpq %rcx, %rdi
jae 0xf374
movd %r9d, %xmm0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
movdqa 0x18e81(%rip), %xmm1    # 0x28190
movl (%rsi), %r10d
movl 0x4(%rsi), %r11d
shlq $0x20, %r10
orq %r10, %r11
movq %r11, (%rsp)
pxor %xmm2, %xmm2
xorl %r10d, %r10d
movzwl (%rsp,%r10), %r11d
movd %r11d, %xmm3
pcmpeqb %xmm0, %xmm3
punpcklbw %xmm3, %xmm3    # xmm3 = xmm3[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pshuflw $0xd4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,1,3,4,5,6,7]
pshufd $0xd4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,1,3]
pand %xmm1, %xmm3
paddq %xmm3, %xmm2
addq $0x2, %r10
cmpq $0x8, %r10
jne 0xf328
pshufd $0xee, %xmm2, %xmm3     # xmm3 = xmm2[2,3,2,3]
paddq %xmm2, %xmm3
movq %xmm3, %r10
addq %r10, %rdx
addq $0x20, %rdi
addq $0x8, %rsi
cmpq %rcx, %rdi
jb 0xf30f
movl (%rsi), %r10d
movl 0x4(%rsi), %r11d
shlq $0x20, %r10
orq %r10, %r11
notl %r14d
andl $0x1f, %r14d
movl %r14d, %ecx
addl %r14d, %ecx
shrq %cl, %r11
shlq %cl, %r11
movq %r11, (%rsp)
movd %r9d, %xmm0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pxor %xmm2, %xmm2
xorl %ecx, %ecx
movdqa 0x18de0(%rip), %xmm1    # 0x28190
movzwl (%rsp,%rcx), %r9d
movd %r9d, %xmm3
pcmpeqb %xmm0, %xmm3
punpcklbw %xmm3, %xmm3    # xmm3 = xmm3[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pshuflw $0xd4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,1,3,4,5,6,7]
pshufd $0xd4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,1,3]
pand %xmm1, %xmm3
paddq %xmm3, %xmm2
addq $0x2, %rcx
cmpq $0x8, %rcx
jne 0xf3b0
pshufd $0xee, %xmm2, %xmm3     # xmm3 = xmm2[2,3,2,3]
paddq %xmm2, %xmm3
xorl %ecx, %ecx
testb %bpl, %bpl
cmoveq %r14, %rcx
movq %xmm3, %r11
movq %rdx, %r9
subq %rcx, %r9
addq %r11, %r9
movq %r9, (%r8)
movq %rax, %rcx
andq $-0x20, %rcx
cmpq %rcx, %rdi
jae 0xf479
movl (%rsi), %r8d
movl 0x4(%rsi), %r9d
shlq $0x20, %r8
orq %r8, %r9
movq %r9, (%rsp)
pxor %xmm2, %xmm2
xorl %r8d, %r8d
movzwl (%rsp,%r8), %r9d
movd %r9d, %xmm3
pcmpeqb %xmm0, %xmm3
punpcklbw %xmm3, %xmm3    # xmm3 = xmm3[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pshuflw $0xd4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,1,3,4,5,6,7]
pshufd $0xd4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,1,3]
pand %xmm1, %xmm3
paddq %xmm3, %xmm2
addq $0x2, %r8
cmpq $0x8, %r8
jne 0xf426
pshufd $0xee, %xmm2, %xmm3     # xmm3 = xmm2[2,3,2,3]
paddq %xmm2, %xmm3
movq %xmm3, %r8
addq %r8, %rdx
addq $0x20, %rdi
addq $0x8, %rsi
cmpq %rcx, %rdi
jb 0xf40d
movl (%rsi), %r10d
shlq $0x20, %r10
movl 0x4(%rsi), %esi
orq %r10, %rsi
notl %eax
andl $0x1f, %eax
movl %eax, %ecx
addl %eax, %ecx
shrq %cl, %rsi
shlq %cl, %rsi
movq %rsi, (%rsp)
pxor %xmm2, %xmm2
xorl %ecx, %ecx
movzwl (%rsp,%rcx), %esi
movd %esi, %xmm3
pcmpeqb %xmm0, %xmm3
punpcklbw %xmm3, %xmm3    # xmm3 = xmm3[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pshuflw $0xd4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,1,3,4,5,6,7]
pshufd $0xd4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,1,3]
pand %xmm1, %xmm3
paddq %xmm3, %xmm2
addq $0x2, %rcx
cmpq $0x8, %rcx
jne 0xf498
xorl %ecx, %ecx
testb %bpl, %bpl
pshufd $0xee, %xmm2, %xmm0     # xmm0 = xmm2[2,3,2,3]
paddq %xmm2, %xmm0
movq %xmm0, %rsi
cmoveq %rax, %rcx
subq %rcx, %rdx
addq %rsi, %rdx
jmp 0xf530
movq %r8, %r14
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rsp, %r13
movq %rax, (%r13)
movq %r15, %rdi
movq %r13, %rdx
callq 0xf07c
movzbl %bpl, %ebp
shll $0x3, %ebp
movq (%rsp,%rbp), %rax
movq %rax, (%r14)
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, (%r13)
movq %rsp, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0xf07c
movq (%rsp,%rbp), %rdx
movq %rdx, (%rbx)
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq