// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/stuffit.c
// Function: do_pre_decompress_fork
static void do_pre_decompress_fork(deark *c, lctx *d, struct member_data *md,
	struct fork_data *frk)
{
	struct de_advfile_forkinfo *advfki;
	int ok = 0;

	if(frk->is_rsrc_fork) {
		advfki = &md->advf->rsrcfork;
	}
	else {
		advfki = &md->advf->mainfork;
	}

	if(!frk->is_a_file) {
		goto done;
	}

	// TODO: What is the correct way to determine the nonexistence of a fork?
	if(frk->unc_len==0 && frk->cmpr_len==0) {
		goto done;
	}

	if(frk->cmpr_pos + frk->cmpr_len > c->infile->len) {
		de_err(c, "Unexpected end of file");
		goto done;
	}

	de_dbg(c, "cmpr method: %u (%s)", (unsigned int)frk->cmpr_meth,
		frk->cmi?frk->cmi->name:"?");

	if(!frk->cmi) {
		de_err(c, "Unknown compression method: %u", (unsigned int)frk->cmpr_meth);
		goto done;
	}

	if(!frk->cmi->decompressor) {
		de_err(c, "%s[%s fork]: Unsupported compression method: %u (%s)",
			ucstring_getpsz_d(md->full_fname), frk->forkname,
			(unsigned int)frk->cmpr_meth, frk->cmi->name);
		goto done;
	}

	if(frk->is_encrypted) {
		de_err(c, "Encrypted files are not supported");
		goto done;
	}

	ok = 1;

	advfki->writelistener_cb = de_writelistener_for_crc;
	if(frk->is_rsrc_fork) {
		advfki->userdata_for_writelistener = (void*)d->crco_rfork;
		de_crcobj_reset(d->crco_rfork);
	}
	else {
		advfki->userdata_for_writelistener = (void*)d->crco_dfork;
		de_crcobj_reset(d->crco_dfork);
	}

done:
	advfki->fork_exists = (ok)?1:0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpb $0x0, (%rcx)
movq 0x8(%rdx), %r13
movl $0x10, %eax
movl $0x38, %ebp
cmoveq %rax, %rbp
cmpb $0x0, 0x2(%rcx)
je 0xd82b8
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
cmpq $0x0, 0x10(%rcx)
jne 0xd8290
cmpq $0x0, 0x20(%r14)
je 0xd82b8
movq 0x20(%r14), %rax
addq 0x18(%r14), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xd82cf
leaq 0x3aa5b(%rip), %rsi     # 0x112d04
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xd82bb
xorl %r14d, %r14d
movb %r14b, (%r13,%rbp)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl 0x3(%r14), %edx
movq 0x30(%r14), %rax
testq %rax, %rax
je 0xd82e3
movq 0x8(%rax), %rcx
jmp 0xd82ea
leaq 0x53b7f(%rip), %rcx     # 0x12be69
leaq 0x504c3(%rip), %rsi     # 0x1287b4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x30(%r14), %rax
testq %rax, %rax
je 0xd831b
cmpq $0x0, 0x10(%rax)
je 0xd8336
cmpb $0x0, 0x4(%r14)
je 0xd836d
leaq 0x72628(%rip), %rsi     # 0x14a941
jmp 0xd82a9
movzbl 0x3(%r14), %edx
leaq 0x69c59(%rip), %rsi     # 0x141f80
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xd82bb
movq 0x18(%r12), %rdi
callq 0xf7557
movzbl 0x3(%r14), %r8d
movq 0x28(%r14), %rcx
movq 0x30(%r14), %rdx
movq 0x8(%rdx), %r9
leaq 0x69c47(%rip), %rsi     # 0x141f9f
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
jmp 0xd82bb
leaq 0x196dd(%rip), %rax     # 0xf1a51
movq %rax, 0x20(%r13,%rbp)
cmpb $0x0, (%r14)
je 0xd8385
movq 0x28(%r15), %rdi
jmp 0xd8389
movq 0x30(%r15), %rdi
movq %rdi, 0x18(%r13,%rbp)
callq 0xebdc3
movb $0x1, %r14b
jmp 0xd82bb