// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
xorl %r15d, %r15d
movq %r15, (%rsp)
callq 0xfdb0a
movq %rax, %r14
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb7d1
movl %eax, 0x18(%r14)
movq %r15, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq 0xb7bfa(%rip), %rdx     # 0x125f35
movl $0x7, %ecx
xorl %esi, %esi
callq 0xf025e
testl %eax, %eax
je 0x6e379
movb $0x1, 0x14(%r14)
movl 0x58(%r14), %edx
testl %edx, %edx
je 0x6e45b
cmpl $0xa, %edx
jne 0x6e463
leaq 0xb7b8a(%rip), %rsi     # 0x125ef6
movq %rbx, %rdi
callq 0xeb6d6
jmp 0x6e474
leaq 0x8(%rsp), %rsi
addq $0x7, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xef14d
cmpb $0x32, %al
je 0x6e557
movzbl %al, %eax
cmpl $0x31, %eax
jne 0x6e34b
movq 0x8(%rsp), %rdx
leaq 0xd(%rdx), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x6e584
leaq 0x13(%rsp), %rsi
movl $0xd, %ecx
callq 0xeeee8
xorl %eax, %eax
movabsq $0xe0000003f002701, %rdx # imm = 0xE0000003F002701
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %esi, %esi
xorl %edi, %edi
movzbl 0x13(%rsp,%rdi), %r10d
testl %r10d, %r10d
je 0x6e3f9
cmpl $0x2e, %r10d
jne 0x6e406
xorl %r9d, %r9d
testl %r8d, %r8d
setne %r9b
movl $0x1, %r8d
jmp 0x6e422
movl $0x2, %r9d
movl $0x1, %esi
jmp 0x6e422
movl $0x1, %r9d
cmpb $0x21, %r10b
jb 0x6e422
leal -0x22(%r10), %r11d
cmpl $0x3b, %r11d
ja 0x6e439
btq %r11, %rdx
jae 0x6e439
testl %r9d, %r9d
jne 0x6e564
incq %rdi
cmpq $0xd, %rdi
jne 0x6e3d6
jmp 0x6e56a
cmpl $0x7c, %r10d
je 0x6e422
cmpl $0x7f, %r10d
je 0x6e422
testl %r8d, %r8d
je 0x6e451
incl %eax
xorl %r9d, %r9d
jmp 0x6e3f1
incl %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
jmp 0x6e422
xorl %r15d, %r15d
jmp 0x6e51f
leaq 0xb7a98(%rip), %rsi     # 0x125f02
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb703
movq $0x8, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfda6c
movq %rax, %r15
movl 0x58(%r14), %eax
decl %eax
cmpl $0x1, %eax
ja 0x6e4d7
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movq 0x58(%r15), %rcx
movl 0x18(%r14), %r9d
movl $0xc, %edx
movl $0x1, %r8d
callq 0xf01b0
movq 0x58(%r15), %rdi
callq 0xf7557
leaq 0xcd50f(%rip), %rsi     # 0x13b9d4
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0xd, (%rsp)
cmpl $0x2, 0x58(%r14)
jne 0x6e4e9
movq %rsp, %rsi
movq %r15, %rdi
callq 0xfdb9b
movq (%rsp), %rax
movq 0x18(%rbx), %rcx
movq 0x18(%rcx), %rcx
subq %rax, %rcx
jge 0x6e501
movb $0x1, 0x14(%r14)
jmp 0x6e51f
movq %rax, 0x40(%r15)
movq %rcx, 0x30(%r15)
leaq 0x31c5(%rip), %rax      # 0x716d5
movq %rax, 0xa8(%r15)
movq %r15, %rdi
callq 0xfdec1
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfdab8
cmpb $0x0, 0x14(%r14)
je 0x6e542
leaq 0xb79da(%rip), %rsi     # 0x125f12
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfdb25
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
movl $0x2, 0x58(%r14)
jmp 0x6e350
cmpl $0x2, %r9d
jne 0x6e584
testl %esi, %esi
sete %dl
addl $-0x9, %ecx
cmpl $-0x8, %ecx
setb %cl
orb %dl, %cl
cmpl $0x4, %eax
setge %al
orb %cl, %al
je 0x6e591
movl $0xa, 0x58(%r14)
jmp 0x6e350
movl $0x1, 0x58(%r14)
jmp 0x6e350