// File: /workspace/github_c_makefile_star2_O3/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 $0xc8, %rsp
movq %rdi, %rbx
movl $0x28, %esi
callq 0xe8b2b
movq %rax, %r14
movq $0x2, 0x18(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xa08e3
testl %eax, %eax
je 0x9f959
movq 0x10(%r14), %rax
addq $0x2, %rax
leaq 0x18(%rsp), %r15
movq %rax, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb4b
movzbl %al, %edx
leaq 0x92a14(%rip), %rsi     # 0x132344
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb4b
movzbl %al, %edx
cmpb $0x20, %dl
jae 0x9f967
leaq 0x9aef9(%rip), %rcx     # 0x13a84e
movb $0x1, %al
jmp 0x9f974
testq %r14, %r14
jne 0x9fb6f
jmp 0x9fb8b
cmpb $0x2f, %al
ja 0x9f97a
leaq 0x7e9eb(%rip), %rcx     # 0x11e35d
movb $0x2, %al
movb %al, 0x18(%r14)
jmp 0x9f981
leaq 0x8c7d0(%rip), %rcx     # 0x12c151
leaq 0x929d4(%rip), %rsi     # 0x13235c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movzbl 0x18(%r14), %edx
testl %edx, %edx
je 0x9f9ac
leaq 0x92a3f(%rip), %rsi     # 0x1323e1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb152
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %r15
movq %r15, %rsi
callq 0xeeb4b
movb %al, 0x19(%r14)
movzbl %al, %edx
testb %dl, %dl
leaq 0x95614(%rip), %rax     # 0x134fe1
leaq 0x8c77d(%rip), %rcx     # 0x12c151
cmoveq %rax, %rcx
leaq 0x929a6(%rip), %rsi     # 0x132385
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb4b
movzbl %al, %edx
leaq 0x929a1(%rip), %rsi     # 0x1323a0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq (%r15), %rdx
leaq 0x92819(%rip), %rsi     # 0x13222c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq (%r15), %r15
movq %r15, 0x20(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
callq 0xea504
movq %rax, %r12
movq (%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xea53f
movb $0x1, 0x8(%r12)
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, 0x28(%rsp)
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r12
movq %rax, %rdi
callq 0xf0855
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeb499
leaq 0x519cb(%rip), %rsi     # 0xf1451
movq %r12, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
callq 0xf1412
leaq 0x30(%rsp), %rbp
leaq 0x50(%rsp), %r13
leaq 0x68(%rsp), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xfa1dc
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movq %r15, 0x8(%rbp)
movq 0x18(%rax), %rax
subq %r15, %rax
movq %rax, 0x10(%rbp)
movq %r12, (%r13)
movl $0x0, 0x8(%rsp)
cmpb $0x1, 0x18(%r14)
jne 0x9fae4
movb $0x1, 0x8(%rsp)
jmp 0x9fae9
movb $0x1, 0x9(%rsp)
leaq 0x8(%rsp), %r8
movb $0x20, 0x4(%r8)
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %r13
leaq 0x68(%rsp), %rbp
movq %rbx, %rdi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x106c60
movq (%r13), %rdi
callq 0xf08ba
cmpl $0x0, (%rbp)
je 0x9fb9d
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa1a4
leaq 0x746ee(%rip), %rsi     # 0x114221
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
movq 0x10(%rsp), %r13
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0xea50e
movq %r12, %rdi
callq 0xf052b
movq %r13, %rdi
callq 0xeb858
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq (%r14), %rdi
callq 0xf6753
movq 0x8(%r14), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x6c(%rsp)
movq 0x10(%rsp), %r13
je 0x9fb45
movq 0x70(%rsp), %rdx
movq 0x38(%rsp), %rcx
addq %rdx, %rcx
leaq 0x92686(%rip), %rsi     # 0x132243
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
addq 0x70(%rsp), %r15
movq %r15, 0x20(%rsp)
cmpb $0x0, 0x19(%r14)
jne 0x9fb45
movq %r13, %rdi
callq 0xeb865
movzwl %ax, %eax
movl %eax, 0x20(%r14)
movq 0x18(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0xeebeb
movl %eax, 0x1c(%r14)
movl 0x20(%r14), %edx
leaq 0x7a82d(%rip), %rsi     # 0x11a435
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x1c(%r14), %edx
leaq 0x926b0(%rip), %rsi     # 0x1322cd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x20(%r14), %eax
cmpl 0x1c(%r14), %eax
je 0x9fb45
leaq 0x9262e(%rip), %rsi     # 0x13226a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x9fb45