// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/aldus.c
// Function: decompress_fork
static void decompress_fork(deark *c, lctx *d, struct fork_data *fkd,
	dbuf *outf)
{
	i64 i;
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;

	for(i=0; i<fkd->nsegs; i++) {
		i64 len1, len_diff;

		de_dfilter_init_objects(c, &dcmpri, &dcmpro, &dres);

		dcmpri.f = c->infile;
		dcmpri.pos = fkd->sdata[i].cmpr_pos;
		dcmpri.len = fkd->sdata[i].cmpr_len;
		dcmpro.f = outf;

		dbuf_flush(dcmpro.f);
		len1 = dcmpro.f->len;

		if(d->fmtcode==1) {
			struct de_lzw_params delzwp;

			de_zeromem(&delzwp, sizeof(struct de_lzw_params));
			delzwp.fmt = DE_LZWFMT_TIFFNEW;
			delzwp.max_code_size = 12;
			fmtutil_decompress_lzw(c, &dcmpri, &dcmpro, &dres, &delzwp);
		}
		else {
			// Each segment seems to be compressed independently. They don't
			// share a history buffer.
			// TODO: It's not efficient to start over for each segment, because
			// DCL Implode has some overhead. We should have a better way to do it.
			fmtutil_dclimplode_codectype1(c, &dcmpri, &dcmpro, &dres, NULL);
		}
		dbuf_flush(dcmpro.f);

		if(dres.errcode) {
			de_err(c, "[%s fork, seg %"I64_FMT"] Decompression failed: %s",
				fkd->forkname, i, de_dfilter_get_errmsg(c, &dres));
			goto done;
		}

		len_diff = dcmpro.f->len - len1;
		if(len_diff != fkd->sdata[i].orig_len) {
			de_err(c, "[%s fork, seg %"I64_FMT"] Expected %"I64_FMT" bytes, "
				"got %"I64_FMT, fkd->forkname, i, fkd->sdata[i].orig_len,
				len_diff);
			goto done;
		}
	}

	fkd->decompress_succeeded = 1;

done:
	if(!fkd->decompress_succeeded) {
		d->errflag = 1;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jge 0x4e6f9
movq -0x8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x60(%rbp), %rdx
leaq -0xc0(%rbp), %rcx
callq 0x1773f0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
imulq $0x18, -0x28(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
imulq $0x18, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x167c30
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x4e5e9
leaq -0xe4(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x19140
movl $0x6, -0xe4(%rbp)
movl $0xc, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x60(%rbp), %rdx
leaq -0xc0(%rbp), %rcx
leaq -0xe4(%rbp), %r8
callq 0x1843b0
jmp 0x4e606
movq -0x8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x60(%rbp), %rdx
leaq -0xc0(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x17faa0
movq -0x60(%rbp), %rdi
callq 0x167c30
cmpl $0x0, -0xc0(%rbp)
je 0x4e678
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x177360
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rdx
movq -0xf0(%rbp), %rcx
movq %rax, %r8
leaq 0x1566d7(%rip), %rsi    # 0x1a4d43
movb $0x0, %al
callq 0x15bfb0
jmp 0x4e701
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
subq -0xc8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x38(%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpq 0x10(%rcx), %rax
je 0x4e6e6
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
imulq $0x18, -0x28(%rbp), %rsi
addq %rsi, %rax
movq 0x10(%rax), %r8
movq -0xd0(%rbp), %r9
leaq 0x156692(%rip), %rsi    # 0x1a4d6f
movb $0x0, %al
callq 0x15bfb0
jmp 0x4e701
jmp 0x4e6e8
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x4e513
movq -0x18(%rbp), %rax
movb $0x1, 0x2(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x2(%rax)
jne 0x4e713
movq -0x10(%rbp), %rax
movb $0x1, 0x8(%rax)
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)