// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tiff.c
// Function: decompress_strile
static int decompress_strile(deark *c, lctx *d, struct page_ctx *pg,
	struct decode_page_ctx *dctx, UI plane_idx)
{
	int retval = 0;

	// TODO: Some of our decompressors have significant overhead. This can
	// be a performance issue with TIFF format, which likes to chop up an
	// image into lots of tiny pieces, each of which is compressed
	// independently.
	// We ought to have a way to efficiently reset a decompressor, without
	// having to recreate it entirely.

	dctx->dcmpri.pos = pg->strile_data[dctx->strile_idx].pos;
	dctx->dcmpri.len = pg->strile_data[dctx->strile_idx].len;

	if(dctx->dcmpri.pos + dctx->dcmpri.len > dctx->dcmpri.f->len) {
		dctx->dcmpri.len = dctx->dcmpri.f->len - dctx->dcmpri.pos;
	}
	if(dctx->dcmpri.len<0) dctx->dcmpri.len = 0;
	dctx->dcmpro.f = dctx->unc_strile_dbuf[plane_idx];
	dctx->dcmpro.len_known = 1;
	dctx->dcmpro.expected_len = dctx->strileset_rowspan * dctx->strileset_height;
	de_dfilter_init_objects(c, NULL, NULL, &dctx->dres);

	if(pg->cmi && pg->cmi->decompressor) {
		pg->cmi->decompressor(c, d, pg, dctx);
	}
	else {
		decompress_strile_uncmpr(c, d, pg, dctx);
	}
	dbuf_flush(dctx->dcmpro.f);

	if(dctx->dres.errcode) {
		detiff_err(c, d, pg, "Decompression failed (strip@%d,%d): %s",
			(int)dctx->strileset_xpos, (int)dctx->strileset_ypos,
			de_dfilter_get_errmsg(c, &dctx->dres));
		// TODO?: Better handling of partial failure
		goto done;
	}

	if(dctx->need_to_reverse_nibbles) {
		reverse_nibbles_in_membuf(dctx->dcmpro.f);
	}

	retval = 1;
done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x68(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0xf0(%rax)
movq -0x18(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x68(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0xf8(%rax)
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x20(%rbp), %rcx
addq 0xf8(%rcx), %rax
movq -0x20(%rbp), %rcx
movq 0xe8(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x135a20
movq -0x20(%rbp), %rax
movq 0xe8(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x20(%rbp), %rax
subq 0xf0(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0xf8(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
jge 0x135a3d
movq -0x20(%rbp), %rax
movq $0x0, 0xf8(%rax)
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movq 0x70(%rax,%rcx,8), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x108(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x110(%rax)
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x20(%rbp), %rax
imulq 0x50(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x118(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rcx
addq $0x120, %rcx            # imm = 0x120
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x1773f0
movq -0x18(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
je 0x135ad9
movq -0x18(%rbp), %rax
movq 0xa8(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x135ad9
movq -0x18(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq *%rax
jmp 0x135aee
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x1335c0
movq -0x20(%rbp), %rax
movq 0x108(%rax), %rdi
callq 0x167c30
movq -0x20(%rbp), %rax
cmpl $0x0, 0x120(%rax)
je 0x135b75
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x120, %rsi            # imm = 0x120
callq 0x177360
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl -0x30(%rbp), %r8d
movl -0x2c(%rbp), %r9d
leaq 0x95d6a(%rip), %rcx     # 0x1cb8d2
movq %rax, (%rsp)
movb $0x0, %al
callq 0x12ee30
jmp 0x135b99
movq -0x20(%rbp), %rax
cmpb $0x0, 0xd2(%rax)
je 0x135b92
movq -0x20(%rbp), %rax
movq 0x108(%rax), %rdi
callq 0x135bb0
movl $0x1, -0x28(%rbp)
movl -0x28(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)