// File: /workspace/github_c_makefile_star2_O1/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 %rdx, %r15
movq %rsi, (%rsp)
movq %rdi, %rbx
movq 0x18(%rdx), %rax
movb $0x1, %bpl
testq %rax, %rax
je 0x8779a
cmpb $0x0, 0x21(%r15)
je 0x877a2
leaq 0xa4a0e(%rip), %rsi     # 0x12c196
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
jmp 0x8786d
xorl %r13d, %r13d
jmp 0x8786d
cmpb $0x0, 0x20(%r15)
jne 0x877b4
cmpq $0x0, 0x8(%rax)
je 0x87845
movq 0x60(%r15), %rax
addq 0x58(%r15), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x877eb
movq 0x78(%r15), %rdi
callq 0xf7557
leaq 0x8d347(%rip), %rsi     # 0x114b1d
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
jmp 0x8786d
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r12
leaq 0x80(%r15), %rax
movl $0x18, %ecx
cmpb $0x0, (%rax)
je 0x8780f
movups (%rax), %xmm0
movups %xmm0, (%r12,%rcx)
addq $0x10, %rcx
addq $0x18, %rax
cmpq $0x68, %rcx
jne 0x87802
cmpb $0x0, 0x20(%r15)
je 0x8782f
movb $0x1, 0x9(%r12)
jmp 0x878d3
cmpb $0x0, 0x23(%r15)
je 0x878c6
orb $0x2, 0x14(%r12)
jmp 0x878d3
movq 0x78(%r15), %rdi
callq 0xf7557
movq 0x18(%r15), %rcx
addq $0x15, %rcx
leaq 0xa4957(%rip), %rsi     # 0x12c1b4
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
movb $0x1, %r14b
xorl %r12d, %r12d
testb %bpl, %bpl
jne 0x878a1
movq 0x18(%r15), %rax
testq %rax, %rax
je 0x878a1
cmpl $0x2d6c6837, 0x4(%rax)  # imm = 0x2D6C6837
jne 0x878a1
testb %r14b, %r14b
je 0x87899
movq (%rsp), %rax
movb $0x1, 0x1a(%rax)
jmp 0x878a1
movq (%rsp), %rax
movb $0x1, 0x19(%rax)
movq %r13, %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r12, %rsi
callq 0xea9b3
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x22(%r15)
je 0x878d3
orb $0x1, 0x14(%r12)
movq 0x78(%r15), %rdx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %ecx
callq 0xea9e4
movb $0x1, %r14b
movb %r14b, 0x8(%r12)
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r13
movq %rax, %rdi
callq 0xf0e3f
movq (%rsp), %rbp
movq 0x28(%rbp), %rdi
callq 0xebdc3
movq 0x28(%rbp), %rdx
leaq 0x6a130(%rip), %rsi     # 0xf1a51
movq %r13, %rdi
callq 0xf1a12
leaq 0x28(%rsp), %rbp
leaq 0x10(%rsp), %rdx
leaq 0x48(%rsp), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xfa6e0
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movq 0x58(%r15), %rax
movq %rax, 0x8(%rbp)
movq 0x60(%r15), %rax
movq %rax, 0x10(%rbp)
leaq 0x10(%rsp), %rcx
movq %r13, (%rcx)
movq 0x28(%r15), %rax
movq %rax, 0x10(%rcx)
movb %r14b, 0x8(%rcx)
cmpb $0x0, 0x20(%r15)
je 0x8797e
movb $0x1, %bpl
jmp 0x87873
movq 0x18(%r15), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x879a6
leaq 0x28(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0x48(%rsp), %r9
movq %rbx, %rdi
movq (%rsp), %rsi
movq %r15, %rdx
callq *%rax
movq 0x10(%rsp), %rdi
callq 0xf0ea4
cmpl $0x0, 0x48(%rsp)
je 0x879f2
movq 0x78(%r15), %rdi
callq 0xf7557
movq %rax, 0x8(%rsp)
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa6a8
leaq 0x8c794(%rip), %rsi     # 0x11416d
xorl %ebp, %ebp
movq %rbx, %rdi
movq 0x8(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9df7
jmp 0x87873
cmpb $0x0, 0x48(%r15)
je 0x87a5c
movq (%rsp), %rbp
movq 0x28(%rbp), %rdi
callq 0xebe2a
movl %eax, %edx
movl %eax, 0x8(%rsp)
cmpl $0x3, 0xc(%rbp)
leaq 0x9083b(%rip), %rax     # 0x118252
leaq 0x8d815(%rip), %rsi     # 0x115233
cmoveq %rax, %rsi
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x8(%rsp), %eax
cmpl 0x4c(%r15), %eax
je 0x87a5e
movq 0x78(%r15), %rdi
callq 0xf7557
leaq 0x8d124(%rip), %rsi     # 0x114b6c
xorl %ebp, %ebp
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
jmp 0x87873
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x87873