// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/zoo.c
// Function: de_run_zoo_filter
static void de_run_zoo_filter(deark *c, de_module_params *mparams)
{
	dbuf *outf = NULL;
	struct de_crcobj *crco = NULL;
	int use_lzh = 0;
	u32 crc_reported;
	u32 crc_calculated;
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;

	if(c->infile->len<6) goto done;

	use_lzh = de_get_ext_option_bool(c, "zoo_filter:lzh", -1);
	if(use_lzh<0) {
		if(dbuf_is_all_zeroes(c->infile, c->infile->len-4, 2)) {
			use_lzh = 1;
		}
		else {
			use_lzh = 0;
		}
	}

	de_declare_fmtf(c, "Zoo filter, LZ%s", (use_lzh?"H":"D"));

	crc_reported = (u32)de_getu32le(c->infile->len-2);
	de_dbg(c, "crc (reported): 0x%04x", (UI)crc_reported);

	outf = dbuf_create_output_file(c, "bin", NULL, 0);
	dbuf_enable_wbuffer(outf);
	crco = de_crcobj_create(c, DE_CRCOBJ_CRC16_ARC);
	dbuf_set_writelistener(outf, de_writelistener_for_crc, (void*)crco);

	de_dfilter_init_objects(c, &dcmpri, &dcmpro, &dres);
	dcmpri.f = c->infile;
	dcmpri.pos = 2;
	dcmpri.len = c->infile->len - 4;

	dcmpro.f = outf;
	dcmpro.len_known = 0;

	if(use_lzh) {
		decompress_lzh(c, &dcmpri, &dcmpro, &dres);
	}
	else {
		decompress_lzd(c, &dcmpri, &dcmpro, &dres);
	}
	dbuf_flush(dcmpro.f);

	if(dres.errcode) {
		de_err(c, "%s", de_dfilter_get_errmsg(c, &dres));
		goto done;
	}

	crc_calculated = de_crcobj_getval(crco);
	de_dbg(c, "crc (calculated): 0x%04x", (UI)crc_calculated);
	if(crc_calculated != crc_reported) {
		de_err(c, "CRC check failed");
		goto done;
	}

done:
	dbuf_close(outf);
	de_crcobj_destroy(crco);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x6, 0x18(%rax)
jge 0x14e3fe
jmp 0x14e607
movq -0x8(%rbp), %rdi
leaq 0x8278e(%rip), %rsi     # 0x1d0b97
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x15cbc0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x14e455
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rsi
subq $0x4, %rsi
movl $0x2, %edx
callq 0x169d30
cmpl $0x0, %eax
je 0x14e44c
movl $0x1, -0x24(%rbp)
jmp 0x14e453
movl $0x0, -0x24(%rbp)
jmp 0x14e455
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %ecx
leaq 0x895ca(%rip), %rdx     # 0x1d7a2d
leaq 0x7f9ea(%rip), %rax     # 0x1cde54
cmpl $0x0, %ecx
cmovneq %rax, %rdx
leaq 0x8272e(%rip), %rsi     # 0x1d0ba6
movb $0x0, %al
callq 0x15e3d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rsi
subq $0x2, %rsi
callq 0x165540
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %edx
leaq 0x8249f(%rip), %rsi     # 0x1d094c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
leaq 0x72d48(%rip), %rsi     # 0x1c1207
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movl $0x21, %esi
callq 0x15eac0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x1add8(%rip), %rsi     # 0x1692d0
callq 0x169280
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0x1773f0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movq $0x2, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
subq $0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movb $0x0, -0x60(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x14e569
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0x150490
jmp 0x14e581
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0x150430
movq -0x68(%rbp), %rdi
callq 0x167c30
cmpl $0x0, -0xc8(%rbp)
je 0x14e5c8
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x177360
movq -0xd0(%rbp), %rdi
movq %rax, %rdx
leaq 0x52570(%rip), %rsi     # 0x1a0b2f
movb $0x0, %al
callq 0x15bfb0
jmp 0x14e607
movq -0x20(%rbp), %rdi
callq 0x15f340
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq 0x52aa5(%rip), %rsi     # 0x1a1087
movb $0x0, %al
callq 0x15b0d0
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0x14e605
movq -0x8(%rbp), %rdi
leaq 0x5241b(%rip), %rsi     # 0x1a0a17
movb $0x0, %al
callq 0x15bfb0
jmp 0x14e607
jmp 0x14e607
movq -0x18(%rbp), %rdi
callq 0x1676a0
movq -0x20(%rbp), %rdi
callq 0x15f2e0
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)