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

	crunchctx = de_malloc(c, sizeof(struct crunch_ctx));

	pos += 2;
	if(!crcr_read_filename_etc(c, pos, &crunchctx->fnd)) goto done;
	pos += crunchctx->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>=0x10 && fmtver_raw<=0x1f) {
		crunchctx->fmtver = 1;
		verstr = "old";
	}
	else if(fmtver_raw>=0x20 && fmtver_raw<=0x2f) {
		crunchctx->fmtver = 2;
		verstr = "new";
	}
	else {
		verstr = "?";
	}
	de_dbg(c, "format version: 0x%02x (%s)", (UI)fmtver_raw, verstr);
	if(crunchctx->fmtver!=0) {
		de_declare_fmtf(c, "Crunch (v%d)", (int)crunchctx->fmtver);
	}

	crunchctx->cksum_type = de_getbyte_p(&pos);
	de_dbg(c, "checksum type: 0x%02x (%s)", (UI)crunchctx->cksum_type,
		(crunchctx->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);
	if(crunchctx->fmtver==1) {
		decompress_crunch_v1(c, crunchctx, pos);
	}
	else {
		// v2 is by far the most common version, but it's not easy to support.
		// We support v1, only because it's easy.
		de_err(c, "This version of Crunch is not supported");
	}

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
movq $0x0, (%rsp)
movl $0x28, %esi
callq 0xe969b
movq %rax, %r14
movq (%rsp), %rsi
addq $0x2, %rsi
movq %rsi, (%rsp)
movq %rbx, %rdi
movq %rax, %rdx
callq 0xa1192
testl %eax, %eax
je 0xa0047
movq 0x10(%r14), %rax
movq %rsp, %r15
addq %rax, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %edx
leaq 0x92203(%rip), %rsi     # 0x131fc0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %edx
movl %edx, %eax
andb $-0x10, %al
cmpb $0x10, %al
je 0x9fdf1
movzbl %al, %eax
cmpl $0x20, %eax
jne 0x9fe00
leaq 0x7e460(%rip), %rcx     # 0x11e24d
movb $0x2, %al
jmp 0x9fdfa
leaq 0x9a6d6(%rip), %rcx     # 0x13a4ce
movb $0x1, %al
movb %al, 0x18(%r14)
jmp 0x9fe07
leaq 0x8c062(%rip), %rcx     # 0x12be69
leaq 0x921ca(%rip), %rsi     # 0x131fd8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movzbl 0x18(%r14), %edx
testl %edx, %edx
je 0x9fe32
leaq 0x921cc(%rip), %rsi     # 0x131ff4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb703
movq 0x18(%rbx), %rdi
movq %rsp, %r15
movq %r15, %rsi
callq 0xef14d
movb %al, 0x19(%r14)
movzbl %al, %edx
testb %dl, %dl
leaq 0x94e04(%rip), %rax     # 0x134c55
leaq 0x8c011(%rip), %rcx     # 0x12be69
cmoveq %rax, %rcx
leaq 0x9219e(%rip), %rsi     # 0x132001
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %edx
leaq 0x92199(%rip), %rsi     # 0x13201c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq (%r15), %rdx
leaq 0x92011(%rip), %rsi     # 0x131ea8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpb $0x1, 0x18(%r14)
jne 0xa0036
movq (%rsp), %rax
movq %rax, 0x8(%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, %al
movb %al, 0x8(%r15)
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, 0x18(%rsp)
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 0x51b3b(%rip), %rsi     # 0xf1a51
movq %r12, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
callq 0xf1a12
leaq 0x20(%rsp), %r15
leaq 0xb8(%rsp), %r13
leaq 0x40(%rsp), %rbp
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0xfa6e0
movq 0x18(%rbx), %rax
movq %rax, (%r15)
movq 0x8(%rsp), %rcx
movq %rcx, 0x8(%r15)
movq 0x18(%rax), %rax
subq %rcx, %rax
movq %rax, 0x10(%r15)
movq %r12, (%r13)
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rax
movaps %xmm0, (%rax)
movl $0x0, 0x10(%rax)
movl $0x7, (%rax)
movb $0x1, %cl
movb %cl, 0x10(%rax)
leaq 0xd0(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x40(%rsi)
leaq 0x62d61(%rip), %rcx     # 0x102d0b
movq %rcx, 0x8(%rsi)
movq %rax, 0x10(%rsi)
leaq 0x5ae44(%rip), %rax     # 0xfadfd
movq %rax, 0x18(%rsi)
movq %r15, 0x28(%rsi)
movq %r13, 0x30(%rsi)
movq %rbp, 0x38(%rsi)
movq %rbx, %rdi
callq 0xfb662
movq (%r13), %rdi
callq 0xf0ea4
cmpl $0x0, (%rbp)
je 0xa007a
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa6a8
leaq 0x74179(%rip), %rsi     # 0x114171
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
movq 0x10(%rsp), %r15
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0xea9b3
movq %r12, %rdi
callq 0xf0b13
movq %r15, %rdi
callq 0xebe1d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
jmp 0xa0047
leaq 0x91ff8(%rip), %rsi     # 0x132035
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
testq %r14, %r14
je 0xa0068
movq (%r14), %rdi
callq 0xf6bb0
movq 0x8(%r14), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x44(%rsp)
movq 0x10(%rsp), %r15
je 0xa000a
movq 0x48(%rsp), %rdx
movq 0x28(%rsp), %rcx
addq %rdx, %rcx
leaq 0x91e25(%rip), %rsi     # 0x131ebf
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x48(%rsp), %rax
addq %rax, 0x8(%rsp)
cmpb $0x0, 0x19(%r14)
jne 0xa000a
movq %r15, %rdi
callq 0xebe2a
movzwl %ax, %eax
movl %eax, 0x20(%r14)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef1ed
movl %eax, 0x1c(%r14)
movl 0x20(%r14), %edx
leaq 0x7a230(%rip), %rsi     # 0x11a315
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x1c(%r14), %edx
leaq 0x91e4f(%rip), %rsi     # 0x131f49
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x20(%r14), %eax
cmpl 0x1c(%r14), %eax
je 0xa000a
leaq 0x91dcd(%rip), %rsi     # 0x131ee6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xa000a