// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/lha.c
// Function: do_extract_file
static void do_extract_file(deark *c, lctx *d, struct member_data *md)
{
	de_finfo *fi = NULL;
	dbuf *outf = NULL;
	int tsidx;
	u8 dcmpr_disabled = 0;
	u8 dcmpr_attempted = 0;
	u8 dcmpr_ok = 0;
	struct de_dfilter_in_params dcmpri;
	struct de_dfilter_out_params dcmpro;
	struct de_dfilter_results dres;

	if(!md->cmi) goto done;

	if(md->is_special) {
		de_dbg(c, "[not extracting special file]");
		goto done;
	}
	else if(md->is_dir) {
		;
	}
	else if((!md->cmi->decompressor) || dcmpr_disabled) {
		de_err(c, "%s: Unsupported compression method '%s'",
			ucstring_getpsz_d(md->fullfilename), md->cmi->id_printable_sz);
		goto done;
	}

	if(md->compressed_data_pos+md->compressed_data_len > c->infile->len) {
		de_err(c, "%s: Data goes beyond end of file", ucstring_getpsz_d(md->fullfilename));
		goto done;
	}

	fi = de_finfo_create(c);

	for(tsidx=0; tsidx<DE_TIMESTAMPIDX_COUNT; tsidx++) {
		if(md->tsdata[tsidx].ts.is_valid) {
			fi->timestamp[tsidx] = md->tsdata[tsidx].ts;
		}
	}

	if(md->is_dir) {
		fi->is_directory = 1;
	}
	else if(md->is_executable) {
		fi->mode_flags |= DE_MODEFLAG_EXE;
	}
	else if(md->is_nonexecutable) {
		fi->mode_flags |= DE_MODEFLAG_NONEXE;
	}

	de_finfo_set_name_from_ucstring(c, fi, md->fullfilename, DE_SNFLAG_FULLPATH);
	fi->original_filename_flag = 1;

	outf = dbuf_create_output_file(c, NULL, fi, 0x0);
	dbuf_enable_wbuffer(outf);
	de_crcobj_reset(d->crco);
	dbuf_set_writelistener(outf, de_writelistener_for_crc, (void*)d->crco);

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

	if(md->is_dir) goto done; // For directories, we're done.

	dcmpr_attempted = 1;
	if(md->cmi->decompressor) {
		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->fullfilename),
			de_dfilter_get_errmsg(c, &dres));
		goto done;
	}

	if(md->have_crc_reported) {
		u32 crc_calc;

		crc_calc = de_crcobj_getval(d->crco);
		if(d->basefmt==BASEFMT_PAKLEO) {
			de_dbg(c, "crc (calculated): 0x%08x", (UI)crc_calc);
		}
		else {
			de_dbg(c, "crc (calculated): 0x%04x", (UI)crc_calc);
		}
		if(crc_calc != md->crc_reported) {
			de_err(c, "%s: CRC check failed", ucstring_getpsz_d(md->fullfilename));
			goto done;
		}
	}

	dcmpr_ok = 1;

done:
	if(dcmpr_attempted && md->cmi && md->cmi->uniq_id==CODE_lh7) {
		if(dcmpr_ok)
			d->lh7_success_flag = 1;
		else
			d->lh7_failed_flag = 1;
	}
	dbuf_close(outf);
	de_finfo_destroy(c, fi);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
movq 0x18(%rdx), %rax
testq %rax, %rax
je 0x8216f
movq %rdx, %r12
cmpb $0x0, 0x21(%rdx)
je 0x82177
leaq 0x9d0b1(%rip), %rsi     # 0x11f20e
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
jmp 0x8223f
xorl %r14d, %r14d
jmp 0x8223f
movq %rsi, %r15
cmpb $0x0, 0x20(%r12)
jne 0x8218d
cmpq $0x0, 0x8(%rax)
je 0x82215
movq 0x60(%r12), %rax
addq 0x58(%r12), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x821c4
movq 0x78(%r12), %rdi
callq 0xeb877
leaq 0x859bb(%rip), %rsi     # 0x107b6d
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
jmp 0x8223f
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r14
leaq 0x80(%r12), %rax
pushq $0x18
popq %rcx
cmpq $0x68, %rcx
je 0x821f7
cmpb $0x0, (%rax)
je 0x821ed
movups (%rax), %xmm0
movups %xmm0, (%r14,%rcx)
addq $0x10, %rcx
addq $0x18, %rax
jmp 0x821da
cmpb $0x0, 0x20(%r12)
je 0x82206
movb $0x1, 0x9(%r14)
jmp 0x82274
cmpb $0x0, 0x23(%r12)
je 0x82267
orb $0x2, 0x14(%r14)
jmp 0x82274
movq 0x78(%r12), %rdi
callq 0xeb877
movq 0x18(%r12), %rcx
addq $0x15, %rcx
leaq 0x9cffd(%rip), %rsi     # 0x11f22c
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
xorl %r13d, %r13d
movq %r13, %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdfd24
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x22(%r12)
je 0x82274
orb $0x1, 0x14(%r14)
movq 0x78(%r12), %rdx
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xdfd55
movb $0x1, %al
movb %al, 0x8(%r14)
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r13
movq %rax, %rdi
callq 0xe589c
movq 0x28(%r15), %rdi
callq 0xe0e44
movq 0x28(%r15), %rdx
leaq 0x64006(%rip), %rsi     # 0xe62c1
movq %r13, %rdi
callq 0xe629a
movq %r15, 0x8(%rsp)
leaq 0x28(%rsp), %rbp
leaq 0x10(%rsp), %r15
leaq 0x48(%rsp), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0xee7ee
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movups 0x58(%r12), %xmm0
movups %xmm0, 0x8(%rbp)
movq %r13, (%r15)
movq 0x28(%r12), %rax
movq %rax, 0x10(%r15)
movb $0x1, %al
movb %al, 0x8(%r15)
cmpb $0x0, 0x20(%r12)
jne 0x82242
movq 0x18(%r12), %rax
movq 0x8(%rax), %rax
movq %r13, %rdi
testq %rax, %rax
movq 0x8(%rsp), %rbp
je 0x8234b
leaq 0x28(%rsp), %rcx
leaq 0x10(%rsp), %r15
leaq 0x48(%rsp), %r9
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %r8
callq *%rax
movq (%r15), %rdi
callq 0xe58e8
cmpl $0x0, 0x48(%rsp)
je 0x823b4
movq 0x78(%r12), %rdi
callq 0xeb877
movq %rax, %r15
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0xee7bc
leaq 0x84e45(%rip), %rsi     # 0x1071bd
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xdf2a5
movb $0x1, %r15b
movq 0x18(%r12), %rax
testq %rax, %rax
je 0x82242
cmpl $0x2d6c6837, 0x4(%rax)  # imm = 0x2D6C6837
jne 0x82242
testb %r15b, %r15b
je 0x82420
movb $0x1, 0x1a(%rbp)
jmp 0x82242
cmpb $0x0, 0x48(%r12)
je 0x82429
movq 0x28(%rbp), %rdi
callq 0xe0e95
movl %eax, %ebp
movq 0x8(%rsp), %rax
cmpl $0x3, 0xc(%rax)
leaq 0x88ec3(%rip), %rax     # 0x10b29a
leaq 0x85e79(%rip), %rsi     # 0x108257
cmoveq %rax, %rsi
xorl %r15d, %r15d
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
cmpl 0x4c(%r12), %ebp
movq 0x8(%rsp), %rbp
je 0x8238b
movq 0x78(%r12), %rdi
callq 0xeb877
leaq 0x857ae(%rip), %rsi     # 0x107bbc
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
jmp 0x82388
movb $0x1, 0x19(%rbp)
jmp 0x82242
xorl %r15d, %r15d
jmp 0x8238b