// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/exectext.c
// Function: de_run_gtxt
static void de_run_gtxt(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 endpos;
	UI b1, b2;
	dbuf *outf = NULL;

	d = create_lctx(c);
	d->supports_fmtconv = 1;
	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;

	d->tpos = 188;
	de_dbg(c, "tpos: %"I64_FMT, d->tpos);

	endpos = c->infile->len;
	b1 = de_getbyte(endpos-2);
	b2 = de_getbyte(endpos-1);

	if(b1==0) {
		endpos -= 2;
	}
	else if(b2==0) {
		endpos -= 1;
	}

	d->tlen = endpos - d->tpos;
	de_dbg(c, "tlen: %"I64_FMT, d->tlen);
	exectext_check_tpos(c, d);
	if(d->errflag) goto done;

	outf = dbuf_create_output_file(c, "txt", NULL, 0);
	dbuf_enable_wbuffer(outf);

	if(d->proctype==ET_PROCTYPE_RAW) {
		dbuf_copy(c->infile, d->tpos, d->tlen, outf);
	}
	else {
		gtxt_convert_to_text(c, d, outf);
	}

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
callq 0x5fc9f
movq %rax, %r14
movb $0x1, %bpl
movb %bpl, 0x17(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5fcb7
movb %bpl, 0x45(%r14)
movb %bpl, 0x53(%r14)
movl $0x1010101, 0x3f(%r14)  # imm = 0x1010101
movq $0xbc, 0x28(%r14)
leaq 0xb792c(%rip), %rsi     # 0x116a80
movl $0xbc, %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r12
leaq -0x2(%r12), %r13
movq %r13, %rsi
callq 0xe3eb4
movl %eax, %ebp
movq 0x18(%rbx), %rdi
leaq -0x1(%r12), %r15
movq %r15, %rsi
callq 0xe3eb4
testb %al, %al
cmoveq %r15, %r12
testb %bpl, %bpl
cmoveq %r13, %r12
subq 0x28(%r14), %r12
movq %r12, 0x30(%r14)
leaq 0xb76c5(%rip), %rsi     # 0x11686c
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5fefd
cmpb $0x0, 0x12(%r14)
je 0x5f1ce
xorl %r13d, %r13d
jmp 0x5f35c
leaq 0xbde8b(%rip), %rsi     # 0x11d060
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r13
movq %rax, %rdi
callq 0xe589c
movl 0x18(%r14), %esi
cmpl $0x1, %esi
jne 0x5f20e
movq 0x18(%rbx), %rdi
movq 0x28(%r14), %rsi
movq 0x30(%r14), %rdx
movq %r13, %rcx
callq 0xe45f4
jmp 0x5f35c
movq 0x30(%r14), %r15
addq 0x28(%r14), %r15
cmpl $0x3, %esi
jne 0x5f256
movzbl 0x8(%r14), %edx
orl $0x400, %edx            # imm = 0x400
pushq $0x3
popq %rsi
movq %rbx, %rdi
movq %r13, %rcx
callq 0x5ff37
movq %rax, %r12
cmpb $0x0, 0xcc(%rbx)
je 0x5f24d
movq %r13, %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0xe1790
testq %r12, %r12
jne 0x5f266
movl 0x18(%r14), %esi
movq %rbx, %rdi
xorl %edx, %edx
movq %r13, %rcx
callq 0x5ff37
movq %rax, %r12
movq %r13, 0x10(%rsp)
movq 0x28(%r14), %rax
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movb $0x7f, %bpl
xorl %r13d, %r13d
cmpq %r15, %rax
jge 0x5f33a
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xe3f2a
testb %al, %al
je 0x5f33a
andb %bpl, %al
movl %eax, %edx
xorb $0x25, %dl
movb $0x1, %cl
movb $-0x1, %bpl
orb %r13b, %dl
je 0x5f32d
testb %r13b, %r13b
jne 0x5f2ba
movb $0x3f, %bpl
cmpb $0x5e, %al
je 0x5f32d
movl 0x18(%r14), %ecx
testb %r13b, %r13b
jne 0x5f2ec
cmpb $0x7e, %al
jne 0x5f2ec
movq %r12, %rdi
pushq $0xd
popq %rsi
cmpl $0x3, %ecx
jne 0x5f30d
callq 0x600ff
movq %r12, %rdi
pushq $0xa
popq %rsi
callq 0x600ff
movq %r12, %rdi
movl $0x240c, %esi           # imm = 0x240C
jmp 0x5f301
movzbl %al, %esi
cmpl $0x3, %ecx
jne 0x5f308
movl %esi, %eax
cmpb $0x1, 0x38(%r14,%rax)
jne 0x5f308
movq %r12, %rdi
callq 0x600ff
jmp 0x5f328
movq %r12, %rdi
jmp 0x5f323
callq 0x60128
movq %r12, %rdi
pushq $0xa
popq %rsi
callq 0x60128
movq %r12, %rdi
pushq $0xc
popq %rsi
callq 0x60128
movb $0x7f, %bpl
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
movl %ecx, %r13d
jmp 0x5f27d
testq %r12, %r12
je 0x5f352
movq %r12, %rdi
callq 0x600bc
movq %rbx, %rdi
movq %r12, %rsi
callq 0x600d5
testq %r14, %r14
movq 0x10(%rsp), %r13
je 0x5f37f
cmpb $0x0, 0x13(%r14)
je 0x5f374
leaq 0xb7786(%rip), %rsi     # 0x116af0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
movq %r13, %rdi
callq 0xe5591
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq