// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x28
popq %rsi
callq 0xdecaf
movq %rax, %r14
movq $0x2, 0x8(%rsp)
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x9aba2
testl %eax, %eax
je 0x99842
movq 0x10(%r14), %rax
addq $0x2, %rax
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %edx
leaq 0x8b84a(%rip), %rsi     # 0x125058
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %edx
movl %edx, %eax
andb $-0x10, %al
cmpb $0x10, %al
je 0x99850
movzbl %al, %eax
cmpl $0x20, %eax
jne 0x9985f
leaq 0x77a4b(%rip), %rcx     # 0x111289
movb $0x2, %al
jmp 0x99859
testq %r14, %r14
jne 0x99aa4
jmp 0x99ab7
leaq 0x93d07(%rip), %rcx     # 0x12d55e
movb $0x1, %al
movb %al, 0x18(%r14)
jmp 0x99866
leaq 0x8567b(%rip), %rcx     # 0x11eee1
leaq 0x8b803(%rip), %rsi     # 0x125070
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movzbl 0x18(%r14), %edx
testl %edx, %edx
je 0x99891
leaq 0x8b805(%rip), %rsi     # 0x12508c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe0824
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xe3f2a
movb %al, 0x19(%r14)
movzbl %al, %edx
testb %dl, %dl
leaq 0x8e44f(%rip), %rax     # 0x127d01
leaq 0x85628(%rip), %rcx     # 0x11eee1
cmoveq %rax, %rcx
leaq 0x8b7d5(%rip), %rsi     # 0x125099
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %edx
leaq 0x8b7d0(%rip), %rsi     # 0x1250b4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq (%r15), %rdx
leaq 0x8b648(%rip), %rsi     # 0x124f40
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpb $0x1, 0x18(%r14)
jne 0x99a93
movq 0x8(%rsp), %r12
movq %r12, 0x18(%rsp)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r15
movq (%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xdfd55
movb $0x1, %al
movb %al, 0x8(%r15)
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, 0x28(%rsp)
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %rbp
movq %rax, %rdi
callq 0xe589c
pushq $0x30
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
leaq 0x4c94d(%rip), %rsi     # 0xe62c1
movq %rbp, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
callq 0xe629a
leaq 0x90(%rsp), %r15
leaq 0xc8(%rsp), %r13
leaq 0x30(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xee7ee
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 0x5ca65(%rip), %rcx     # 0xf6467
movq %rcx, 0x8(%rsi)
movq %rax, 0x10(%rsi)
leaq 0x55432(%rip), %rax     # 0xeee43
movq %rax, 0x18(%rsi)
movq %r15, 0x28(%rsi)
movq %r13, 0x30(%rsi)
leaq 0x30(%rsp), %r15
movq %r15, 0x38(%rsi)
movq %rbx, %rdi
callq 0xef577
movq (%r13), %rdi
callq 0xe58e8
cmpl $0x0, (%r15)
je 0x99ac9
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0xee7bc
leaq 0x6d76c(%rip), %rsi     # 0x1071c1
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
movq 0x10(%rsp), %r15
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0xdfd24
movq 0x20(%rsp), %rdi
callq 0xe5591
movq %r15, %rdi
callq 0xe0e8d
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
jmp 0x99aa4
leaq 0x8b633(%rip), %rsi     # 0x1250cd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %r14, %rdi
callq 0x9ab8c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
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 0x99a67
movq 0x38(%rsp), %rdx
movq 0x98(%rsp), %rcx
addq %rdx, %rcx
leaq 0x8b46b(%rip), %rsi     # 0x124f57
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
addq 0x38(%rsp), %r12
movq %r12, 0x18(%rsp)
cmpb $0x0, 0x19(%r14)
jne 0x99a67
movq %r15, %rdi
callq 0xe0e95
movzwl %ax, %eax
movl %eax, 0x20(%r14)
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xe3fc4
movl %eax, 0x1c(%r14)
movl 0x20(%r14), %edx
leaq 0x7380e(%rip), %rsi     # 0x10d345
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x1c(%r14), %edx
leaq 0x8b495(%rip), %rsi     # 0x124fe1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x20(%r14), %eax
cmpl 0x1c(%r14), %eax
je 0x99a67
leaq 0x8b413(%rip), %rsi     # 0x124f7e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x99a67