// File: /workspace/github_c_makefile_star2_O2/lh3[P]fermi-lite/rld0.c
// Function: rld_restore
rld_t *rld_restore(const char *fn)
{
	FILE *fp;
	rld_t *e;
	uint64_t k, n_blks;
	int32_t i;

	if ((e = rld_restore_header(fn, &fp)) == 0) { // then load as plain DNA rle
		uint8_t *buf;
		int l;
		rlditr_t itr;
		buf = malloc(0x10000);
		e = rld_init(6, 3);
		rld_itr_init(e, &itr, 0);
		while ((l = fread(buf, 1, 0x10000, fp)) != 0)
			for (i = 0; i < l; ++i)
				if (buf[i]>>3) rld_enc(e, &itr, buf[i]>>3, buf[i]&7);
		fclose(fp);
		free(buf);
		rld_enc_finish(e, &itr);
		return e;
	}
	if (e->n_bytes / 8 > RLD_LSIZE) { // allocate enough memory
		e->n = (e->n_bytes / 8 + RLD_LSIZE - 1) / RLD_LSIZE;
		e->z = realloc(e->z, e->n * sizeof(void*));
		for (i = 1; i < e->n; ++i)
			e->z[i] = xcalloc(RLD_LSIZE, 8);
	}
	for (i = 0, k = e->n_bytes / 8; i < e->n - 1; ++i, k -= RLD_LSIZE)
		fread(e->z[i], 8, RLD_LSIZE, fp);
	fread(e->z[i], 8, k, fp);
	e->frame = xmalloc(e->n_frames * e->asize1 * 8);
	fread(e->frame, 8 * e->asize1, e->n_frames, fp);
	fclose(fp);
	n_blks = e->n_bytes * 8 / 64 / e->ssize + 1;
	e->ibits = ilog2(e->mcnt[0] / n_blks) + RLD_IBITS_PLUS;
	return e;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq 0x8(%rsp), %rsi
callq 0x7ef7
testq %rax, %rax
je 0x7d06
movq %rax, %rbx
movq 0x10(%rax), %rax
cmpq $0x4000007, %rax        # imm = 0x4000007
jbe 0x7df6
shrq $0x3, %rax
movq %rax, (%rsp)
leaq 0x7fffff(%rax), %r13
shrq $0x17, %r13
movl %r13d, 0xc(%rbx)
movq 0x18(%rbx), %rdi
movslq %r13d, %r12
leaq (,%r12,8), %rsi
callq 0x21c0
movq %rax, %r14
movq %rax, 0x18(%rbx)
pushq $0x1
popq %rbp
pushq $0x8
popq %r15
cmpq %r12, %rbp
jge 0x7e02
movl $0x800000, %edi         # imm = 0x800000
movq %r15, %rsi
callq 0x2130
movq %rax, (%r14,%rbp,8)
incq %rbp
jmp 0x7ce7
movl $0x10000, %edi          # imm = 0x10000
callq 0x21a0
movq %rax, %r14
pushq $0x6
popq %rdi
pushq $0x3
popq %rsi
callq 0x736c
movq %rax, %rbx
movq 0x18(%rax), %rax
leaq 0x20(%rsp), %r15
movq %rax, 0x28(%r15)
movq (%rax), %rax
movq %rax, 0x18(%r15)
movslq 0x8(%rbx), %rcx
xorl %edx, %edx
cmpq $0x800000, %rcx         # imm = 0x800000
setne %dl
leaq (%rax,%rcx,8), %rcx
shll $0x3, %edx
orq $-0x10, %rdx
addq %rcx, %rdx
movq %rdx, 0x20(%r15)
movq (%rax), %rcx
shrq $0x3e, %rcx
movsbq 0x5(%rbx,%rcx), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, 0x10(%r15)
movq %rax, 0x30(%r15)
movabsq $-0xffffffc0, %rax      # imm = 0xFFFFFFFF00000040
movq %rax, (%r15)
andq $0x0, 0x8(%r15)
movq 0x8(%rsp), %r12
movl $0x10000, %edx          # imm = 0x10000
movq %r14, %rdi
pushq $0x1
popq %rsi
movq %r12, %rcx
callq 0x2060
movq %rax, %rbp
testl %ebp, %ebp
je 0x7dd4
movl $0x0, %eax
cmovlel %eax, %ebp
xorl %r13d, %r13d
cmpq %r13, %rbp
je 0x7d87
movzbl (%r14,%r13), %ecx
cmpq $0x8, %rcx
jb 0x7dcf
movl %ecx, %edx
shrl $0x3, %edx
andl $0x7, %ecx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7555
incq %r13
jmp 0x7dac
movq %r12, %rdi
callq 0x2090
movq %r14, %rdi
callq 0x2040
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x7932
jmp 0x7ee5
movl 0xc(%rbx), %r13d
shrq $0x3, %rax
movq %rax, (%rsp)
cmpl $0x2, %r13d
pushq $0x1
popq %rbp
cmovgel %r13d, %ebp
movq 0x8(%rsp), %r14
decl %ebp
movq 0x18(%rbx), %r12
movq %rbp, 0x18(%rsp)
shlq $0x17, %rbp
xorl %r13d, %r13d
pushq $0x8
popq %r15
movq %r12, 0x10(%rsp)
cmpq %r13, %rbp
je 0x7e53
movq (%r12), %rdi
movl $0x800000, %edx         # imm = 0x800000
movq %r15, %rsi
movq %r14, %rcx
callq 0x2060
addq $0x800000, %r13         # imm = 0x800000
addq $0x8, %r12
jmp 0x7e2d
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rsp), %rbp
movq %rbp, %rdx
subq %r13, %rdx
pushq $0x8
popq %rsi
movq %r14, %rcx
callq 0x2060
movq 0x30(%rbx), %r15
movzbl 0x1(%rbx), %r12d
movq %r12, %rdi
imulq %r15, %rdi
shlq $0x3, %rdi
callq 0x21a0
movq %rax, 0x38(%rbx)
shll $0x3, %r12d
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2060
movq %r14, %rdi
callq 0x2090
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq %rbp, %rax
movslq 0x8(%rbx), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
incq %rcx
movq 0x28(%rbx), %rax
movq (%rax), %rax
xorl %edx, %edx
divq %rcx
movq %rax, %rdi
callq 0x742b
addb $0x4, %al
movb %al, 0x4(%rbx)
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq