// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x10
popq %rax
pushq $0x38
popq %rbp
cmoveq %rax, %rbp
cmpb $0x0, 0x2(%rcx)
je 0xce5b5
movq %rcx, %r14
movq 0x20(%rcx), %rax
movq 0x10(%rcx), %rcx
orq %rax, %rcx
jne 0xce5bd
xorl %r14d, %r14d
jmp 0xce6b1
movq %rdi, %rbx
addq 0x18(%r14), %rax
movq 0x18(%rdi), %rcx
cmpq 0x18(%rcx), %rax
jle 0xce5e7
leaq 0x3771f(%rip), %rsi     # 0x105cf4
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0xce6b1
movq %rdx, %r12
movq %rsi, %r15
movzbl 0x3(%r14), %edx
movq 0x30(%r14), %rax
testq %rax, %rax
je 0xce601
movq 0x8(%rax), %rcx
jmp 0xce608
leaq 0x508d9(%rip), %rcx     # 0x11eee1
leaq 0x4d195(%rip), %rsi     # 0x11b7a4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x30(%r14), %rax
testq %rax, %rax
je 0xce639
cmpq $0x0, 0x10(%rax)
je 0xce654
cmpb $0x0, 0x4(%r14)
je 0xce688
leaq 0x6f3ea(%rip), %rsi     # 0x13da21
jmp 0xce5d5
movzbl 0x3(%r14), %edx
leaq 0x669cb(%rip), %rsi     # 0x135010
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0xce6b1
movq 0x18(%r12), %rdi
callq 0xeb877
movzbl 0x3(%r14), %r8d
movq 0x28(%r14), %rcx
movq 0x30(%r14), %rdx
movq 0x8(%rdx), %r9
leaq 0x669b9(%rip), %rsi     # 0x13502f
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
jmp 0xce6b1
leaq 0x17c32(%rip), %rax     # 0xe62c1
movq %rax, 0x20(%r13,%rbp)
cmpb $0x0, (%r14)
je 0xce6a0
movq 0x28(%r15), %rdi
jmp 0xce6a4
movq 0x30(%r15), %rdi
movq %rdi, 0x18(%r13,%rbp)
callq 0xe0e44
movb $0x1, %r14b
movb %r14b, (%r13,%rbp)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq