// File: /workspace/github_c_makefile_star2_O3/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 0x9742
testq %rax, %rax
je 0x9481
movq %rax, %rbx
movq 0x10(%rax), %r13
cmpq $0x4000007, %r13        # imm = 0x4000007
jbe 0x9594
shrq $0x3, %r13
leaq 0x7fffff(%r13), %r15
shrq $0x17, %r15
movl %r15d, 0xc(%rbx)
movq 0x18(%rbx), %rdi
movslq %r15d, %r12
leaq (,%r12,8), %rsi
callq 0x21c0
movq %rax, 0x18(%rbx)
cmpl $0x2, %r12d
jl 0x95f9
movq %rax, %r14
movl %r15d, %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0x1, %ebp
movl $0x800000, %edi         # imm = 0x800000
movl $0x8, %esi
callq 0x2130
movq %rax, (%r14,%rbp,8)
incq %rbp
cmpq %rbp, %r12
jne 0x9461
jmp 0x959c
movl $0x10000, %edi          # imm = 0x10000
callq 0x21a0
movq %rax, %r14
movl $0x6, %edi
movl $0x3, %esi
callq 0x8880
movq %rax, %rbx
movq 0x18(%rax), %rax
movq %rax, 0x48(%rsp)
movq (%rax), %rax
movq %rax, 0x38(%rsp)
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, 0x40(%rsp)
movq (%rax), %rcx
shrq $0x3e, %rcx
movsbq 0x5(%rbx,%rcx), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
movq %rax, 0x50(%rsp)
movabsq $-0xffffffc0, %rax      # imm = 0xFFFFFFFF00000040
movq %rax, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x8(%rsp), %r15
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
movq %r14, %rdi
movq %r15, %rcx
callq 0x2060
testl %eax, %eax
je 0x9572
leaq 0x20(%rsp), %r12
testl %eax, %eax
jle 0x9559
movl %eax, %r13d
xorl %ebp, %ebp
movzbl (%r14,%rbp), %ecx
cmpq $0x8, %rcx
jb 0x9551
movl %ecx, %edx
shrl $0x3, %edx
andl $0x7, %ecx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x8aba
incq %rbp
cmpq %rbp, %r13
jne 0x9533
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
movq %r14, %rdi
movq %r15, %rcx
callq 0x2060
testl %eax, %eax
jne 0x952a
movq %r15, %rdi
callq 0x2090
movq %r14, %rdi
callq 0x2040
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x9060
jmp 0x9730
movl 0xc(%rbx), %r15d
shrq $0x3, %r13
cmpl $0x1, %r15d
jle 0x95f9
decl %r15d
movq 0x18(%rbx), %r12
movq 0x8(%rsp), %r14
movl %r15d, %r15d
movq %r15, 0x10(%rsp)
shlq $0x17, %r15
xorl %ebp, %ebp
movq %r12, 0x18(%rsp)
movq (%r12), %rdi
movl $0x8, %esi
movl $0x800000, %edx         # imm = 0x800000
movq %r14, %rcx
callq 0x2060
addq $0x8, %r12
addq $0x800000, %rbp         # imm = 0x800000
cmpq %rbp, %r15
jne 0x95c1
movq %r13, %rdx
subq %rbp, %rdx
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
jmp 0x9607
movq 0x18(%rbx), %rax
movq 0x8(%rsp), %r14
xorl %ecx, %ecx
movq %r13, %rdx
movq (%rax,%rcx,8), %rdi
movl $0x8, %esi
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 %r13, %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, %rcx
shrq $0x20, %rcx
jne 0x96a2
cmpq $0x10000, %rax          # imm = 0x10000
jae 0x96bd
cmpq $0x100, %rax            # imm = 0x100
jae 0x96eb
leaq 0xe146(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %al
jmp 0x972b
movq %rax, %rdx
shrq $0x30, %rdx
jne 0x96d7
shrq $0x28, %rax
jne 0x96fd
leaq 0xe128(%rip), %rax      # 0x177e0
movb (%rcx,%rax), %al
jmp 0x9729
cmpq $0x1000000, %rax        # imm = 0x1000000
jae 0x970b
shrq $0x10, %rax
leaq 0xe110(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %al
addb $0x10, %al
jmp 0x972b
shrq $0x38, %rax
jne 0x971d
leaq 0xe0fc(%rip), %rax      # 0x177e0
movb (%rdx,%rax), %al
addb $0x10, %al
jmp 0x9729
shrq $0x8, %rax
leaq 0xe0ea(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %al
addb $0x8, %al
jmp 0x972b
leaq 0xe0dc(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %al
addb $0x8, %al
jmp 0x9729
shrq $0x18, %rax
leaq 0xe0ca(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %al
addb $0x18, %al
jmp 0x972b
leaq 0xe0bc(%rip), %rcx      # 0x177e0
movb (%rax,%rcx), %al
addb $0x18, %al
addb $0x20, %al
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