// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq %r8, %rbx
movq %rcx, %r12
orl $-0x1, 0xc(%rsp)
testq %rsi, %rsi
je 0x85cd
movq %rsi, %r13
movq %rdx, 0x18(%rsp)
leaq -0x1(%rsi), %rdx
leaq 0x30(%rsp), %rbp
leaq 0x28(%rsp), %r15
movq %rdi, 0x10(%rsp)
movq %rbp, %rsi
movq %r12, %rcx
movq %r15, %r8
callq 0x8261
movq %rax, 0x20(%rsp)
movq (%r15), %r14
leaq 0xc(%rsp), %r15
movq %rbp, %rdi
movq %r15, %rsi
callq 0x846b
movq %rax, %rdi
addq %r14, %rdi
cmpq %r13, %rdi
jae 0x85a4
movslq 0xc(%rsp), %rcx
addq %rax, (%r12,%rcx,8)
movq %rdi, %r14
jmp 0x8580
movq 0x18(%rsp), %rsi
cmpq %rsi, 0x20(%rsp)
jbe 0x85e6
movq 0x10(%rsp), %r15
movzbl (%r15), %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x860d
movq (%r12,%rdx,8), %r8
movq %r8, (%rbx,%rdx,8)
incq %rdx
jmp 0x85bb
movzbl (%rdi), %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x85e1
andq $0x0, (%r12,%rcx,8)
incq %rcx
jmp 0x85d2
movq %rdx, %rsi
jmp 0x85f7
subq %r14, %r13
movslq 0xc(%rsp), %rax
addq %r13, (%r12,%rax,8)
movq 0x10(%rsp), %rdi
movq %rbx, %rdx
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x81cc
subq %r14, %r13
movl 0xc(%rsp), %ebp
movslq %ebp, %rcx
addq %r13, (%r12,%rcx,8)
cmpq %rsi, %rdi
jae 0x8725
movq %rdi, 0x28(%rsp)
addq %rax, (%rbx,%rcx,8)
movq 0x50(%rsp), %r8
movq 0x40(%rsp), %r9
movl 0x30(%rsp), %eax
pushq $0x1
popq %r10
pushq $0x1
popq %r11
movq (%r9), %rdx
movl %eax, %ecx
negb %cl
shlq %cl, %rdx
cmpq %r8, %r9
je 0x8668
movl $0x0, %r12d
cmpl $0x40, %eax
je 0x866b
movq 0x8(%r9), %r12
movl %eax, %ecx
shrq %cl, %r12
jmp 0x866b
xorl %r12d, %r12d
orq %rdx, %r12
movl %r11d, %edx
movq %r10, %r13
js 0x86dd
movq %r12, %rcx
shrq $0x39, %rcx
andb $0x3c, %cl
movabsq $0x333333335555779b, %rdx # imm = 0x333333335555779B
shrq %cl, %rdx
movl %edx, %ecx
andl $0xf, %ecx
movq %r12, %r14
shrq $0x3a, %r14
jne 0x86a5
cmpl $0xb, %ecx
jne 0x86a5
xorl %r13d, %r13d
jmp 0x870a
negb %cl
movq %r12, %r14
shrq %cl, %r14
andl $0xf, %edx
movq %r12, %rbp
movl %edx, %ecx
shlq %cl, %rbp
leaq -0x1(%r14), %r15
movb $0x41, %cl
subb %r14b, %cl
shrq %cl, %rbp
movl %r11d, %r13d
movl %r15d, %ecx
shll %cl, %r13d
orq %rbp, %r13
movq 0x18(%rsp), %rsi
addl %r15d, %edx
movq 0x10(%rsp), %r15
movl %edx, %ecx
shlq %cl, %r12
movsbl 0x2(%r15), %ebp
movl %ebp, %ecx
negb %cl
shrq %cl, %r12
addl %ebp, %edx
leal 0x40(%rax), %ecx
xorl %r14d, %r14d
cmpl %edx, %eax
setle %r14b
cmovgl %eax, %ecx
leaq (%r9,%r14,8), %r9
subl %edx, %ecx
movl %r12d, %ebp
movl %ecx, %eax
leaq (%rdi,%r13), %rdx
movslq %ebp, %rcx
cmpq %rsi, %rdx
jae 0x8722
addq %r13, (%rbx,%rcx,8)
movq %rdx, %rdi
jmp 0x8643
movq %rdi, %r14
subq %r14, %rsi
addq %rsi, (%rbx,%rcx,8)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq