// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
testq %rsi, %rsi
movq %rdi, 0x8(%rsp)
je 0xa167
movq %rsi, %r13
movabsq $0x333333335555779b, %r14 # imm = 0x333333335555779B
leaq -0x1(%rsi), %rdx
leaq 0x20(%rsp), %rbp
leaq 0x18(%rsp), %r15
movq %rbp, %rsi
movq %r12, %rcx
movq %r15, %r8
callq 0x9ccb
movl (%rbp), %edx
movq 0x10(%rbp), %rdi
movq (%r15), %r10
movq (%rdi), %rsi
cmpl $0x40, %edx
jne 0x9f60
testq %rsi, %rsi
js 0x9fde
movq %rsi, %r8
jmp 0x9f73
movq 0x8(%rdi), %r8
movl %edx, %ecx
shrdq %cl, %rsi, %r8
testq %r8, %r8
js 0x9ff5
movq %r8, %rcx
shrq $0x39, %rcx
andb $0x3c, %cl
movq %r14, %rsi
shrq %cl, %rsi
movl %esi, %r9d
andl $0xf, %r9d
movl %r9d, %ecx
negb %cl
movq %r8, %r15
shrq %cl, %r15
andb $0xf, %sil
movq %r8, %rbp
movl %esi, %ecx
shlq %cl, %rbp
leal -0x1(%r15), %esi
movb $0x41, %cl
subb %r15b, %cl
shrq %cl, %rbp
movl $0x1, %r11d
movl %esi, %ecx
shll %cl, %r11d
orq %rbp, %r11
leal (%r15,%r9), %ecx
decl %ecx
shlq %cl, %r8
shrq $0x3d, %r8
subl %ecx, %edx
leal -0x3(%rdx), %ecx
testl %ecx, %ecx
jle 0x9fd5
movl %ecx, %edx
jmp 0xa01c
addq $0x8, %rdi
addl $0x3d, %edx
jmp 0xa01c
shrq $0x3c, %rsi
andl $0x7, %esi
movl $0x1, %r11d
movl $0x3c, %edx
movl %esi, %r8d
jmp 0xa01c
leaq 0x8(%rdi), %rcx
shrq $0x3c, %r8
andl $0x7, %r8d
xorl %esi, %esi
cmpl $0x5, %edx
cmovlq %rcx, %rdi
setl %sil
shll $0x6, %esi
addl %esi, %edx
addl $-0x4, %edx
movl $0x1, %r11d
leaq (%r10,%r11), %r9
cmpq %r13, %r9
jae 0xa034
movl %r8d, %ecx
addq %r11, (%r12,%rcx,8)
movq %r9, %r10
jmp 0x9f4a
movq 0x10(%rsp), %rsi
cmpq %rsi, %rax
jbe 0xa188
movq 0x8(%rsp), %rax
movzbl (%rax), %eax
testq %rax, %rax
je 0xa061
xorl %ecx, %ecx
movq (%r12,%rcx,8), %rsi
movq %rsi, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0xa051
subq %r10, %r13
movl %r8d, %eax
addq %r13, (%r12,%rax,8)
movq 0x10(%rsp), %r13
cmpq %r13, %r9
jae 0xa1b0
movq %r9, 0x18(%rsp)
addq %r11, (%rbx,%rax,8)
movq 0x40(%rsp), %r10
movq 0x8(%rsp), %r12
movq (%rdi), %rax
movl %edx, %ecx
negb %cl
shlq %cl, %rax
cmpq %r10, %rdi
je 0xa0b1
movl $0x0, %r11d
cmpl $0x40, %edx
je 0xa0b4
movq 0x8(%rdi), %r11
movl %edx, %ecx
shrq %cl, %r11
jmp 0xa0b4
xorl %r11d, %r11d
orq %rax, %r11
js 0xa0e1
movq %r11, %rcx
shrq $0x39, %rcx
andb $0x3c, %cl
movq %r14, %rax
shrq %cl, %rax
movl %eax, %ecx
andl $0xf, %ecx
movq %r11, %rsi
shrq $0x3a, %rsi
jne 0xa0ee
cmpl $0xb, %ecx
jne 0xa0ee
xorl %r15d, %r15d
jmp 0xa14f
movl $0x1, %r15d
movl $0x1, %eax
jmp 0xa122
negb %cl
movq %r11, %r8
shrq %cl, %r8
andl $0xf, %eax
movq %r11, %r12
movl %eax, %ecx
shlq %cl, %r12
leaq -0x1(%r8), %rsi
movb $0x41, %cl
subb %r8b, %cl
shrq %cl, %r12
movl $0x1, %r15d
movl %esi, %ecx
shll %cl, %r15d
orq %r12, %r15
movq 0x8(%rsp), %r12
addl %esi, %eax
movl %eax, %ecx
shlq %cl, %r11
movsbl 0x2(%r12), %esi
movl %esi, %ecx
negb %cl
shrq %cl, %r11
addl %esi, %eax
leal 0x40(%rdx), %ecx
xorl %esi, %esi
cmpl %eax, %edx
setle %sil
cmovgl %edx, %ecx
leaq (%rdi,%rsi,8), %rdi
subl %eax, %ecx
movl %ecx, %edx
movl %r11d, %r8d
leaq (%r9,%r15), %rcx
movslq %r8d, %rax
cmpq %r13, %rcx
jae 0xa1ad
addq %r15, (%rbx,%rax,8)
movq %rcx, %r9
jmp 0xa08c
movzbl (%rdi), %edx
testq %rdx, %rdx
je 0xa17c
shll $0x3, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2100
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
jmp 0xa197
subq %r10, %r13
movl %r8d, %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 0x9b65
movq %r9, %r10
subq %r10, %r13
addq %r13, (%rbx,%rax,8)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq