// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/exectext.c
// Function: de_run_doc2com_dkn
static void de_run_doc2com_dkn(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos_of_tpos = 0;
	i64 pos_of_tlen = 0;
	UI n;
	UI b1, b2;

	d = create_lctx(c);
	exectext_set_common_enc_opts(c, d, DE_ENCODING_CP437);
	d->chartypes[7] = ETCT_CONTROL;
	d->chartypes[8] = ETCT_CONTROL;
	d->chartypes[9] = ETCT_CONTROL;
	d->chartypes[10] = ETCT_CONTROL;
	d->chartypes[13] = ETCT_CONTROL;
	d->chartypes[27] = ETCT_CONTROL;

	n = (UI)de_getu16le(1);
	if(n==0x0093) {
		d->fmtcode = 1;
		pos_of_tpos = 171;
		pos_of_tlen = 178;
	}
	else if(n==0x0107) {
		d->fmtcode = 2;
		pos_of_tpos = 293;
		pos_of_tlen = 300;
	}

	if(d->fmtcode==0) goto done;
	if(de_getbyte(pos_of_tpos-1)!=0xbf) goto done;
	de_dbg(c, "fmt code: %u", d->fmtcode);
	d->tpos = de_getu16le(pos_of_tpos);
	d->tpos -= 0x100;
	if(d->fmtcode==2) d->tpos--;
	de_dbg(c, "tpos: %"I64_FMT, d->tpos);

	b1 = de_getbyte(pos_of_tlen);
	b2 = de_getbyte(pos_of_tlen+2);
	d->tlen = ((UI)b1<<8) | b2;
	de_dbg(c, "tlen: %"I64_FMT, d->tlen);

	exectext_extract_default(c, d);

done:
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Not a DOC2COM file, or unsupported version");
		}
		destroy_lctx(c, d);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8dcb0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0xd, %edx
callq 0x8dcf0
movq -0x18(%rbp), %rax
movb $0x1, 0x3f(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x40(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x41(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x42(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x45(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x53(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1, %esi
callq 0x165280
movl %eax, -0x2c(%rbp)
cmpl $0x93, -0x2c(%rbp)
jne 0x8ca92
movq -0x18(%rbp), %rax
movl $0x1, 0xc(%rax)
movq $0xab, -0x20(%rbp)
movq $0xb2, -0x28(%rbp)
jmp 0x8cab8
cmpl $0x107, -0x2c(%rbp)     # imm = 0x107
jne 0x8cab6
movq -0x18(%rbp), %rax
movl $0x2, 0xc(%rax)
movq $0x125, -0x20(%rbp)     # imm = 0x125
movq $0x12c, -0x28(%rbp)     # imm = 0x12C
jmp 0x8cab8
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x8cac7
jmp 0x8cbd5
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
subq $0x1, %rsi
callq 0x165060
movzbl %al, %eax
cmpl $0xbf, %eax
je 0x8caeb
jmp 0x8cbd5
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %edx
leaq 0x122a28(%rip), %rsi    # 0x1af525
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
subq $0x100, %rcx            # imm = 0x100
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x8cb4d
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x122a11(%rip), %rsi    # 0x1af571
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165060
movzbl %al, %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x2, %rsi
callq 0x165060
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
shll $0x8, %eax
orl -0x34(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdx
leaq 0x12279c(%rip), %rsi    # 0x1af35d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x8df30
cmpq $0x0, -0x18(%rbp)
je 0x8cc05
movq -0x18(%rbp), %rax
cmpb $0x0, 0x13(%rax)
je 0x8cbf8
movq -0x8(%rbp), %rdi
leaq 0x122941(%rip), %rsi    # 0x1af532
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x8e0b0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)