// File: /workspace/github_c_makefile_star2_O3/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 0xe8a1c
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r14
testq %rbp, %rbp
je 0x28191
movq 0x8(%rbp), %rdi
callq 0xf67a3
testl %eax, %eax
je 0x28191
movq 0x8(%rbp), %rsi
movq %r14, %rdi
callq 0xf6509
movq 0x10(%r14), %rax
testq %rax, %rax
jle 0x28191
movq 0x8(%r14), %rcx
xorl %edx, %edx
cmpl $0x5c, (%rcx,%rdx,4)
jne 0x28175
movl $0x2f, (%rcx,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x28168
cmpl $0x2f, -0x4(%rcx,%rax,4)
je 0x28191
movq %r14, %rdi
movl $0x2f, %esi
callq 0xf6542
movq 0x50(%r12), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xf730d
leaq 0x60(%r15), %rbp
cmpb $0x0, 0x60(%r15)
je 0x281c9
movl 0x90(%r15), %r8d
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbp, %rcx
xorl %r9d, %r9d
callq 0xf93ff
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movl $0x1, %ecx
callq 0xea53f
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r15), %rax
testq %rax, %rax
je 0x282b8
cmpq $0x0, 0x10(%rax)
je 0x282b8
movq %rbp, 0x10(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r13
movq %rax, %rdi
callq 0xf0855
movq 0x48(%r12), %rdx
leaq 0xc9225(%rip), %rsi     # 0xf1451
movq %r13, %rdi
callq 0xf1412
movq 0x48(%r12), %rdi
callq 0xeb7fe
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 0xfa1dc
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 0x28322
movq 0x48(%r15), %rdi
callq 0xf70f6
leaq 0xec94f(%rip), %rsi     # 0x114bf8
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
jmp 0x282f4
cmpb $0xa, 0x10(%r15)
jne 0x282c8
leaq 0xec78a(%rip), %r12     # 0x114a50
jmp 0x282cc
movq 0x20(%r15), %r12
movq 0x48(%r15), %rdi
callq 0xf70f6
movzbl 0x10(%r15), %ecx
leaq 0xec88c(%rip), %rsi     # 0x114b6d
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rax, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0xe9295
movq %r13, %rdi
callq 0xf052b
movq %r14, %rdi
callq 0xf6753
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
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 0xf08ba
cmpl $0x0, (%rbp)
je 0x2838d
movq 0x48(%r15), %rdi
callq 0xf70f6
movq %rax, %r15
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa1a4
leaq 0xebea5(%rip), %rsi     # 0x11421d
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9295
jmp 0x282f4
movq 0x8(%rsp), %r12
movq 0x48(%r12), %rdi
callq 0xeb865
movl %eax, 0x44(%r15)
leaq 0xecf3c(%rip), %rsi     # 0x1152e3
xorl %ebp, %ebp
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl 0x40(%r15), %eax
testl %eax, %eax
jne 0x283c7
cmpl $0x0, 0x20(%r12)
je 0x283ef
xorl %ebp, %ebp
testb %bpl, %bpl
jne 0x282f4
cmpl %eax, 0x44(%r15)
je 0x282f4
movq 0x48(%r15), %rdi
callq 0xf70f6
leaq 0xec85d(%rip), %rsi     # 0x114c47
jmp 0x282a9
movq 0x10(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x283c5
cmpl $0xddc, 0x70(%r15)      # imm = 0xDDC
jne 0x283c5
cmpb $-0x7e, 0x10(%r15)
sete %bpl
jmp 0x283c7