// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rdi, %r14
movq 0x10(%rdi), %rcx
shrq $0x3, %rcx
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
movq %rcx, -0x30(%rbp)
andq %rcx, %rax
movslq 0x8(%rdi), %rcx
xorl %r15d, %r15d
xorl %edx, %edx
movq %rcx, -0x48(%rbp)
divq %rcx
movq %rax, %rsi
movb 0x3(%rdi), %cl
pushq $-0x1
popq %rax
shlq %cl, %rax
movq %rax, -0x50(%rbp)
incq %rsi
movzbl (%rdi), %eax
movq %rax, -0x58(%rbp)
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movq 0x28(%rdi), %rax
movq (%rax), %r12
movq %r12, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %rdi
callq 0x742b
addb $0x4, %al
movsbq %al, %rcx
pushq $0x1
popq %r13
movq %r13, %rdx
shlq %cl, %rdx
movb %al, 0x4(%r14)
movl %ecx, %eax
movq %rax, -0x68(%rbp)
leaq (%r12,%rdx), %rax
decq %rax
shrq %cl, %rax
movq %rax, -0x60(%rbp)
leaq 0x1(%rax), %r12
movq %r12, 0x30(%r14)
movzbl 0x1(%r14), %ecx
movq %r12, %rdi
movq %rcx, -0x38(%rbp)
imulq %rcx, %rdi
pushq $0x8
popq %rsi
callq 0x2130
movq -0x58(%rbp), %rsi
movq %rax, -0x40(%rbp)
movq %r14, -0x70(%rbp)
movq %rax, 0x38(%r14)
cmpq %r15, %rsi
je 0x7753
andq $0x0, (%rbx,%r15,8)
incq %r15
jmp 0x7744
movabsq $0x4000000000000000, %r9 # imm = 0x4000000000000000
movq -0x30(%rbp), %rcx
andq %rcx, -0x50(%rbp)
leaq 0x1(%rsi), %rcx
movq %rcx, -0x30(%rbp)
addq $0x8, %rax
movq -0x38(%rbp), %rcx
leal (,%rcx,8), %r8d
movq -0x48(%rbp), %r10
cmpq -0x50(%rbp), %r10
ja 0x78b1
movl %r10d, %ecx
andl $0x7fffff, %ecx         # imm = 0x7FFFFF
shll $0x3, %ecx
movq -0x70(%rbp), %rdi
movq 0x18(%rdi), %r11
movq %r10, %r15
shrq $0x17, %r15
movq (%r11,%r15,8), %r11
movl %r10d, %r15d
andl $0x7fffff, %r15d        # imm = 0x7FFFFF
movq (%r11,%r15,8), %r15
cmpq %r9, %r15
jae 0x77da
addq %r11, %rcx
addq $0x2, %rcx
xorl %r11d, %r11d
cmpq %r11, %rsi
je 0x782b
movzwl (%rcx,%r11,2), %r15d
addq %r15, (%rbx,%r11,8)
incq %r11
jmp 0x77c7
movabsq $-0x4000000000000000, %rdx # imm = 0xC000000000000000
andq %rdx, %r15
cmpq %r9, %r15
jne 0x780f
addq %r11, %rcx
addq $0x4, %rcx
xorl %r11d, %r11d
cmpq %r11, %rsi
je 0x782b
movl (%rcx,%r11,4), %r15d
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
addq %r15, (%rbx,%r11,8)
incq %r11
jmp 0x77f6
addq %r11, %rcx
addq $0x8, %rcx
xorl %r11d, %r11d
cmpq %r11, %rsi
je 0x782b
movq (%rcx,%r11,8), %r15
addq %r15, (%rbx,%r11,8)
incq %r11
jmp 0x7819
xorl %ecx, %ecx
xorl %r11d, %r11d
cmpq %rcx, %rsi
je 0x783e
addq (%rbx,%rcx,8), %r11
incq %rcx
jmp 0x7830
movq %r9, %rdx
movq %rsi, %rdi
movq %r12, %rsi
movq %r8, %r15
imulq %r13, %r15
addq %rax, %r15
movq %r13, %r12
movq -0x68(%rbp), %r9
movq %r12, %r13
movq %r12, %r14
movl %r9d, %ecx
shlq %cl, %r14
movq %r15, %rcx
incq %r12
addq %r8, %r15
cmpq %r14, %r11
jae 0x7858
movq %rsi, %r12
cmpq %rsi, %r13
movq %rdi, %rsi
movq %rdx, %r9
jae 0x78a8
movq %r13, %r11
imulq -0x38(%rbp), %r11
movq -0x40(%rbp), %rdx
movq %r10, (%rdx,%r11,8)
xorl %r11d, %r11d
cmpq %r11, %rsi
je 0x78a8
movq (%rbx,%r11,8), %r14
movq %r14, (%rcx)
incq %r11
addq $0x8, %rcx
jmp 0x7893
addq -0x48(%rbp), %r10
jmp 0x7781
cmpq -0x60(%rbp), %r13
jb 0x7913
movq -0x38(%rbp), %rsi
leal (,%rsi,8), %eax
pushq $0x1
popq %rcx
movq -0x40(%rbp), %rdx
movq %rdx, %rdi
movq -0x30(%rbp), %r11
cmpq %r12, %rcx
jae 0x7904
movq %rcx, %r8
imulq %rsi, %r8
cmpq $0x0, (%rdx,%r8,8)
je 0x78eb
incq %rcx
addq %rax, %rdi
jmp 0x78d0
movq %rdi, %r8
movq %r11, %r9
subq $0x1, %r9
jb 0x78e3
movq (%r8), %r10
movq %r10, (%r8,%rax)
addq $0x8, %r8
jmp 0x78f1
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xce26(%rip), %rdi      # 0x14740
leaq 0xce34(%rip), %rsi      # 0x14755
leaq 0xce34(%rip), %rcx      # 0x1475c
movl $0xc5, %edx
callq 0x20e0