// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/exectext.c
// Function: de_run_asc2com
static void de_run_asc2com(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	struct asc2com_ctx *a2cc = NULL;
	struct asc2com_detection_data idd;

	a2cc = de_malloc(c, sizeof(struct asc2com_ctx));

	de_zeromem(&idd, sizeof(struct asc2com_detection_data));
	asc2com_identify(c, &idd, 0);
	if(!idd.found) {
		de_err(c, "Not a known Asc2Com format");
		goto done;
	}
	de_dbg(c, "format code: 0x%08x", idd.fmtcode);
	de_dbg(c, "compressed: %u", (UI)idd.is_compressed);
	a2cc->version = (idd.fmtcode >> 20) & 0xfff;
	a2cc->lister = idd.fmtcode & 0xf;

	d = create_lctx(c);
	d->userdata = (void*)a2cc;

	d->supports_fmtconv = 1;
	exectext_set_common_enc_opts(c, d, DE_ENCODING_CP437);

	asc2com_find_special_chars(c, d, &idd);

	d->tpos = idd.tpos;
	de_dbg(c, "tpos: %"I64_FMT, d->tpos);
	d->tlen = c->infile->len - d->tpos;

	// TODO: Can we read and use the original filename?
	if(idd.is_compressed) {
		asc2com_extract_compressed(c, d);
	}
	else {
		asc2com_extract_uncompressed(c, d);
	}

done:
	destroy_lctx(c, d);
	de_free(c, a2cc);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
pushq $0x8
popq %r12
movq %r12, %rsi
callq 0xdecaf
movq %rax, %r13
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x601eb
cmpb $0x0, (%r14)
je 0x5e727
movl 0x14(%rsp), %ebp
leaq 0xb82c6(%rip), %rsi     # 0x116985
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
movb 0x11(%rsp), %r14b
movzbl %r14b, %edx
leaq 0xb82be(%rip), %rsi     # 0x116999
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl %ebp, %eax
shrl $0x14, %eax
movl %eax, (%r13)
andl $0xf, %ebp
movl %ebp, 0x4(%r13)
movq %rbx, %rdi
callq 0x5fc9f
movq %rax, %r15
movq %r13, (%rax)
movb $0x1, 0x17(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5fcb7
movq (%r15), %rcx
cmpl $0x4, 0x4(%rcx)
movq %r13, 0x8(%rsp)
jne 0x5e740
movb $0x1, 0x41(%r15)
jmp 0x5e749
leaq 0xb823c(%rip), %rsi     # 0x11696a
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x5e9eb
movl (%rcx), %eax
cmpl $0x165, %eax            # imm = 0x165
jae 0x5e751
xorl %r13d, %r13d
jmp 0x5e853
cmpl $0x175, %eax            # imm = 0x175
jb 0x5e75f
movb $0x64, 0x41(%r15)
movl (%rcx), %eax
leal -0x165(%rax), %ecx
cmpl $0x2, %ecx
movb %r14b, 0x7(%rsp)
jae 0x5e776
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x5e79c
leal -0x175(%rax), %ecx
cmpl $0x2, %ecx
jae 0x5e788
movb $0x1, %r14b
xorl %ebp, %ebp
jmp 0x5e79c
addl $0xfffffe00, %eax       # imm = 0xFFFFFE00
xorl %r14d, %r14d
cmpl $0x5, %eax
ja 0x5e84b
movb $0x1, %bpl
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r13
movb $0x2, %al
movb %al, 0x38(%r15)
movb %al, 0x137(%r15)
leaq 0xb8202(%rip), %rsi     # 0x1169bd
pushq $0x5
popq %rdx
movq %r13, %rdi
callq 0xeae42
testb %r14b, %r14b
je 0x5e807
leaq 0xb81f2(%rip), %rbp     # 0x1169c4
pushq $0x5
popq %r14
cmpq $0xc, %r12
ja 0x5e84e
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3eb4
movzbl %al, %ecx
movb $0x2, 0x38(%r15,%rcx)
movq %r13, %rdi
movl %r14d, %esi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xeae8b
addq $0x2, %r12
jmp 0x5e7d6
testb %bpl, %bpl
je 0x5e84e
pushq $0x50
popq %r12
leaq 0xb81ad(%rip), %rbp     # 0x1169c4
pushq $0x5
popq %r14
cmpq $0x54, %r12
je 0x5e84e
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3eb4
movzbl %al, %ecx
movb $0x2, 0x38(%r15,%rcx)
movq %r13, %rdi
movl %r14d, %esi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xeae8b
incq %r12
jmp 0x5e81b
xorl %r13d, %r13d
movb 0x7(%rsp), %r14b
movq %r13, %rdi
callq 0xeaf8a
testl %eax, %eax
je 0x5e87b
movq %r13, %rdi
callq 0xeb7e4
leaq 0xb815c(%rip), %rsi     # 0x1169ca
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %r13, %rdi
callq 0xeaf3c
movq 0x18(%rsp), %rdx
movq %rdx, 0x28(%r15)
leaq 0xb81ed(%rip), %rsi     # 0x116a80
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
subq 0x28(%r15), %rax
movq %rax, 0x30(%r15)
testb %r14b, %r14b
je 0x5e9a7
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe59cd
movq %rax, %r12
leaq 0xb8(%rsp), %r14
leaq 0xa0(%rsp), %rbp
leaq 0x40(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0xee7ee
movq 0x18(%rbx), %rax
movq %rax, (%r14)
movups 0x28(%r15), %xmm0
movups %xmm0, 0x8(%r14)
movq %r12, (%rbp)
movb $0x0, 0x8(%rbp)
xorps %xmm0, %xmm0
leaq 0x2c(%rsp), %r8
movups %xmm0, 0x4(%r8)
movl $0xc, (%r8)
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
leaq 0x40(%rsp), %rcx
callq 0xf644c
movq %r12, %rdi
callq 0xe58e8
cmpq $0x0, 0x18(%r12)
jle 0x5e972
leaq 0xbe71e(%rip), %rsi     # 0x11d060
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r13
movq %rax, %rdi
callq 0xe589c
movq %r12, 0x20(%r15)
movq 0x18(%r12), %rcx
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r13, %r8
callq 0x6034f
cmpl $0x0, 0x40(%rsp)
je 0x5e99a
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0xee7bc
leaq 0xa9372(%rip), %rsi     # 0x107cff
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
movq %r12, %rdi
callq 0xe5591
movq %r13, %rdi
jmp 0x5e9e1
leaq 0xbe6b2(%rip), %rsi     # 0x11d060
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r14
movq %rax, %rdi
callq 0xe589c
movq 0x28(%r15), %rdx
movq 0x30(%r15), %rcx
addq %rdx, %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %r8
callq 0x6034f
movq %r14, %rdi
callq 0xe5591
movq 0x8(%rsp), %r13
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5fe42
movq %rbx, %rdi
movq %r13, %rsi
callq 0xded32
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq