// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0x140fda
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x38, %rax
movq %rax, -0x28(%rbp)
jmp 0x140fea
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpb $0x0, 0x2(%rax)
jne 0x140ff9
jmp 0x14119c
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x141014
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x141014
jmp 0x14119c
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
addq 0x20(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x141049
movq -0x8(%rbp), %rdi
leaq 0x5dd82(%rip), %rsi     # 0x19edbf
movb $0x0, %al
callq 0x15bfb0
jmp 0x14119c
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movzbl 0x3(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x141079
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x141086
leaq 0x76bad(%rip), %rax     # 0x1b7c2d
movq %rax, -0x40(%rbp)
jmp 0x141086
movl -0x30(%rbp), %edx
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rcx
leaq 0x730e8(%rip), %rsi     # 0x1b4180
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x1410c9
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movzbl 0x3(%rax), %edx
leaq 0x8cf23(%rip), %rsi     # 0x1cdfe0
movb $0x0, %al
callq 0x15bfb0
jmp 0x14119c
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
cmpq $0x0, 0x10(%rax)
jne 0x141121
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x48(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x20(%rbp), %rax
movzbl 0x3(%rax), %r8d
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %r9
leaq 0x8cee7(%rip), %rsi     # 0x1cdfff
movb $0x0, %al
callq 0x15bfb0
jmp 0x14119c
movq -0x20(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x14113f
movq -0x8(%rbp), %rdi
leaq 0x95837(%rip), %rsi     # 0x1d696d
movb $0x0, %al
callq 0x15bfb0
jmp 0x14119c
movl $0x1, -0x2c(%rbp)
movq -0x28(%rbp), %rax
leaq 0x2817f(%rip), %rcx     # 0x1692d0
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0x14117d
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x15f250
jmp 0x14119a
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x15f250
jmp 0x14119c
movl -0x2c(%rbp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)