// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/packdir.c
// Function: do_packdir_extract_file
static void do_packdir_extract_file(deark *c, struct pdctx_struct *d,
	struct pdctx_object *md, i64 pos)
{
	dbuf *outf = NULL;
	de_finfo *fi = NULL;
	de_ucstring *fullfn = NULL;

	de_dbg(c, "%"I64_FMT" bytes of %scompressed data at %"I64_FMT,
		md->cmpr_len, (md->is_compressed?"":"un"), pos);

	if(pos + md->cmpr_len > c->infile->len) {
		de_err(c, "Unexpected EOF");
		goto done;
	}

	fi = de_finfo_create(c);

	fullfn = ucstring_create(c);
	if(md->is_dir) {
		fi->is_directory = 1;
		de_strarray_make_path(d->curpath, fullfn, DE_MPFLAG_NOTRAILINGSLASH);
	}
	else {
		de_strarray_make_path(d->curpath, fullfn, 0);
		ucstring_append_ucstring(fullfn, md->name);
	}

	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);
	fi->original_filename_flag = 1;

	fi->timestamp[DE_TIMESTAMPIDX_MODIFY] = md->rfa.mod_time;

	fi->has_riscos_data = 1;
	fi->riscos_attribs = md->rfa.attribs;
	fi->load_addr = md->rfa.load_addr;
	fi->exec_addr = md->rfa.exec_addr;

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

	if(md->is_compressed) {
		dbuf_enable_wbuffer(outf);
		do_packdir_file_compressed(c, d, md, pos, outf);
	}
	else {
		dbuf_copy(c->infile, pos, md->cmpr_len, outf);
	}

done:
	dbuf_close(outf);
	de_finfo_destroy(c, fi);
	ucstring_destroy(fullfn);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
movq 0x18(%rdx), %rdx
cmpl $0x0, 0x20(%r12)
leaq 0x54d25(%rip), %rax     # 0x10666f
leaq 0x8630f(%rip), %rcx     # 0x137c60
cmoveq %rax, %rcx
leaq 0x79599(%rip), %rsi     # 0x12aef5
movq %rbp, %r8
xorl %eax, %eax
callq 0xde896
movq 0x18(%r12), %rax
addq %rbp, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xb1997
leaq 0x7959c(%rip), %rsi     # 0x12af1b
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0xb1b76
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r14
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r15
cmpb $0x0, 0x4(%r12)
movq %r13, 0x10(%rsp)
je 0xb19d0
movb $0x1, 0x9(%r14)
movq 0x8(%r13), %rdi
pushq $0x1
popq %rdx
movq %r15, %rsi
callq 0xeba55
jmp 0xb19eb
movq 0x8(%r13), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xeba55
movq 0x28(%r12), %rsi
movq %r15, %rdi
callq 0xead71
leaq 0x30(%r12), %rcx
movzbl 0x4(%r12), %r8d
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %r9d, %r9d
callq 0xeda93
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xdfd55
movb $0x1, %al
movb %al, 0x8(%r14)
movups 0x50(%r12), %xmm0
movups %xmm0, 0x18(%r14)
movb %al, 0x10(%r14)
movl 0x3c(%r12), %eax
movl %eax, 0xa0(%r14)
movq 0x34(%r12), %rax
movq %rax, 0xa4(%r14)
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r13
cmpl $0x0, 0x20(%r12)
je 0xb1b29
movq %r15, 0x8(%rsp)
movq %r13, %rdi
callq 0xe589c
leaq 0xa8(%rsp), %r15
leaq 0x18(%rsp), %rdx
leaq 0x48(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xee7ee
movq 0x18(%rbx), %rax
movq %rax, (%r15)
movq %rbp, 0x8(%r15)
movq 0x18(%r12), %rax
movq %rax, 0x10(%r15)
leaq 0x18(%rsp), %rdx
movq %r13, (%rdx)
movb $0x1, 0x8(%rdx)
movq 0x10(%r12), %rax
movq %rax, 0x10(%rdx)
movq 0x10(%rsp), %rax
movl (%rax), %eax
xorps %xmm0, %xmm0
leaq 0x34(%rsp), %r8
movups %xmm0, 0x4(%r8)
movl $0x4, (%r8)
movl %eax, 0xc(%r8)
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x48(%rsp), %r15
movq %r15, %rcx
callq 0xf644c
movq %r13, %rdi
callq 0xe58e8
cmpl $0x0, (%r15)
je 0xb1b3f
movq 0x28(%r12), %rdi
callq 0xeb877
movq %rax, %r15
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0xee7bc
leaq 0x8a39b(%rip), %rsi     # 0x13beb2
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xdf2a5
jmp 0xb1b71
movq 0x18(%rbx), %rdi
movq 0x18(%r12), %rdx
movq %rbp, %rsi
movq %r13, %rcx
callq 0xe45f4
jmp 0xb1b76
movq 0x18(%r13), %rax
cmpq 0x10(%r12), %rax
je 0xb1b71
movq 0x28(%r12), %rdi
callq 0xeb877
movq 0x10(%r12), %rcx
movq 0x18(%r13), %r8
leaq 0x793c6(%rip), %rsi     # 0x12af2a
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
movq 0x8(%rsp), %r15
movq %r13, %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdfd24
movq %r15, %rdi
callq 0xeaf3c
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop