// File: /workspace/github_c_makefile_star2_O3/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 0x870c7
movq %rdx, %r12
cmpb $0x0, 0x21(%rdx)
je 0x870cf
leaq 0xa53c9(%rip), %rsi     # 0x12c47e
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
jmp 0x87197
xorl %r14d, %r14d
jmp 0x87197
movq %rsi, %r15
cmpb $0x0, 0x20(%r12)
jne 0x870e5
cmpq $0x0, 0x8(%rax)
je 0x8716d
movq 0x60(%r12), %rax
addq 0x58(%r12), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x8711c
movq 0x78(%r12), %rdi
callq 0xf70f6
leaq 0x8daee(%rip), %rsi     # 0x114bf8
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
jmp 0x87197
movq %rbx, %rdi
callq 0xea504
movq %rax, %r14
leaq 0x80(%r12), %rax
movl $0x18, %ecx
cmpb $0x0, (%rax)
je 0x87141
movups (%rax), %xmm0
movups %xmm0, (%r14,%rcx)
addq $0x10, %rcx
addq $0x18, %rax
cmpq $0x68, %rcx
jne 0x87134
cmpb $0x0, 0x20(%r12)
je 0x8715e
movb $0x1, 0x9(%r14)
jmp 0x871cc
cmpb $0x0, 0x23(%r12)
je 0x871bf
orb $0x2, 0x14(%r14)
jmp 0x871cc
movq 0x78(%r12), %rdi
callq 0xf70f6
movq 0x18(%r12), %rcx
addq $0x15, %rcx
leaq 0xa5315(%rip), %rsi     # 0x12c49c
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
xorl %r13d, %r13d
movq %r13, %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r14, %rsi
callq 0xea50e
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x22(%r12)
je 0x871cc
orb $0x1, 0x14(%r14)
movq 0x78(%r12), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %ecx
callq 0xea53f
movb $0x1, %al
movb %al, 0x8(%r14)
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r13
movq %rax, %rdi
callq 0xf0855
movq 0x28(%r15), %rdi
callq 0xeb7fe
movq 0x28(%r15), %rdx
leaq 0x6a23c(%rip), %rsi     # 0xf1451
movq %r13, %rdi
callq 0xf1412
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 0xfa1dc
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 0x8719a
movq 0x18(%r12), %rax
movq 0x8(%rax), %rax
movq %r13, %rdi
testq %rax, %rax
movq 0x8(%rsp), %rbp
je 0x872a5
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 0xf08ba
cmpl $0x0, 0x48(%rsp)
je 0x8730e
movq 0x78(%r12), %rdi
callq 0xf70f6
movq %rax, %r15
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa1a4
leaq 0x8cf4b(%rip), %rsi     # 0x11421d
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9295
movb $0x1, %r15b
movq 0x18(%r12), %rax
testq %rax, %rax
je 0x8719a
cmpl $0x2d6c6837, 0x4(%rax)  # imm = 0x2D6C6837
jne 0x8719a
testb %r15b, %r15b
je 0x8737a
movb $0x1, 0x1a(%rbp)
jmp 0x8719a
cmpb $0x0, 0x48(%r12)
je 0x87383
movq 0x28(%rbp), %rdi
callq 0xeb865
movl %eax, %ebp
movq 0x8(%rsp), %rax
cmpl $0x3, 0xc(%rax)
leaq 0x91059(%rip), %rax     # 0x11838a
leaq 0x8dfab(%rip), %rsi     # 0x1152e3
cmoveq %rax, %rsi
xorl %r15d, %r15d
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
cmpl 0x4c(%r12), %ebp
movq 0x8(%rsp), %rbp
je 0x872e5
movq 0x78(%r12), %rdi
callq 0xf70f6
leaq 0x8d8df(%rip), %rsi     # 0x114c47
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
jmp 0x872e2
movb $0x1, 0x19(%rbp)
jmp 0x8719a
xorl %r15d, %r15d
jmp 0x872e5