// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/lbr.c
// Function: decompress_crlzh
static void decompress_crlzh(deark *c, struct crlzh_ctx *crlzhctx, 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_lh1_params lh1p;

	de_dbg_indent(c, 1);
	fi = de_finfo_create(c);
	de_finfo_set_name_from_ucstring(c, fi, crlzhctx->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(&lh1p, sizeof(struct de_lh1_params));
	if(crlzhctx->fmtver==1) {
		lh1p.is_crlzh11 = 1;
	}
	else {
		lh1p.is_crlzh20 = 1;
	}
	lh1p.history_fill_val = 0x20;

	fmtutil_lh1_codectype1(c, &dcmpri, &dcmpro, &dres, (void*)&lh1p);
	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(crlzhctx->cksum_type==0) {
			crlzhctx->checksum_calc = de_crcobj_getval(crco);
			crlzhctx->checksum_calc &= 0xffff;
			crlzhctx->checksum_reported = (UI)de_getu16le_p(&pos);
			de_dbg(c, "checksum (calculated): %u", crlzhctx->checksum_calc);
			de_dbg(c, "checksum (reported): %u", crlzhctx->checksum_reported);
			if(crlzhctx->checksum_calc != crlzhctx->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 $0xe0, %rsp
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 0x7c4af(%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 -0xd5(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x19140
movq -0x10(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x1, %eax
jne 0xece97
movb $0x1, -0xd5(%rbp)
jmp 0xece9e
movb $0x1, -0xd4(%rbp)
movb $0x20, -0xd1(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
leaq -0xd5(%rbp), %r8
callq 0x18b940
movq -0x70(%rbp), %rdi
callq 0x167c30
cmpl $0x0, -0xd0(%rbp)
je 0xecf0e
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x177360
movq -0xe0(%rbp), %rdi
movq %rax, %rdx
leaq 0xb30fb(%rip), %rsi     # 0x19fffd
movb $0x0, %al
callq 0x15bfb0
jmp 0xecff7
cmpb $0x0, -0xcc(%rbp)
je 0xecff5
movq -0x8(%rbp), %rdi
movq -0xc8(%rbp), %rdx
movq -0x50(%rbp), %rcx
addq -0xc8(%rbp), %rcx
leaq 0xd0cc2(%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 0xecff3
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 0xb90e8(%rip), %rsi     # 0x1a6095
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %edx
leaq 0xd0cbe(%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 0xecff1
movq -0x8(%rbp), %rdi
leaq 0xd0c39(%rip), %rsi     # 0x1bdc21
movb $0x0, %al
callq 0x15bfb0
jmp 0xecff7
jmp 0xecff3
jmp 0xecff5
jmp 0xecff7
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 $0xe0, %rsp
popq %rbp
retq
nopl (%rax)