// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/arc.c
// Function: do_extract_member_file
static void do_extract_member_file(deark *c, lctx *d, struct member_data *md,
	struct persistent_member_data *pmd, de_finfo *fi, i64 pos)
{
	de_ucstring *fullfn = NULL;
	dbuf *outf = NULL;
	int ignore_failed_crc = 0;
	int saved_indent_level;
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;

	de_dbg_indent_save(c, &saved_indent_level);
	fullfn = ucstring_create(c);

	if(pmd && ucstring_isnonempty(pmd->path)) {
		// For PAK-style paths.
		// (Pretty useless, until we support cmpr. meth. #11.)
		// Note that PAK-style paths, and directory recursion, are not expected to
		// be possible in the same file.
		ucstring_append_ucstring(fullfn, pmd->path);
		fixup_path(c, d, fullfn);
	}

	de_strarray_make_path(d->curpath, fullfn, DE_MPFLAG_NOTRAILINGSLASH);

	if(md->rfa.file_type_known) {
		fmtutil_riscos_append_type_to_filename(c, fi, fullfn, &md->rfa, md->is_dir, 0);
	}
	de_finfo_set_name_from_ucstring(c, fi, fullfn, DE_SNFLAG_FULLPATH);

	de_dbg_indent(c, 1);

	if(!md->cmi || !md->cmi->decompressor) {
		const char *mname;

		// A quick hack because we don't want the error message claiming that
		// "trimmed or crushed" isn't supported. We do support trimmed, so
		// if we got here, we must have decided it's crushed.
		mname = md->cmpr_meth==10 ? "crushed" : md->cmpr_meth_name;

		de_err(c, "%s: Compression type 0x%02x (%s) is not supported.",
			ucstring_getpsz_d(md->fn), (UI)md->cmpr_meth, mname);
		goto done;
	}

	outf = dbuf_create_output_file(c, NULL, fi, 0x0);
	dbuf_enable_wbuffer(outf);

	dbuf_set_writelistener(outf, de_writelistener_for_crc, (void*)d->crco);
	de_crcobj_reset(d->crco);

	de_dfilter_init_objects(c, &dcmpri, &dcmpro, &dres);
	dcmpri.f = c->infile;
	dcmpri.pos = pos;
	dcmpri.len = md->cmpr_size;
	dcmpro.f = outf;
	dcmpro.len_known = 1;
	dcmpro.expected_len = md->orig_size;

	if(dcmpri.pos + dcmpri.len > dcmpri.f->len) {
		de_err(c, "%s: Data goes beyond end of file", ucstring_getpsz_d(md->fn));
		goto done;
	}

	md->cmi->decompressor(c, d, md, &dcmpri, &dcmpro, &dres);
	dbuf_flush(dcmpro.f);
	if(dres.errcode) {
		de_err(c, "%s: Decompression failed: %s", ucstring_getpsz_d(md->fn),
			de_dfilter_get_errmsg(c, &dres));
		goto done;
	}

