// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r13
movq 0x10(%rdi), %rsi
shrq $0x3, %rsi
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rax
movslq 0x8(%rdi), %rcx
movq %rcx, -0x40(%rbp)
xorl %edx, %edx
divq %rcx
movq %rax, %rdi
movb 0x3(%r13), %cl
shrq %cl, %rsi
shlq %cl, %rsi
movq %rsi, -0x48(%rbp)
incq %rdi
movzbl (%r13), %ebx
leal 0xf(,%rbx,8), %eax
andl $-0x10, %eax
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
movq 0x28(%r13), %rax
movq (%rax), %rsi
movq %rsi, %rax
xorl %edx, %edx
divq %rdi
movq %rax, %rcx
shrq $0x20, %rcx
jne 0x89a6
cmpq $0x10000, %rax          # imm = 0x10000
jae 0x89c2
cmpq $0x100, %rax            # imm = 0x100
jae 0x89f6
leaq 0xedd3(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %r12b
jmp 0x8a3d
movq %rax, %rdx
shrq $0x30, %rdx
jne 0x89df
shrq $0x28, %rax
jne 0x8a0b
leaq 0xedb4(%rip), %rax      # 0x17770
movb (%rcx,%rax), %r12b
jmp 0x8a39
cmpq $0x1000000, %rax        # imm = 0x1000000
jae 0x8a1c
shrq $0x10, %rax
leaq 0xed9b(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %r12b
addb $0x10, %r12b
jmp 0x8a3d
shrq $0x38, %rax
leaq 0xed86(%rip), %rcx      # 0x17770
jne 0x8a31
movb (%rdx,%rcx), %r12b
addb $0x10, %r12b
jmp 0x8a39
shrq $0x8, %rax
leaq 0xed6f(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %r12b
addb $0x8, %r12b
jmp 0x8a3d
leaq 0xed5e(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %r12b
addb $0x8, %r12b
jmp 0x8a39
shrq $0x18, %rax
leaq 0xed49(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %r12b
addb $0x18, %r12b
jmp 0x8a3d
movb (%rax,%rcx), %r12b
addb $0x18, %r12b
addb $0x20, %r12b
addb $0x4, %r12b
movb %r12b, 0x4(%r13)
movl $0x1, %r15d
movl $0x1, %eax
movl %r12d, %ecx
shlq %cl, %rax
leaq (%rsi,%rax), %rdi
decq %rdi
shrq %cl, %rdi
incq %rdi
movq %rdi, 0x30(%r13)
movzbl 0x1(%r13), %eax
movq %rax, -0x38(%rbp)
imulq %rax, %rdi
movl $0x8, %esi
callq 0x2130
movq %rax, 0x38(%r13)
movq %rax, -0x30(%rbp)
movq $0x0, (%rax)
testq %rbx, %rbx
je 0x8aa3
leal (,%rbx,8), %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x2100
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %r8
cmpq %r8, %rsi
movq -0x38(%rbp), %r11
jb 0x8c48
movsbq %r12b, %rax
movl %eax, %r12d
movabsq $0x4000000000000000, %r9 # imm = 0x4000000000000000
movq 0x18(%r13), %r10
movq %r13, -0x58(%rbp)
movq 0x30(%r13), %rax
movq %rax, -0x88(%rbp)
leal (,%rbx,8), %eax
movq %rax, -0x60(%rbp)
movl %ebx, %edi
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x78(%rbp)
leal (,%r11,8), %r13d
movl $0x1, %eax
movq %r8, %rcx
movq %rdi, -0x80(%rbp)
movq %r10, -0x68(%rbp)
movq %rax, %r15
movl %ecx, %eax
andl $0x7fffff, %eax         # imm = 0x7FFFFF
shll $0x3, %eax
movq %rcx, -0x50(%rbp)
shrq $0x17, %rcx
movq (%r10,%rcx,8), %rcx
movq (%rcx,%rax), %rdx
cmpq %r9, %rdx
jae 0x8b53
testq %rbx, %rbx
je 0x8bbf
addq %rcx, %rax
addq $0x2, %rax
xorl %ecx, %ecx
movzwl (%rax,%rcx,2), %edx
addq %rdx, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rdi
jne 0x8b41
jmp 0x8ba8
movabsq $-0x4000000000000000, %rdi # imm = 0xC000000000000000
andq %rdi, %rdx
cmpq %r9, %rdx
jne 0x8b8a
testq %rbx, %rbx
je 0x8bbf
addq %rcx, %rax
addq $0x4, %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
addq %rdx, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rbx
jne 0x8b73
jmp 0x8ba8
testq %rbx, %rbx
je 0x8bbf
addq %rcx, %rax
addq $0x8, %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
addq %rdx, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rbx
jne 0x8b98
testq %rbx, %rbx
je 0x8bbf
xorl %ecx, %ecx
xorl %eax, %eax
addq (%r14,%rcx,8), %rax
incq %rcx
cmpq %rcx, %rbx
jne 0x8bb1
jmp 0x8bc1
xorl %eax, %eax
leaq -0x8(,%r15,8), %rdi
imulq %r11, %rdi
addq -0x78(%rbp), %rdi
movq %r15, %rdx
movl %r12d, %ecx
shlq %cl, %rdx
addq %r13, %rdi
incq %r15
cmpq %rdx, %rax
jae 0x8bd1
leaq -0x1(%r15), %rax
cmpq -0x88(%rbp), %rax
movq -0x50(%rbp), %rcx
jae 0x8c31
movq %rcx, -0x8(%rdi)
testq %rbx, %rbx
je 0x8c31
movq %r14, %rsi
movq -0x60(%rbp), %rdx
movq %rax, -0x70(%rbp)
callq 0x2180
movq -0x70(%rbp), %rax
movq -0x50(%rbp), %rcx
movq -0x68(%rbp), %r10
movabsq $0x4000000000000000, %r9 # imm = 0x4000000000000000
movq -0x38(%rbp), %r11
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %rsi
addq %r8, %rcx
cmpq %rsi, %rcx
movq -0x80(%rbp), %rdi
jbe 0x8b0d
decq %r15
movq -0x58(%rbp), %r13
movq 0x30(%r13), %rax
decq %rax
cmpq %rax, %r15
jb 0x8cb4
movq 0x30(%r13), %rax
cmpq $0x2, %rax
movq -0x30(%rbp), %r14
jb 0x8ca5
leaq 0x1(%rbx), %rcx
leal (,%r11,8), %edx
movl $0x1, %esi
movq %r14, %rdi
movq %rsi, %r8
imulq %r11, %r8
cmpq $0x0, (%r14,%r8,8)
jne 0x8c9a
movq %rcx, %r8
movq %rdi, %r9
movq (%r9), %r10
movq %r10, (%r9,%rdx)
addq $0x8, %r9
decq %r8
jne 0x8c8a
incq %rsi
addq %rdx, %rdi
cmpq %rax, %rsi
jne 0x8c76
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xea70(%rip), %rdi      # 0x1772b
leaq 0xea7e(%rip), %rsi      # 0x17740
leaq 0xea7e(%rip), %rcx      # 0x17747
movl $0xc5, %edx
callq 0x20e0