// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi-lite/rld0.c
// Function: rld_locate_blk
static inline uint64_t rld_locate_blk(const rld_t *e, rlditr_t *itr, uint64_t k, uint64_t *cnt, uint64_t *sum)
{
	int j;
	uint64_t c = 0, *q, *z = e->frame + (k>>e->ibits) * e->asize1;
	itr->i = e->z + (*z>>RLD_LBITS);
	q = itr->p = *itr->i + (*z&RLD_LMASK);
	for (j = 1, *sum = 0; j < e->asize1; ++j) *sum += (cnt[j-1] = z[j]);
	while (1) { // seek to the small block
		int type;
		q += e->ssize;
		if (q - *itr->i == RLD_LSIZE) q = *++itr->i;
		type = rld_block_type(*q);
		c = type == 2? *q&0x3fffffffffffffffULL : type == 1? *(uint32_t*)q : *(uint16_t*)q;
		if (*sum + c > k) break;
		if (type == 0) {
			uint16_t *p = (uint16_t*)q + 1;
#ifdef _DNA_ONLY
			cnt[0] += p[0]; cnt[1] += p[1]; cnt[2] += p[2]; cnt[3] += p[3]; cnt[4] += p[4]; cnt[5] += p[5];
#else
			for (j = 0; j < e->asize; ++j) cnt[j] += p[j];
#endif
		} else if (type == 1) {
			uint32_t *p = (uint32_t*)q + 1;
			for (j = 0; j < e->asize; ++j) cnt[j] += p[j] & 0x3fffffff;
		} else {
			uint64_t *p = (uint64_t*)q + 1;
			for (j = 0; j < e->asize; ++j) cnt[j] += p[j];
		}
		*sum += c;
		itr->p = q;
	}
	itr->shead = itr->p;
	itr->stail = rld_get_stail(e, itr);
	itr->p += e->offset0[rld_block_type(*itr->shead)];
	itr->q = (uint8_t*)itr->p;
	itr->r = 64;
	return c + *sum;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
movl %ecx, %ecx
shrq %cl, %rdx
movq %rdx, %rcx
movq -0x8(%rbp), %rdx
movzbl 0x1(%rdx), %edx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x48(%rbp), %rax
movq (%rax), %rax
shrq $0x17, %rax
shlq $0x3, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rcx), %rcx
andq $0x7fffff, %rcx         # imm = 0x7FFFFF
shlq $0x3, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq %rax, 0x10(%rcx)
movq %rax, -0x40(%rbp)
movl $0x1, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0xce94
movq -0x48(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq %rcx, (%rax,%rdx,8)
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xce53
jmp 0xce96
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
sarq $0x3, %rax
cmpq $0x800000, %rax         # imm = 0x800000
jne 0xcee8
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x28(%rcx)
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
shrq $0x3e, %rax
movl %eax, -0x4c(%rbp)
cmpl $0x2, -0x4c(%rbp)
jne 0xcf13
movq -0x40(%rbp), %rcx
movabsq $0x3fffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFFF
andq (%rcx), %rax
movq %rax, -0x70(%rbp)
jmp 0xcf37
cmpl $0x1, -0x4c(%rbp)
jne 0xcf24
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0xcf2e
movq -0x40(%rbp), %rax
movzwl (%rax), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
addq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jbe 0xcf55
jmp 0xd0b4
cmpl $0x0, -0x4c(%rbp)
jne 0xcff1
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movzwl (%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
movzwl 0x4(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movzwl 0x6(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x58(%rbp), %rax
movzwl 0x8(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x58(%rbp), %rax
movzwl 0xa(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
jmp 0xd095
cmpl $0x1, -0x4c(%rbp)
jne 0xd049
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xd047
movq -0x60(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movl %eax, %edx
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xd00a
jmp 0xd093
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xd091
movq -0x68(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xd05c
jmp 0xd093
jmp 0xd095
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0xce96
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
movslq 0x8(%rax), %rax
shlq $0x3, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x8(%rbp), %rax
movslq 0x8(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
subq %rax, %rsi
sarq $0x3, %rsi
movl $0x1, %eax
movl $0x2, %edx
cmpq $0x800000, %rsi         # imm = 0x800000
cmovel %edx, %eax
movslq %eax, %rdx
xorl %eax, %eax
subq %rdx, %rax
shlq $0x3, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx), %rcx
shrq $0x3e, %rcx
movsbl 0x5(%rax,%rcx), %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movslq %edx, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl $0x40, (%rax)
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
addq (%rcx), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)