// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x28
popq %rsi
callq 0xdecaf
movq %rax, %r14
movq $0x2, 0x18(%rsp)
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x9aba2
testl %eax, %eax
je 0x99c4b
movq 0x10(%r14), %rax
addq $0x2, %rax
leaq 0x18(%rsp), %r15
movq %rax, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %edx
leaq 0x8b436(%rip), %rsi     # 0x125058
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %edx
cmpb $0x20, %dl
jae 0x99c59
leaq 0x93917(%rip), %rcx     # 0x12d55e
movb $0x1, %al
jmp 0x99c66
testq %r14, %r14
jne 0x99e58
jmp 0x99e6b
cmpb $0x2f, %al
ja 0x99c6c
leaq 0x77625(%rip), %rcx     # 0x111289
movb $0x2, %al
movb %al, 0x18(%r14)
jmp 0x99c73
leaq 0x8526e(%rip), %rcx     # 0x11eee1
leaq 0x8b3f6(%rip), %rsi     # 0x125070
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movzbl 0x18(%r14), %edx
testl %edx, %edx
je 0x99c9e
leaq 0x8b461(%rip), %rsi     # 0x1250f5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe0824
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %r15
movq %r15, %rsi
callq 0xe3f2a
movb %al, 0x19(%r14)
movzbl %al, %edx
testb %dl, %dl
leaq 0x8e042(%rip), %rax     # 0x127d01
leaq 0x8521b(%rip), %rcx     # 0x11eee1
cmoveq %rax, %rcx
leaq 0x8b3c8(%rip), %rsi     # 0x125099
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %edx
leaq 0x8b3c3(%rip), %rsi     # 0x1250b4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq (%r15), %rdx
leaq 0x8b23b(%rip), %rsi     # 0x124f40
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq (%r15), %r15
movq %r15, 0x20(%rsp)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r12
movq (%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xdfd55
movb $0x1, 0x8(%r12)
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, 0x28(%rsp)
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r12
movq %rax, %rdi
callq 0xe589c
pushq $0x30
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
leaq 0x4c54d(%rip), %rsi     # 0xe62c1
movq %r12, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
callq 0xe629a
leaq 0x30(%rsp), %rbp
leaq 0x50(%rsp), %r13
leaq 0x68(%rsp), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xee7ee
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movq %r15, 0x8(%rbp)
movq 0x18(%rax), %rax
subq %r15, %rax
andl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rbp)
movq %r12, (%r13)
cmpb $0x1, 0x18(%r14)
jne 0x99dcf
movb $0x1, 0x8(%rsp)
jmp 0x99dd4
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 0xfa3ca
movq (%r13), %rdi
callq 0xe58e8
cmpl $0x0, (%rbp)
je 0x99e7d
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0xee7bc
leaq 0x6d3a3(%rip), %rsi     # 0x1071c1
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
movq 0x10(%rsp), %r13
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0xdfd24
movq %r12, %rdi
callq 0xe5591
movq %r13, %rdi
callq 0xe0e8d
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %r14, %rdi
callq 0x9ab8c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
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 0x99e30
movq 0x70(%rsp), %rdx
movq 0x38(%rsp), %rcx
addq %rdx, %rcx
leaq 0x8b0ba(%rip), %rsi     # 0x124f57
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
addq 0x70(%rsp), %r15
movq %r15, 0x20(%rsp)
cmpb $0x0, 0x19(%r14)
jne 0x99e30
movq %r13, %rdi
callq 0xe0e95
movzwl %ax, %eax
movl %eax, 0x20(%r14)
movq 0x18(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0xe3fc4
movl %eax, 0x1c(%r14)
movl 0x20(%r14), %edx
leaq 0x7345d(%rip), %rsi     # 0x10d345
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x1c(%r14), %edx
leaq 0x8b0e4(%rip), %rsi     # 0x124fe1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x20(%r14), %eax
cmpl 0x1c(%r14), %eax
je 0x99e30
leaq 0x8b062(%rip), %rsi     # 0x124f7e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x99e30