// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/palmbitmap.c
// Function: de_decompress_image
static int de_decompress_image(deark *c, lctx *d, struct page_ctx *pg,
	dbuf *inf, i64 pos, i64 len, dbuf *unc_pixels)
{
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;
	int retval = 0;
	i64 n;

	de_dfilter_init_objects(c, &dcmpri, &dcmpro, &dres);
	dcmpri.f = inf;
	dcmpri.pos = pos;
	dcmpri.len = len;
	dcmpro.f = unc_pixels;
	dcmpro.expected_len = pg->expected_num_uncmpr_image_bytes;
	dcmpro.len_known = 1;

	if(pg->cmpr_type==PCMPR_SCANLINE) {
		do_decompress_scanline_compression(c, d, pg, &dcmpri, &dcmpro, &dres);
	}
	else if(pg->cmpr_type==PCMPR_RLE) {
		dbuf_enable_wbuffer(unc_pixels);
		do_decompress_rle_compression(c, &dcmpri, &dcmpro, &dres);
	}
	else if(pg->cmpr_type==PCMPR_PACKBITS8) {
		dbuf_enable_wbuffer(unc_pixels);
		fmtutil_decompress_packbits_ex(c, &dcmpri, &dcmpro, &dres, NULL);
	}
	else if(pg->cmpr_type==PCMPR_PACKBITS16) {
			struct de_packbits_params pbparams;

			de_zeromem(&pbparams, sizeof(struct de_packbits_params));
			pbparams.nbytes_per_unit = 2;
			dbuf_enable_wbuffer(unc_pixels);
			fmtutil_decompress_packbits_ex(c, &dcmpri, &dcmpro, &dres, &pbparams);
	}
	else {
		de_err(c, "Unsupported compression type: %u", pg->cmpr_type_field);
		goto done;
	}

	dbuf_flush(unc_pixels);

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

	if(dres.bytes_consumed_valid) {
		n = dres.bytes_consumed;
	}
	else {
		n = len;
	}

	de_dbg(c, "decompressed %"I64_FMT" bytes to %"I64_FMT" bytes", n,
		unc_pixels->len);
	retval = 1;

done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0xcc(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0x1773f0
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x58(%rbp)
movb $0x1, -0x60(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, 0x38(%rax)
jne 0xfdcb8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq -0x68(%rbp), %r8
leaq -0xc8(%rbp), %r9
callq 0xfe170
jmp 0xfdd8f
movq -0x18(%rbp), %rax
cmpl $0x3, 0x38(%rax)
jne 0xfdce8
movq 0x10(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0xfe330
jmp 0xfdd8d
movq -0x18(%rbp), %rax
cmpl $0x4, 0x38(%rax)
jne 0xfdd1a
movq 0x10(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x177e10
jmp 0xfdd8b
movq -0x18(%rbp), %rax
cmpl $0x5, 0x38(%rax)
jne 0xfdd6b
leaq -0xdc(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x19140
movl $0x2, -0xdc(%rbp)
movq 0x10(%rbp), %rdi
callq 0x167b90
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
leaq -0xdc(%rbp), %r8
callq 0x177e10
jmp 0xfdd89
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x34(%rax), %edx
leaq 0xa5b6e(%rip), %rsi     # 0x1a38eb
movb $0x0, %al
callq 0x15bfb0
jmp 0xfde25
jmp 0xfdd8b
jmp 0xfdd8d
jmp 0xfdd8f
movq 0x10(%rbp), %rdi
callq 0x167c30
cmpl $0x0, -0xc8(%rbp)
je 0xfddd6
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x177360
movq -0xe8(%rbp), %rdi
movq %rax, %rdx
leaq 0xa2d62(%rip), %rsi     # 0x1a0b2f
movb $0x0, %al
callq 0x15bfb0
jmp 0xfde25
cmpb $0x0, -0xc4(%rbp)
je 0xfddef
movq -0xc0(%rbp), %rax
movq %rax, -0xd8(%rbp)
jmp 0xfddfa
movq -0x30(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd8(%rbp), %rdx
movq 0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0xa85cf(%rip), %rsi     # 0x1a63e3
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)