// File: /workspace/github_c_makefile_star2_O1/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
movl $0x138, %esi            # imm = 0x138
callq 0xe969b
movq %rax, %r14
movq 0x18(%rbx), %rax
movq %rax, 0x20(%r14)
movb $0x1, %bpl
movb %bpl, 0x17(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x634f2
movb %bpl, 0x45(%r14)
movb %bpl, 0x53(%r14)
movl $0x1010101, 0x3f(%r14)  # imm = 0x1010101
movq $0xbc, 0x28(%r14)
leaq 0xc1222(%rip), %rsi     # 0x123a60
movl $0xbc, %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r12
leaq -0x2(%r12), %r13
movq %r13, %rsi
callq 0xef0d5
movl %eax, %ebp
movq 0x18(%rbx), %rdi
leaq -0x1(%r12), %r15
movq %r15, %rsi
callq 0xef0d5
testb %al, %al
cmoveq %r15, %r12
testb %bpl, %bpl
cmoveq %r13, %r12
subq 0x28(%r14), %r12
movq %r12, 0x30(%r14)
leaq 0xc0fbb(%rip), %rsi     # 0x12384c
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6373a
cmpb $0x0, 0x12(%r14)
je 0x628b8
xorl %r12d, %r12d
jmp 0x62a75
leaq 0xc7781(%rip), %rsi     # 0x12a040
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r12
movq %rax, %rdi
callq 0xf0e3f
movl 0x18(%r14), %eax
cmpl $0x1, %eax
jne 0x628f8
movq 0x18(%rbx), %rdi
movq 0x28(%r14), %rsi
movq 0x30(%r14), %rdx
movq %r12, %rcx
callq 0xefabc
jmp 0x62a75
movq 0x30(%r14), %r15
addq 0x28(%r14), %r15
cmpl $0x3, %eax
jne 0x6293b
movzbl 0x8(%r14), %edx
orl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
movl $0x3, %esi
movq %r12, %rcx
callq 0x63774
movq %rax, %r13
cmpb $0x0, 0xcc(%rbx)
je 0x6293e
movq %r12, %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0xec81c
jmp 0x6293e
xorl %r13d, %r13d
testq %r13, %r13
jne 0x62957
movl 0x18(%r14), %esi
movq %rbx, %rdi
xorl %edx, %edx
movq %r12, %rcx
callq 0x63774
movq %rax, %r13
movq %r13, (%rsp)
movq %r12, 0x10(%rsp)
movq 0x28(%r14), %rax
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movb $0x7f, %r12b
xorl %r13d, %r13d
cmpq %r15, 0x8(%rsp)
jge 0x62a4c
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef14d
movl %eax, %ebp
testb %al, %al
je 0x629f4
andb %bpl, %r12b
movl %r12d, %edx
xorb $0x25, %dl
movb $0x1, %al
movb $-0x1, %cl
orb %r13b, %dl
je 0x62a3d
testb %r13b, %r13b
jne 0x629b8
movb $0x3f, %cl
cmpb $0x5e, %r12b
je 0x62a3d
movl 0x18(%r14), %eax
testb %r13b, %r13b
jne 0x629fc
cmpb $0x7e, %r12b
jne 0x629fc
cmpl $0x3, %eax
movq (%rsp), %r12
movq %r12, %rdi
movl $0xd, %esi
jne 0x62a1a
callq 0x63956
movq %r12, %rdi
movl $0xa, %esi
callq 0x63956
movq %r12, %rdi
movl $0x240c, %esi           # imm = 0x240C
jmp 0x62a13
movl %r12d, %ecx
movl %r13d, %eax
jmp 0x62a3d
movzbl %r12b, %esi
cmpl $0x3, %eax
movq (%rsp), %rdi
jne 0x62a34
movl %esi, %eax
cmpb $0x1, 0x38(%r14,%rax)
jne 0x62a34
callq 0x63956
jmp 0x62a39
callq 0x639a4
movq %r12, %rdi
movl $0xa, %esi
callq 0x639a4
movq %r12, %rdi
movl $0xc, %esi
callq 0x639a4
movb $0x7f, %cl
xorl %eax, %eax
movl %ecx, %r12d
movl %eax, %r13d
testb %bpl, %bpl
jne 0x62972
movq (%rsp), %r15
testq %r15, %r15
je 0x62a70
movq %r15, %rdi
callq 0x63901
movq (%r15), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
movq 0x10(%rsp), %r12
testq %r14, %r14
je 0x62a9d
cmpb $0x0, 0x13(%r14)
je 0x62a92
leaq 0xc1048(%rip), %rsi     # 0x123ad0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movq %r12, %rdi
callq 0xf0b13
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq