// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/lbr.c
// Function: decompress_crunch_v1
static void decompress_crunch_v1(deark *c, struct crunch_ctx *crunchctx, i64 pos1)
{
	de_finfo *fi = NULL;
	dbuf *outf = NULL;
	i64 pos = pos1;
	struct de_crcobj *crco = NULL;
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;
	struct de_lzw_params delzwp;
	struct de_dcmpr_two_layer_params tlp;

	de_dbg_indent(c, 1);
	fi = de_finfo_create(c);
	de_finfo_set_name_from_ucstring(c, fi, crunchctx->fnd.fn, 0);
	fi->original_filename_flag = 1;

	outf = dbuf_create_output_file(c, NULL, fi, 0x0);
	dbuf_enable_wbuffer(outf);
	crco = de_crcobj_create(c, DE_CRCOBJ_SUM_BYTES);
	dbuf_set_writelistener(outf, de_writelistener_for_crc, (void*)crco);

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

	de_zeromem(&delzwp, sizeof(struct de_lzw_params));
	delzwp.fmt = DE_LZWFMT_ARC5;
	delzwp.arc5_has_stop_code = 1;

	de_zeromem(&tlp, sizeof(struct de_dcmpr_two_layer_params));
	tlp.codec1_pushable = dfilter_lzw_codec;
	tlp.codec1_private_params = (void*)&delzwp;
	tlp.codec2 = dfilter_rle90_codec;
	tlp.dcmpri = &dcmpri;
	tlp.dcmpro = &dcmpro;
	tlp.dres = &dres;
	de_dfilter_decompress_two_layer(c, &tlp);
	dbuf_flush(dcmpro.f);

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

	if(dres.bytes_consumed_valid) {
		de_dbg(c, "compressed data size: %"I64_FMT", ends at %"I64_FMT, dres.bytes_consumed,
			dcmpri.pos+dres.bytes_consumed);
		pos += dres.bytes_consumed;

		if(crunchctx->cksum_type==0) {
			crunchctx->checksum_calc = de_crcobj_getval(crco);
			crunchctx->checksum_calc &= 0xffff;
			crunchctx->checksum_reported = (UI)de_getu16le_p(&pos);
			de_dbg(c, "checksum (calculated): %u", crunchctx->checksum_calc);
			de_dbg(c, "checksum (reported): %u", crunchctx->checksum_reported);
			if(crunchctx->checksum_calc != crunchctx->checksum_reported) {
				de_err(c, "Checksum error. Decompression probably failed.");
				goto done;
			}
		}
	}

done:
	de_finfo_destroy(c, fi);
	dbuf_close(outf);
	de_crcobj_destroy(crco);
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x20(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
movl $0x30, %esi
callq 0x15eac0
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x7c7af(%rip), %rsi     # 0x1692d0
callq 0x169280
movq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
callq 0x1773f0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0xe4(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x19140
movl $0x7, -0xe4(%rbp)
movb $0x1, -0xd4(%rbp)
leaq -0x138(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x19140
leaq 0x97854(%rip), %rax     # 0x184400
movq %rax, -0x130(%rbp)
leaq -0xe4(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq 0x8b418(%rip), %rax     # 0x177fe0
movq %rax, -0x120(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0xd0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x178cf0
movq -0x70(%rbp), %rdi
callq 0x167c30
cmpl $0x0, -0xd0(%rbp)
je 0xecc4d
movq -0x8(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x177360
movq -0x140(%rbp), %rdi
movq %rax, %rdx
leaq 0xb33bc(%rip), %rsi     # 0x19fffd
movb $0x0, %al
callq 0x15bfb0
jmp 0xecd36
cmpb $0x0, -0xcc(%rbp)
je 0xecd34
movq -0x8(%rbp), %rdi
movq -0xc8(%rbp), %rdx
movq -0x50(%rbp), %rcx
addq -0xc8(%rbp), %rcx
leaq 0xd0f83(%rip), %rsi     # 0x1bdbfa
movb $0x0, %al
callq 0x15b0d0
movq -0xc8(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x19(%rax), %eax
cmpl $0x0, %eax
jne 0xecd32
movq -0x38(%rbp), %rdi
callq 0x15f340
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x20(%rax), %edx
leaq 0xb93a9(%rip), %rsi     # 0x1a6095
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %edx
leaq 0xd0f7f(%rip), %rsi     # 0x1bdc84
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
je 0xecd30
movq -0x8(%rbp), %rdi
leaq 0xd0efa(%rip), %rsi     # 0x1bdc21
movb $0x0, %al
callq 0x15bfb0
jmp 0xecd36
jmp 0xecd32
jmp 0xecd34
jmp 0xecd36
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15d260
movq -0x28(%rbp), %rdi
callq 0x1676a0
movq -0x38(%rbp), %rdi
callq 0x15f2e0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopl (%rax)