// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi-lite/rld0.c
// Function: rld_rank_index
void rld_rank_index(rld_t *e)
{
	uint64_t last, n_blks, i, k, *cnt;
	int j;

	n_blks = e->n_bytes * 8 / 64 / e->ssize + 1;
	last = rld_last_blk(e);
	cnt = alloca(e->asize * 8);
	e->ibits = ilog2(e->mcnt[0] / n_blks) + RLD_IBITS_PLUS;
	e->n_frames = ((e->mcnt[0] + (1ll<<e->ibits) - 1) >> e->ibits) + 1;
	e->frame = xcalloc(e->n_frames * e->asize1, 8);
	e->frame[0] = 0;
	for (j = 0; j < e->asize; ++j) cnt[j] = 0;
	for (i = e->ssize, k = 1; i <= last; i += e->ssize) {
		uint64_t sum, *p = rld_seek_blk(e, i);
		int type = rld_block_type(*p);
		if (type == 0) {
			uint16_t *q = (uint16_t*)p;
			for (j = 1; j <= e->asize; ++j) cnt[j-1] += q[j];
		} else if (type == 1) {
			uint32_t *q = (uint32_t*)p;
			for (j = 1; j <= e->asize; ++j) cnt[j-1] += q[j] & 0x3fffffff;
		} else {
			uint64_t *q = (uint64_t*)p;
			for (j = 1; j <= e->asize; ++j) cnt[j-1] += q[j];
		}
		for (j = 0, sum = 0; j < e->asize; ++j) sum += cnt[j];
		while (sum >= k<<e->ibits) ++k;
		if (k < e->n_frames) {
			uint64_t x = k * e->asize1;
			e->frame[x] = i;
			for (j = 0; j < e->asize; ++j) e->frame[x + j + 1] = cnt[j];
		}
	}
	assert(k >= e->n_frames - 1);
	for (k = 1; k < e->n_frames; ++k) { // fill zero cells
		uint64_t x = k * e->asize1;
		if (e->frame[x] == 0) {
			for (j = 0; j <= e->asize; ++j)
				e->frame[x + j] = e->frame[x - e->asize1 + j];
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rax
shrq $0x3, %rax
movabsq $0x3ffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFF
andq %rdx, %rax
movslq 0x8(%rcx), %rcx
xorl %edx, %edx
divq %rcx
incq %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rax
shrq $0x3, %rax
movb 0x3(%rcx), %cl
movb %cl, -0x79(%rbp)
shrq %cl, %rax
movb -0x79(%rbp), %cl
shlq %cl, %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movzbl (%rax), %ecx
movl %ecx, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movl %eax, %ecx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x18(%rbp)
movq %rax, %rdi
callq 0xb5f0
addl $0x4, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
movl %ecx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
addq %rcx, %rax
subq $0x1, %rax
movq -0x8(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
movl %ecx, %ecx
shrq %cl, %rax
movq %rax, %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movzbl 0x1(%rax), %eax
imulq %rax, %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq $0x0, (%rax)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xbb9b
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xbb72
movq -0x8(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x1, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x10(%rbp), %rax
ja 0xbded
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
shrq $0x17, %rcx
movq (%rax,%rcx,8), %rax
movq -0x20(%rbp), %rcx
andq $0x7fffff, %rcx         # imm = 0x7FFFFF
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
shrq $0x3e, %rax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0xbc4b
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jg 0xbc46
movq -0x58(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, %edx
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xbc0a
jmp 0xbcf1
cmpl $0x1, -0x4c(%rbp)
jne 0xbca4
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jg 0xbca2
movq -0x60(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movl %eax, %edx
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xbc60
jmp 0xbcef
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jg 0xbced
movq -0x68(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xbcb3
jmp 0xbcef
jmp 0xbcf1
movl $0x0, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xbd2d
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xbd00
jmp 0xbd2f
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rcx
movsbl 0x4(%rcx), %ecx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
cmpq %rcx, %rax
jb 0xbd5a
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xbd2f
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0xbdd6
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
imulq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x70(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xbdd4
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x70(%rbp), %rcx
movslq -0x34(%rbp), %rsi
addq %rsi, %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xbd97
jmp 0xbdd6
jmp 0xbdd8
movq -0x8(%rbp), %rax
movslq 0x8(%rax), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0xbbaf
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jb 0xbe04
jmp 0xbe23
leaq 0x19884(%rip), %rdi     # 0x2568f
leaq 0x19892(%rip), %rsi     # 0x256a4
movl $0xc5, %edx
leaq 0x1988d(%rip), %rcx     # 0x256ab
callq 0x20f0
movq $0x1, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0xbed2
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
imulq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x78(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0xbebf
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jg 0xbebd
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x78(%rbp), %rcx
movq -0x8(%rbp), %rdx
movzbl 0x1(%rdx), %edx
subq %rdx, %rcx
movslq -0x34(%rbp), %rdx
addq %rdx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x78(%rbp), %rcx
movslq -0x34(%rbp), %rsi
addq %rsi, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xbe6b
jmp 0xbebf
jmp 0xbec1
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xbe2b
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)