// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/lbr.c
// Function: de_run_crlzh
static void de_run_crlzh(deark *c, de_module_params *mparams)
{
	struct crlzh_ctx *crlzhctx = NULL;
	i64 pos = 0;
	u8 b;
	u8 fmtver_raw;
	const char *verstr;

	crlzhctx = de_malloc(c, sizeof(struct crlzh_ctx));

	pos += 2;
	if(!crcr_read_filename_etc(c, pos, &crlzhctx->fnd)) goto done;
	pos += crlzhctx->fnd.size;
	b = de_getbyte_p(&pos);
	de_dbg(c, "encoder version: 0x%02x", (UI)b);

	fmtver_raw = de_getbyte_p(&pos);
	if(fmtver_raw<=0x1f) {
		crlzhctx->fmtver = 1;
		verstr = "old";
	}
	else if(fmtver_raw>=0x20 && fmtver_raw<=0x2f) {
		// Note: Alternatives are ==0x20 (CFX), and >=0x20 (lbrate).
		crlzhctx->fmtver = 2;
		verstr = "new";
	}
	else {
		verstr = "?";
	}
	de_dbg(c, "format version: 0x%02x (%s)", (UI)fmtver_raw, verstr);
	if(crlzhctx->fmtver!=0) {
		de_declare_fmtf(c, "CRLZH (v%d)", (int)crlzhctx->fmtver);
	}

	crlzhctx->cksum_type = de_getbyte_p(&pos);
	de_dbg(c, "checksum type: 0x%02x (%s)", (UI)crlzhctx->cksum_type,
		(crlzhctx->cksum_type==0?"standard":"?"));

	b = de_getbyte_p(&pos);
	de_dbg(c, "unused info byte: 0x%02x", (UI)b);

	de_dbg(c, "compressed data at %"I64_FMT, pos);
	decompress_crlzh(c, crlzhctx, pos);

done:
	if(crlzhctx) {
		crcr_filename_data_freecontents(c, &crlzhctx->fnd);
		de_free(c, crlzhctx);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
movq $0x0, 0x8(%rsp)
movl $0x28, %esi
callq 0xe969b
movq %rax, %r14
movq 0x8(%rsp), %rsi
addq $0x2, %rsi
movq %rsi, 0x8(%rsp)
movq %rbx, %rdi
movq %rax, %rdx
callq 0xa1192
testl %eax, %eax
je 0xa0412
movq 0x10(%r14), %rax
leaq 0x8(%rsp), %r15
addq %rax, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %edx
leaq 0x91de1(%rip), %rsi     # 0x131fc0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %edx
cmpb $0x20, %dl
jae 0xa0208
leaq 0x9a2ca(%rip), %rcx     # 0x13a4ce
movb $0x1, %al
jmp 0xa0215
cmpb $0x2f, %al
ja 0xa021b
leaq 0x7e03a(%rip), %rcx     # 0x11e24d
movb $0x2, %al
movb %al, 0x18(%r14)
jmp 0xa0222
leaq 0x8bc47(%rip), %rcx     # 0x12be69
leaq 0x91daf(%rip), %rsi     # 0x131fd8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movzbl 0x18(%r14), %edx
testl %edx, %edx
je 0xa024d
leaq 0x91e1a(%rip), %rsi     # 0x13205d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb703
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xef14d
movb %al, 0x19(%r14)
movzbl %al, %edx
testb %dl, %dl
leaq 0x949e7(%rip), %rax     # 0x134c55
leaq 0x8bbf4(%rip), %rcx     # 0x12be69
cmoveq %rax, %rcx
leaq 0x91d81(%rip), %rsi     # 0x132001
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %edx
leaq 0x91d7c(%rip), %rsi     # 0x13201c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq (%r15), %rdx
leaq 0x91bf4(%rip), %rsi     # 0x131ea8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq (%r15), %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r15
movq (%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xea9e4
movb $0x1, 0x8(%r15)
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r12
movq %rax, %rdi
callq 0xf0e3f
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeba56
leaq 0x51730(%rip), %rsi     # 0xf1a51
movq %r12, %rdi
movq %rax, 0x18(%rsp)
movq %rax, %rdx
callq 0xf1a12
leaq 0x20(%rsp), %rbp
leaq 0x40(%rsp), %r13
leaq 0x58(%rsp), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xfa6e0
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rbp)
movq 0x18(%rax), %rax
subq %rcx, %rax
movq %rax, 0x10(%rbp)
movq %r12, (%r13)
movb $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
cmpb $0x1, 0x18(%r14)
jne 0xa0387
movb $0x1, (%rsp)
jmp 0xa038c
movb $0x1, 0x1(%rsp)
movq %rsp, %r8
movb $0x20, 0x4(%r8)
leaq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %r13
leaq 0x58(%rsp), %rbp
movq %rbx, %rdi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x107127
movq (%r13), %rdi
callq 0xf0ea4
cmpl $0x0, (%rbp)
je 0xa0445
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa6a8
leaq 0x73d99(%rip), %rsi     # 0x114171
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
movq 0x18(%rsp), %r13
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea9b3
movq %r12, %rdi
callq 0xf0b13
movq %r13, %rdi
callq 0xebe1d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
testq %r14, %r14
je 0xa0433
movq (%r14), %rdi
callq 0xf6bb0
movq 0x8(%r14), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x5c(%rsp)
movq 0x18(%rsp), %r13
je 0xa03ea
movq 0x60(%rsp), %rdx
movq 0x28(%rsp), %rcx
addq %rdx, %rcx
leaq 0x91a5a(%rip), %rsi     # 0x131ebf
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x60(%rsp), %rax
addq %rax, 0x10(%rsp)
cmpb $0x0, 0x19(%r14)
jne 0xa03ea
movq %r13, %rdi
callq 0xebe2a
movzwl %ax, %eax
movl %eax, 0x20(%r14)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xef1ed
movl %eax, 0x1c(%r14)
movl 0x20(%r14), %edx
leaq 0x79e65(%rip), %rsi     # 0x11a315
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x1c(%r14), %edx
leaq 0x91a84(%rip), %rsi     # 0x131f49
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x20(%r14), %eax
cmpl 0x1c(%r14), %eax
je 0xa03ea
leaq 0x91a02(%rip), %rsi     # 0x131ee6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xa03ea