// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/misc3.c
// Function: de_run_edi_pack
static void de_run_edi_pack(deark *c, de_module_params *mparams)
{
	de_arch_lctx *d = NULL;
	struct de_arch_member_data *md = NULL;
	i64 pos = 0;

	d = de_arch_create_lctx(c);
	d->is_le = 1;
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);

	edi_detect_fmt(c, d);
	if(d->fmtver==0) goto done;
	else if(d->fmtver==10) {
		de_declare_fmt(c, "EDI LZSSLib");
	}
	else {
		de_declare_fmtf(c, "EDI Pack LZSS%d", d->fmtver);
	}
	pos = 8;

	md = de_arch_create_md(c, d);
	if(d->fmtver==1 || d->fmtver==2) {
		dbuf_read_to_ucstring(c->infile, pos, 12, md->filename, DE_CONVFLAG_STOP_AT_NUL,
			d->input_encoding);
		de_dbg(c, "filename: \"%s\"", ucstring_getpsz_d(md->filename));
		pos += 13;
	}

	if(d->fmtver==2) {
		de_arch_read_field_orig_len_p(md, &pos);
	}

	if(pos > c->infile->len) {
		d->need_errmsg = 1;
		goto done;
	}

	md->cmpr_pos = pos;
	md->cmpr_len = c->infile->len - md->cmpr_pos;
	md->dfn = edi_pack_decompressor_fn;
	de_arch_extract_member_file(md);

done:
	de_arch_destroy_md(c, md);
	if(d->need_errmsg) {
		de_err(c, "Bad or unsupported EDI Pack format");
	}
	de_arch_destroy_lctx(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
andq $0x0, (%rsp)
callq 0xf16ce
movq %rax, %r14
movl $0x1, 0x10(%rax)
pushq $0x9
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x18(%r14)
movq 0x18(%rbx), %rdi
leaq 0xaeb23(%rip), %rdx     # 0x118f65
pushq $0x7
popq %rcx
xorl %esi, %esi
callq 0xe4d48
testl %eax, %eax
je 0x6a473
movb $0x1, 0x14(%r14)
movl 0x58(%r14), %edx
testl %edx, %edx
je 0x6a4b9
cmpl $0xa, %edx
jne 0x6a4c1
leaq 0xaeabd(%rip), %rsi     # 0x118f26
movq %rbx, %rdi
callq 0xe07f7
jmp 0x6a4d2
leaq 0x8(%rsp), %rsi
movq $0x7, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xe3f2a
cmpb $0x32, %al
je 0x6a5c2
movzbl %al, %eax
cmpl $0x31, %eax
jne 0x6a450
movq 0x8(%rsp), %rdx
leaq 0xd(%rdx), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jle 0x6a5cf
movl $0xa, 0x58(%r14)
jmp 0x6a455
xorl %r15d, %r15d
jmp 0x6a587
leaq 0xaea6a(%rip), %rsi     # 0x118f32
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe0824
movq $0x8, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf1630
movq %rax, %r15
movl 0x58(%r14), %eax
decl %eax
cmpl $0x1, %eax
ja 0x6a54e
movq 0x18(%rbx), %rdi
movq 0x58(%r15), %rcx
movl 0x18(%r14), %r9d
pushq $0x8
popq %rsi
pushq $0xc
popq %rdx
pushq $0x1
popq %r8
callq 0xe4c9a
movq 0x58(%r15), %rdi
callq 0xeb877
leaq 0xc4540(%rip), %rsi     # 0x12ea5e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq $0x15, (%rsp)
cmpl $0x2, 0x58(%r14)
jne 0x6a552
movq %rsp, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0xf1766
movq (%r12), %rax
jmp 0x6a555
pushq $0x8
jmp 0x6a554
pushq $0x15
popq %rax
movq 0x18(%rbx), %rcx
movq 0x18(%rcx), %rcx
subq %rax, %rcx
jge 0x6a569
movb $0x1, 0x14(%r14)
jmp 0x6a587
movq %rax, 0x40(%r15)
movq %rcx, 0x30(%r15)
leaq 0x2fcf(%rip), %rax      # 0x6d547
movq %rax, 0xa8(%r15)
movq %r15, %rdi
callq 0xf1a85
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf167c
cmpb $0x0, 0x14(%r14)
je 0x6a5aa
leaq 0xae9a2(%rip), %rsi     # 0x118f42
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf16e7
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, 0x58(%r14)
jmp 0x6a455
pushq $0x1
popq %rbp
leaq 0x13(%rsp), %rsi
pushq $0xd
popq %rcx
callq 0xe3cb7
xorl %ecx, %ecx
movabsq $0xe0000003f002701, %rsi # imm = 0xE0000003F002701
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
cmpq $0xd, %rcx
je 0x6a659
movzbl 0x13(%rsp,%rcx), %r8d
cmpl $0x2e, %r8d
je 0x6a644
testl %r8d, %r8d
je 0x6a659
cmpb $0x21, %r8b
jb 0x6a4af
leal -0x22(%r8), %r9d
cmpl $0x3b, %r9d
ja 0x6a626
btq %r9, %rsi
jb 0x6a4af
cmpl $0x7c, %r8d
je 0x6a4af
cmpl $0x7f, %r8d
je 0x6a4af
testl %edi, %edi
je 0x6a653
incl %eax
movl %ebp, %edi
jmp 0x6a64e
testl %edi, %edi
movl %ebp, %edi
jne 0x6a4af
incq %rcx
jmp 0x6a5f1
incl %edx
xorl %edi, %edi
jmp 0x6a64e
cmpq $0xd, %rcx
setae %cl
addl $-0x9, %edx
cmpl $-0x8, %edx
setb %dl
cmpl $0x4, %eax
setge %al
orb %cl, %al
orb %dl, %al
jne 0x6a4af
movl $0x1, 0x58(%r14)
jmp 0x6a455