// File: /workspace/github_c_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %rdi, %rbx
movl $0x28, %esi
callq 0xe8b2b
movq %rax, %r14
movq $0x2, 0x8(%rsp)
movl $0x2, %esi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xa08e3
testl %eax, %eax
je 0x9f53b
movq 0x10(%r14), %rax
addq $0x2, %rax
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb4b
movzbl %al, %edx
leaq 0x92e3d(%rip), %rsi     # 0x132344
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb4b
movzbl %al, %edx
movl %edx, %eax
andb $-0x10, %al
cmpb $0x10, %al
je 0x9f549
movzbl %al, %eax
cmpl $0x20, %eax
jne 0x9f558
leaq 0x7ee26(%rip), %rcx     # 0x11e35d
movb $0x2, %al
jmp 0x9f552
testq %r14, %r14
jne 0x9f7a3
jmp 0x9f7bf
leaq 0x9b2fe(%rip), %rcx     # 0x13a84e
movb $0x1, %al
movb %al, 0x18(%r14)
jmp 0x9f55f
leaq 0x8cbf2(%rip), %rcx     # 0x12c151
leaq 0x92df6(%rip), %rsi     # 0x13235c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movzbl 0x18(%r14), %edx
testl %edx, %edx
je 0x9f58a
leaq 0x92df8(%rip), %rsi     # 0x132378
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb152
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xeeb4b
movb %al, 0x19(%r14)
movzbl %al, %edx
testb %dl, %dl
leaq 0x95a36(%rip), %rax     # 0x134fe1
leaq 0x8cb9f(%rip), %rcx     # 0x12c151
cmoveq %rax, %rcx
leaq 0x92dc8(%rip), %rsi     # 0x132385
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb4b
movzbl %al, %edx
leaq 0x92dc3(%rip), %rsi     # 0x1323a0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq (%r15), %rdx
leaq 0x92c3b(%rip), %rsi     # 0x13222c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
cmpb $0x1, 0x18(%r14)
jne 0x9f792
movq 0x8(%rsp), %r12
movq %r12, 0x18(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
callq 0xea504
movq %rax, %r15
movq (%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xea53f
movb $0x1, %al
movb %al, 0x8(%r15)
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, 0x28(%rsp)
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %rbp
movq %rax, %rdi
callq 0xf0855
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeb499
leaq 0x51de0(%rip), %rsi     # 0xf1451
movq %rbp, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
callq 0xf1412
leaq 0x90(%rsp), %r15
leaq 0xc8(%rsp), %r13
leaq 0x30(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xfa1dc
movq 0x18(%rbx), %rax
movq %rax, (%r15)
movq %r12, 0x8(%r15)
movq 0x18(%rax), %rax
subq %r12, %rax
movq %rax, 0x10(%r15)
movq %rbp, 0x20(%rsp)
movq %rbp, (%r13)
xorps %xmm0, %xmm0
leaq 0xb4(%rsp), %rax
movups %xmm0, 0x4(%rax)
movl $0x7, (%rax)
movb $0x1, %cl
movb %cl, 0x10(%rax)
leaq 0xe0(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x40(%rsi)
leaq 0x62d1c(%rip), %rcx     # 0x10241b
movq %rcx, 0x8(%rsi)
movq %rax, 0x10(%rsi)
leaq 0x5b1eb(%rip), %rax     # 0xfa8f9
movq %rax, 0x18(%rsi)
movq %r15, 0x28(%rsi)
movq %r13, 0x30(%rsi)
leaq 0x30(%rsp), %r15
movq %r15, 0x38(%rsi)
movq %rbx, %rdi
callq 0xfb10b
movq (%r13), %rdi
callq 0xf08ba
cmpl $0x0, (%r15)
je 0x9f7d1
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa1a4
leaq 0x74acf(%rip), %rsi     # 0x114221
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
movq 0x10(%rsp), %r15
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0xea50e
movq 0x20(%rsp), %rdi
callq 0xf052b
movq %r15, %rdi
callq 0xeb858
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
jmp 0x9f7a3
leaq 0x92c20(%rip), %rsi     # 0x1323b9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq (%r14), %rdi
callq 0xf6753
movq 0x8(%r14), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x34(%rsp)
movq 0x10(%rsp), %r15
je 0x9f764
movq 0x38(%rsp), %rdx
movq 0x98(%rsp), %rcx
addq %rdx, %rcx
leaq 0x92a4f(%rip), %rsi     # 0x132243
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
addq 0x38(%rsp), %r12
movq %r12, 0x18(%rsp)
cmpb $0x0, 0x19(%r14)
jne 0x9f764
movq %r15, %rdi
callq 0xeb865
movzwl %ax, %eax
movl %eax, 0x20(%r14)
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xeebeb
movl %eax, 0x1c(%r14)
movl 0x20(%r14), %edx
leaq 0x7abf6(%rip), %rsi     # 0x11a435
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x1c(%r14), %edx
leaq 0x92a79(%rip), %rsi     # 0x1322cd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x20(%r14), %eax
cmpl 0x1c(%r14), %eax
je 0x9f764
leaq 0x929f7(%rip), %rsi     # 0x13226a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x9f764