// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rsp, %rsi
callq 0x93ac
testq %rax, %rax
je 0x914f
movq %rax, %rbx
movq 0x10(%rax), %r14
cmpq $0x4000008, %r14        # imm = 0x4000008
jb 0x90f6
movq %r14, %r12
shrq $0x3, %r12
addq $0x7fffff, %r12         # imm = 0x7FFFFF
shrq $0x17, %r12
movl %r12d, 0xc(%rbx)
movq 0x18(%rbx), %rdi
movslq %r12d, %r13
leaq (,%r13,8), %rsi
callq 0x21d0
movq %rax, 0x18(%rbx)
cmpl $0x2, %r13d
jl 0x90f6
movq %rax, %r15
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0x1, %r13d
movl $0x800000, %edi         # imm = 0x800000
movl $0x8, %esi
callq 0x2130
movq %rax, (%r15,%r13,8)
incq %r13
cmpq %r13, %r12
jne 0x90db
shrq $0x3, %r14
movl 0xc(%rbx), %r13d
cmpl $0x2, %r13d
jl 0x9261
decl %r13d
movq 0x18(%rbx), %r15
movq (%rsp), %r12
movq %r13, %rax
shlq $0x17, %rax
movq %r14, %rcx
subq %rax, %rcx
movq %rcx, 0x8(%rsp)
xorl %ebp, %ebp
movq (%r15,%rbp,8), %rdi
movl $0x8, %esi
movl $0x800000, %edx         # imm = 0x800000
movq %r12, %rcx
callq 0x2060
incq %rbp
cmpq %rbp, %r13
jne 0x9127
movq 0x8(%rsp), %rdx
jmp 0x9266
movl $0x10000, %edi          # imm = 0x10000
callq 0x21b0
movq %rax, %r14
movl $0x6, %edi
movl $0x3, %esi
callq 0x84a4
movq %rax, %rbx
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movq (%rax), %rax
movq %rax, 0x28(%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, 0x30(%rsp)
movq (%rax), %rcx
shrq $0x3e, %rcx
movsbq 0x5(%rbx,%rcx), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, 0x20(%rsp)
movq %rax, 0x40(%rsp)
movabsq $-0xffffffc0, %rax      # imm = 0xFFFFFFFF00000040
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq (%rsp), %r15
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
movq %r14, %rdi
movq %r15, %rcx
callq 0x2060
testl %eax, %eax
je 0x923f
leaq 0x10(%rsp), %r12
testl %eax, %eax
jle 0x9226
movl %eax, %r13d
xorl %ebp, %ebp
movzbl (%r14,%rbp), %ecx
cmpq $0x8, %rcx
jb 0x921e
movl %ecx, %edx
shrl $0x3, %edx
andl $0x7, %ecx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x86de
incq %rbp
cmpq %rbp, %r13
jne 0x9200
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
movq %r14, %rdi
movq %r15, %rcx
callq 0x2060
testl %eax, %eax
jne 0x91f7
movq %r15, %rdi
callq 0x2090
movq %r14, %rdi
callq 0x2040
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x8cd3
jmp 0x939a
xorl %ebp, %ebp
movq %r14, %rdx
movq 0x18(%rbx), %rax
movq (%rax,%rbp,8), %rdi
movq (%rsp), %r12
movl $0x8, %esi
movq %r12, %rcx
callq 0x2060
movq 0x30(%rbx), %r15
movzbl 0x1(%rbx), %r13d
movq %r13, %rdi
imulq %r15, %rdi
shlq $0x3, %rdi
callq 0x21b0
movq %rax, 0x38(%rbx)
shll $0x3, %r13d
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x2060
movq %r12, %rdi
callq 0x2090
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq %rax, %r14
movslq 0x8(%rbx), %rcx
movq %r14, %rax
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 0x930c
cmpq $0x10000, %rax          # imm = 0x10000
jae 0x9327
cmpq $0x100, %rax            # imm = 0x100
jae 0x9355
leaq 0xe46c(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %al
jmp 0x9395
movq %rax, %rdx
shrq $0x30, %rdx
jne 0x9341
shrq $0x28, %rax
jne 0x9367
leaq 0xe44e(%rip), %rax      # 0x17770
movb (%rcx,%rax), %al
jmp 0x9393
cmpq $0x1000000, %rax        # imm = 0x1000000
jae 0x9375
shrq $0x10, %rax
leaq 0xe436(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %al
addb $0x10, %al
jmp 0x9395
shrq $0x38, %rax
jne 0x9387
leaq 0xe422(%rip), %rax      # 0x17770
movb (%rdx,%rax), %al
addb $0x10, %al
jmp 0x9393
shrq $0x8, %rax
leaq 0xe410(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %al
addb $0x8, %al
jmp 0x9395
leaq 0xe402(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %al
addb $0x8, %al
jmp 0x9393
shrq $0x18, %rax
leaq 0xe3f0(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %al
addb $0x18, %al
jmp 0x9395
leaq 0xe3e2(%rip), %rcx      # 0x17770
movb (%rax,%rcx), %al
addb $0x18, %al
addb $0x20, %al
addb $0x4, %al
movb %al, 0x4(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq