// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0xc800
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0xc61d
movl $0x10000, %edi          # imm = 0x10000
callq 0x21c0
movq %rax, -0x40(%rbp)
movl $0x6, %edi
movl $0x3, %esi
callq 0xb4b0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x80(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xb740
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x2070
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
je 0xc5f1
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0xc5ec
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl (%rax,%rcx), %eax
sarl $0x3, %eax
cmpl $0x0, %eax
je 0xc5df
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl (%rax,%rcx), %eax
sarl $0x3, %eax
movslq %eax, %rdx
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl $0x7, %eax
leaq -0x80(%rbp), %rsi
movzbl %al, %ecx
callq 0xb870
jmp 0xc5e1
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xc592
jmp 0xc56c
movq -0x18(%rbp), %rdi
callq 0x20a0
movq -0x40(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xbee0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc7f0
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
shrq $0x3, %rax
cmpq $0x800000, %rax         # imm = 0x800000
jbe 0xc6be
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
shrq $0x3, %rax
addq $0x800000, %rax         # imm = 0x800000
subq $0x1, %rax
shrq $0x17, %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movslq 0xc(%rax), %rsi
shlq $0x3, %rsi
callq 0x21e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0xc6bc
movl $0x800000, %edi         # imm = 0x800000
movl $0x8, %esi
callq 0x2140
movq %rax, %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xc683
jmp 0xc6be
movl $0x0, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
shrq $0x3, %rax
movq %rax, -0x28(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
movl 0xc(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xc722
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x18(%rbp), %rcx
movl $0x8, %esi
movl $0x800000, %edx         # imm = 0x800000
callq 0x2070
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
subq $0x800000, %rax         # imm = 0x800000
movq %rax, -0x28(%rbp)
jmp 0xc6d5
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x8, %esi
callq 0x2070
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rax
movzbl 0x1(%rax), %eax
imulq %rax, %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x3, %eax
movslq %eax, %rsi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x18(%rbp), %rcx
callq 0x2070
movq -0x18(%rbp), %rdi
callq 0x20a0
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
shlq $0x3, %rax
shrq $0x6, %rax
movq -0x20(%rbp), %rcx
movslq 0x8(%rcx), %rcx
xorl %edx, %edx
divq %rcx
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x30(%rbp)
movq %rax, %rdi
callq 0xb5f0
addl $0x4, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)