	md->crc_calc = de_crcobj_getval(d->crco);
	de_dbg(c, "crc (calculated): 0x%04x", (unsigned int)md->crc_calc);
	if(md->crc_reported==0 && !d->recurse_subdirs && md->rfa.file_type_known &&
		md->rfa.file_type==0xddc && md->cmpr_meth==0x82)
	{
		ignore_failed_crc = 1;
	}
	if((md->crc_calc!=md->crc_reported) && !ignore_failed_crc) {
		de_err(c, "%s: CRC check failed", ucstring_getpsz_d(md->fn));
	}

done:
	dbuf_close(outf);
	ucstring_destroy(fullfn);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, 0x18(%rsp)
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x4(%rsp), %rsi
callq 0xe958c
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r14
testq %rbp, %rbp
je 0x281d0
movq 0x8(%rbp), %rdi
callq 0xf6c00
testl %eax, %eax
je 0x281d0
movq 0x8(%rbp), %rsi
movq %r14, %rdi
callq 0xf6969
movq 0x10(%r14), %rax
testq %rax, %rax
jle 0x281d0
movq 0x8(%r14), %rcx
xorl %edx, %edx
cmpl $0x5c, (%rcx,%rdx,4)
jne 0x281b4
movl $0x2f, (%rcx,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x281a7
cmpl $0x2f, -0x4(%rcx,%rax,4)
je 0x281d0
movq %r14, %rdi
movl $0x2f, %esi
callq 0xf69a2
movq 0x50(%r12), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xf776e
leaq 0x60(%r15), %rbp
cmpb $0x0, 0x60(%r15)
je 0x28208
movl 0x90(%r15), %r8d
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbp, %rcx
xorl %r9d, %r9d
callq 0xf9907
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movl $0x1, %ecx
callq 0xea9e4
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r15), %rax
testq %rax, %rax
je 0x282f7
cmpq $0x0, 0x10(%rax)
je 0x282f7
movq %rbp, 0x10(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r13
movq %rax, %rdi
callq 0xf0e3f
movq 0x48(%r12), %rdx
leaq 0xc97e6(%rip), %rsi     # 0xf1a51
movq %r13, %rdi
callq 0xf1a12
movq 0x48(%r12), %rdi
callq 0xebdc3
leaq 0x38(%rsp), %rbp
movq %r12, 0x8(%rsp)
leaq 0x20(%rsp), %r12
leaq 0x58(%rsp), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0xfa6e0
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movq 0x18(%rsp), %rsi
movq %rsi, 0x8(%rbp)
movq 0x38(%r15), %rcx
movq %rcx, 0x10(%rbp)
movq %r13, (%r12)
movb $0x1, 0x8(%r12)
movq 0x28(%r15), %rdx
movq %rdx, 0x10(%r12)
addq %rsi, %rcx
cmpq 0x18(%rax), %rcx
jle 0x28361
movq 0x48(%r15), %rdi
callq 0xf7557
leaq 0xec835(%rip), %rsi     # 0x114b1d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
jmp 0x28333
cmpb $0xa, 0x10(%r15)
jne 0x28307
leaq 0xec670(%rip), %r12     # 0x114975
jmp 0x2830b
movq 0x20(%r15), %r12
movq 0x48(%r15), %rdi
callq 0xf7557
movzbl 0x10(%r15), %ecx
leaq 0xec772(%rip), %rsi     # 0x114a92
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rax, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0xe9df7
movq %r13, %rdi
callq 0xf0b13
movq %r14, %rdi
callq 0xf6bb0
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%r15), %rax
leaq 0x38(%rsp), %rcx
leaq 0x20(%rsp), %r12
leaq 0x58(%rsp), %rbp
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %r12, %r8
movq %rbp, %r9
callq *0x10(%rax)
movq (%r12), %rdi
callq 0xf0ea4
cmpl $0x0, (%rbp)
je 0x283cc
movq 0x48(%r15), %rdi
callq 0xf7557
movq %rax, %r15
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa6a8
leaq 0xebdb6(%rip), %rsi     # 0x11416d
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9df7
jmp 0x28333
movq 0x8(%rsp), %r12
movq 0x48(%r12), %rdi
callq 0xebe2a
movl %eax, 0x44(%r15)
leaq 0xece4d(%rip), %rsi     # 0x115233
xorl %ebp, %ebp
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl 0x40(%r15), %eax
testl %eax, %eax
jne 0x28406
cmpl $0x0, 0x20(%r12)
je 0x2842e
xorl %ebp, %ebp
testb %bpl, %bpl
jne 0x28333
cmpl %eax, 0x44(%r15)
je 0x28333
movq 0x48(%r15), %rdi
callq 0xf7557
leaq 0xec743(%rip), %rsi     # 0x114b6c
jmp 0x282e8
movq 0x10(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x28404
cmpl $0xddc, 0x70(%r15)      # imm = 0xDDC
jne 0x28404
cmpb $-0x7e, 0x10(%r15)
sete %bpl
jmp 0x28406