// File: /workspace/github_c_makefile_star2_O1/lh3[P]fermi-lite/rld0.c
// Function: rld_rank2a
void rld_rank2a(const rld_t *e, uint64_t k, uint64_t l, uint64_t *ok, uint64_t *ol)
{
	uint64_t z, y, len;
	rlditr_t itr;
	int a = -1;
	if (k == 0) {
		for (a = 0; a < e->asize; ++a) ok[a] = 0;
		rld_rank1a(e, l, ol);
		return;
	}
	y = rld_locate_blk(e, &itr, k-1, ok, &z); // locate the block bracketing k
	while (1) { // compute ok[]
#ifdef _DNA_ONLY
		len = rld_dec0_fast_dna(e, &itr, &a);
#else
		len = rld_dec0(e, &itr, &a);
#endif
		if (z + len >= k) break;
		z += len; ok[a] += len;
	}
	if (y > l) { // we do not need to decode other blocks
		int b;
		for (b = 0; b < e->asize; ++b) ol[b] = ok[b]; // copy ok[] to ol[]
		ok[a] += k - z; // finalize ok[a]
		if (z + len < l) { // we need to decode the next run
			z += len; ol[a] += len;
			while (1) {
				len = rld_dec0(e, &itr, &a);
				if (z + len >= l) break;
				z += len; ol[a] += len;
			}
		}
		ol[a] += l - z;
	} else { // we have to decode other blocks
		ok[a] += k - z;
		rld_rank1a(e, l, ol);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, 0x18(%rsp)
testq %rsi, %rsi
movq %rdi, 0x8(%rsp)
je 0x9cb5
movq %rsi, %r13
movabsq $0x333333335555779b, %r14 # imm = 0x333333335555779B
leaq -0x1(%rsi), %rdx
leaq 0x20(%rsp), %rbp
leaq 0x10(%rsp), %r15
movq %rbp, %rsi
movq %r12, %rcx
movq %r15, %r8
callq 0x9882
movl (%rbp), %edx
movq (%r15), %r8
movq 0x10(%rbp), %r9
movq (%r9), %rdi
cmpl $0x40, %edx
je 0x9ac2
movq 0x8(%r9), %rsi
movl %edx, %ecx
shrdq %cl, %rdi, %rsi
movq %rsi, %rdi
testq %rdi, %rdi
js 0x9b29
movq %rdi, %rcx
shrq $0x39, %rcx
andb $0x3c, %cl
movq %r14, %rsi
shrq %cl, %rsi
movl %esi, %r11d
andl $0xf, %r11d
movl %r11d, %ecx
negb %cl
movq %rdi, %r15
shrq %cl, %r15
andb $0xf, %sil
movq %rdi, %rbp
movl %esi, %ecx
shlq %cl, %rbp
leal -0x1(%r15), %esi
movb $0x41, %cl
subb %r15b, %cl
shrq %cl, %rbp
movl $0x1, %r10d
movl %esi, %ecx
shll %cl, %r10d
orq %rbp, %r10
leal (%r15,%r11), %ecx
decl %ecx
shlq %cl, %rdi
shrq $0x3d, %rdi
subl %ecx, %edx
leal -0x3(%rdx), %ecx
testl %ecx, %ecx
jle 0x9b44
movl %ecx, %edx
jmp 0x9b50
shrq $0x3c, %rdi
andl $0x7, %edi
movl $0x1, %r10d
cmpl $0x4, %edx
jg 0x9b4d
addq $0x8, %r9
addl $0x3c, %edx
jmp 0x9b50
addq $0x8, %r9
addl $0x3d, %edx
jmp 0x9b50
addl $-0x4, %edx
leaq (%r8,%r10), %rcx
cmpq %r13, %rcx
jae 0x9b67
movl %edi, %esi
addq %r10, (%r12,%rsi,8)
movq %rcx, %r8
jmp 0x9aad
movq %r9, 0x30(%rsp)
movl %edx, 0x20(%rsp)
movq %r8, 0x10(%rsp)
movq 0x18(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x9cd6
movq 0x8(%rsp), %rax
movzbl (%rax), %eax
testq %rax, %rax
je 0x9ba2
xorl %edx, %edx
movq (%r12,%rdx,8), %rsi
movq %rsi, (%rbx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x9b92
subq %r8, %r13
movl %edi, %eax
addq %r13, (%r12,%rax,8)
movq 0x18(%rsp), %r13
cmpq %r13, %rcx
jae 0x9d08
movq %rcx, 0x10(%rsp)
addq %r10, (%rbx,%rax,8)
movq 0x40(%rsp), %r9
movq 0x30(%rsp), %r8
movl 0x20(%rsp), %eax
movq 0x10(%rsp), %r10
movq 0x8(%rsp), %r12
movq (%r8), %rdx
movl %eax, %ecx
negb %cl
shlq %cl, %rdx
cmpq %r9, %r8
je 0x9bff
movl $0x0, %r11d
cmpl $0x40, %eax
je 0x9c02
movq 0x8(%r8), %r11
movl %eax, %ecx
shrq %cl, %r11
jmp 0x9c02
xorl %r11d, %r11d
orq %rdx, %r11
js 0x9c2f
movq %r11, %rcx
shrq $0x39, %rcx
andb $0x3c, %cl
movq %r14, %rdx
shrq %cl, %rdx
movl %edx, %ecx
andl $0xf, %ecx
movq %r11, %rsi
shrq $0x3a, %rsi
jne 0x9c3c
cmpl $0xb, %ecx
jne 0x9c3c
xorl %r15d, %r15d
jmp 0x9c9d
movl $0x1, %r15d
movl $0x1, %edx
jmp 0x9c70
negb %cl
movq %r11, %rdi
shrq %cl, %rdi
andl $0xf, %edx
movq %r11, %r12
movl %edx, %ecx
shlq %cl, %r12
leaq -0x1(%rdi), %rsi
movb $0x41, %cl
subb %dil, %cl
shrq %cl, %r12
movl $0x1, %r15d
movl %esi, %ecx
shll %cl, %r15d
orq %r12, %r15
movq 0x8(%rsp), %r12
addl %esi, %edx
movl %edx, %ecx
shlq %cl, %r11
movsbl 0x2(%r12), %esi
movl %esi, %ecx
negb %cl
shrq %cl, %r11
addl %esi, %edx
leal 0x40(%rax), %ecx
xorl %esi, %esi
cmpl %edx, %eax
setle %sil
cmovgl %eax, %ecx
leaq (%r8,%rsi,8), %r8
subl %edx, %ecx
movl %ecx, %eax
movl %r11d, %edi
leaq (%r10,%r15), %rcx
cmpq %r13, %rcx
jae 0x9cfa
movslq %edi, %rdx
addq %r15, (%rbx,%rdx,8)
movq %rcx, %r10
jmp 0x9bda
movzbl (%rdi), %edx
testq %rdx, %rdx
je 0x9cca
shll $0x3, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2100
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
jmp 0x9ce4
subq %r8, %r13
movl %edi, %eax
addq %r13, (%r12,%rax,8)
movq 0x8(%rsp), %rdi
movq %rbx, %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x973b
movq %r8, 0x30(%rsp)
movl %eax, 0x20(%rsp)
movq %r10, 0x10(%rsp)
subq 0x10(%rsp), %r13
movslq %edi, %rax
addq %r13, (%rbx,%rax,8)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq