// File: /workspace/github_c_makefile_star2_O3/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 0x10(%rdi), %rsi
shrq $0x3, %rsi
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq %rsi, %rax
movslq 0x8(%rdi), %rcx
movq %rcx, -0x60(%rbp)
xorl %edx, %edx
divq %rcx
movq %rax, %r8
incq %r8
movb 0x3(%rdi), %cl
shrq %cl, %rsi
shlq %cl, %rsi
movq %rsi, -0x68(%rbp)
movzbl (%rdi), %r12d
leal (,%r12,8), %eax
movq %rax, -0x48(%rbp)
leal 0xf(,%r12,8), %eax
andl $-0x10, %eax
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
movq %rdi, -0x30(%rbp)
movq 0x28(%rdi), %rax
movq (%rax), %rsi
movq %rsi, %rax
xorl %edx, %edx
divq %r8
movq %rax, %rcx
shrq $0x20, %rcx
jne 0x8d50
cmpq $0x10000, %rax          # imm = 0x10000
jae 0x8d6b
cmpq $0x100, %rax            # imm = 0x100
jae 0x8d9b
leaq 0xea98(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %cl
jmp 0x8dd9
movq %rax, %rdx
shrq $0x30, %rdx
jne 0x8d86
shrq $0x28, %rax
jne 0x8dae
leaq 0xea7a(%rip), %rax      # 0x177e0
movb (%rcx,%rax), %cl
jmp 0x8dd6
cmpq $0x1000000, %rax        # imm = 0x1000000
jae 0x8dbd
shrq $0x10, %rax
leaq 0xea62(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %cl
addb $0x10, %cl
jmp 0x8dd9
shrq $0x38, %rax
leaq 0xea4f(%rip), %rcx      # 0x177e0
jne 0x8dd0
movb (%rdx,%rcx), %cl
addb $0x10, %cl
jmp 0x8dd6
shrq $0x8, %rax
leaq 0xea3a(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %cl
addb $0x8, %cl
jmp 0x8dd9
leaq 0xea2b(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %cl
addb $0x8, %cl
jmp 0x8dd6
shrq $0x18, %rax
leaq 0xea18(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %cl
addb $0x18, %cl
jmp 0x8dd9
movb (%rax,%rcx), %cl
addb $0x18, %cl
addb $0x20, %cl
addb $0x4, %cl
movl $0x1, %eax
shlq %cl, %rax
movq -0x30(%rbp), %r13
movb %cl, 0x4(%r13)
movl $0x1, %ebx
leaq (%rsi,%rax), %r15
decq %r15
movb %cl, -0x38(%rbp)
shrq %cl, %r15
leaq 0x1(%r15), %rdi
movq %rdi, 0x30(%r13)
movzbl 0x1(%r13), %eax
movq %rdi, -0x50(%rbp)
movq %rax, -0x58(%rbp)
imulq %rax, %rdi
movl $0x8, %esi
callq 0x2130
movq %rax, -0x40(%rbp)
movq %rax, 0x38(%r13)
testq %r12, %r12
je 0x8e3c
movq %r14, %rdi
xorl %esi, %esi
movq -0x48(%rbp), %rdx
callq 0x2100
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %r8
cmpq %r8, %rsi
movq -0x58(%rbp), %r10
movq -0x50(%rbp), %r9
jb 0x8fdb
movq %r15, -0x70(%rbp)
movsbq -0x38(%rbp), %rax
movl %eax, %r13d
movabsq $0x4000000000000000, %r11 # imm = 0x4000000000000000
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movl %r12d, %edi
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x80(%rbp)
leal (,%r10,8), %r15d
movl $0x1, %eax
movq %r8, %rcx
movq %rdi, -0x88(%rbp)
movq %rax, %rbx
movl %ecx, %eax
andl $0x7fffff, %eax         # imm = 0x7FFFFF
shll $0x3, %eax
movq %rcx, -0x30(%rbp)
shrq $0x17, %rcx
movq -0x38(%rbp), %rdx
movq (%rdx,%rcx,8), %rcx
movq (%rcx,%rax), %rdx
cmpq %r11, %rdx
jae 0x8ee7
testq %r12, %r12
je 0x8f53
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 0x8ed5
jmp 0x8f3c
movabsq $-0x4000000000000000, %rdi # imm = 0xC000000000000000
andq %rdi, %rdx
cmpq %r11, %rdx
jne 0x8f1e
testq %r12, %r12
je 0x8f53
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, %r12
jne 0x8f07
jmp 0x8f3c
testq %r12, %r12
je 0x8f53
addq %rcx, %rax
addq $0x8, %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
addq %rdx, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x8f2c
testq %r12, %r12
je 0x8f53
xorl %ecx, %ecx
xorl %eax, %eax
addq (%r14,%rcx,8), %rax
incq %rcx
cmpq %rcx, %r12
jne 0x8f45
jmp 0x8f55
xorl %eax, %eax
leaq -0x8(,%rbx,8), %rdi
imulq %r10, %rdi
addq -0x80(%rbp), %rdi
movq %rbx, %rdx
movl %r13d, %ecx
shlq %cl, %rdx
addq %r15, %rdi
incq %rbx
cmpq %rdx, %rax
jae 0x8f65
leaq -0x1(%rbx), %rax
cmpq %r9, %rax
movq -0x30(%rbp), %rcx
jae 0x8fc1
movq %rcx, -0x8(%rdi)
testq %r12, %r12
je 0x8fc1
movq %r14, %rsi
movq -0x48(%rbp), %rdx
movq %rax, -0x78(%rbp)
callq 0x2170
movq -0x78(%rbp), %rax
movq -0x30(%rbp), %rcx
movabsq $0x4000000000000000, %r11 # imm = 0x4000000000000000
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %r10
movq -0x60(%rbp), %r8
movq -0x68(%rbp), %rsi
addq %r8, %rcx
cmpq %rsi, %rcx
movq -0x88(%rbp), %rdi
jbe 0x8e9d
decq %rbx
movq -0x70(%rbp), %r15
cmpq %r15, %rbx
jb 0x9041
cmpq $0x2, %r9
movq -0x40(%rbp), %r11
jb 0x9032
leaq 0x1(%r12), %rax
leal (,%r10,8), %ecx
movl $0x1, %esi
movq %r11, %rdx
movq %rsi, %rdi
imulq %r10, %rdi
cmpq $0x0, (%r11,%rdi,8)
jne 0x9023
movq %rax, %rdi
movq %rdx, %r8
movq (%r8), %r9
movq %r9, (%r8,%rcx)
addq $0x8, %r8
decq %rdi
jne 0x9013
leaq 0x1(%rsi), %rdi
addq %rcx, %rdx
cmpq %r15, %rsi
movq %rdi, %rsi
jne 0x8fff
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe748(%rip), %rdi      # 0x17790
leaq 0xe756(%rip), %rsi      # 0x177a5
leaq 0xe756(%rip), %rcx      # 0x177ac
movl $0xc5, %edx
callq 0x20e0