// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
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 0x63336
movb %bpl, 0x45(%r14)
movb %bpl, 0x53(%r14)
movl $0x1010101, 0x3f(%r14)  # imm = 0x1010101
movq $0xbc, 0x28(%r14)
leaq 0xc158e(%rip), %rsi     # 0x123c40
movl $0xbc, %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r12
leaq -0x2(%r12), %r13
movq %r13, %rsi
callq 0xeead3
movl %eax, %ebp
movq 0x18(%rbx), %rdi
leaq -0x1(%r12), %r15
movq %r15, %rsi
callq 0xeead3
testb %al, %al
cmoveq %r15, %r12
testb %bpl, %bpl
cmoveq %r13, %r12
subq 0x28(%r14), %r12
movq %r12, 0x30(%r14)
leaq 0xc1327(%rip), %rsi     # 0x123a2c
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movq %r14, %rsi
callq 0x63572
cmpb $0x0, 0x12(%r14)
je 0x6272c
xorl %r13d, %r13d
jmp 0x628cf
leaq 0xc7b7d(%rip), %rsi     # 0x12a2b0
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r13
movq %rax, %rdi
callq 0xf0855
movl 0x18(%r14), %esi
cmpl $0x1, %esi
jne 0x6276c
movq 0x18(%rbx), %rdi
movq 0x28(%r14), %rsi
movq 0x30(%r14), %rdx
movq %r13, %rcx
callq 0xef481
jmp 0x628cf
movq 0x30(%r14), %r15
addq 0x28(%r14), %r15
cmpl $0x3, %esi
jne 0x627b6
movzbl 0x8(%r14), %edx
orl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
movl $0x3, %esi
movq %r13, %rcx
callq 0x635ac
movq %rax, %r12
cmpb $0x0, 0xcc(%rbx)
je 0x627ad
movq %r13, %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0xec1c4
testq %r12, %r12
jne 0x627c6
movl 0x18(%r14), %esi
movq %rbx, %rdi
xorl %edx, %edx
movq %r13, %rcx
callq 0x635ac
movq %rax, %r12
movq %r13, 0x10(%rsp)
movq 0x28(%r14), %rax
movq %rax, 0x8(%rsp)
cmpq %r15, %rax
jge 0x628a4
movb $0x7f, %bpl
xorl %r13d, %r13d
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeeb4b
testb %al, %al
je 0x628a4
andb %bpl, %al
movl %eax, %edx
xorb $0x25, %dl
movb $0x1, %cl
movb $-0x1, %bpl
orb %r13b, %dl
je 0x62896
testb %r13b, %r13b
jne 0x6281b
movb $0x3f, %bpl
cmpb $0x5e, %al
je 0x62896
movl 0x18(%r14), %ecx
testb %r13b, %r13b
jne 0x62851
cmpb $0x7e, %al
jne 0x62851
movq %r12, %rdi
movl $0xd, %esi
cmpl $0x3, %ecx
jne 0x62872
callq 0x6378e
movq %r12, %rdi
movl $0xa, %esi
callq 0x6378e
movq %r12, %rdi
movl $0x240c, %esi           # imm = 0x240C
jmp 0x62866
movzbl %al, %esi
cmpl $0x3, %ecx
jne 0x6286d
movl %esi, %eax
cmpb $0x1, 0x38(%r14,%rax)
jne 0x6286d
movq %r12, %rdi
callq 0x6378e
jmp 0x62891
movq %r12, %rdi
jmp 0x6288c
callq 0x637dc
movq %r12, %rdi
movl $0xa, %esi
callq 0x637dc
movq %r12, %rdi
movl $0xc, %esi
callq 0x637dc
movb $0x7f, %bpl
xorl %ecx, %ecx
movl %ecx, %r13d
cmpq %r15, 0x8(%rsp)
jl 0x627e3
testq %r12, %r12
je 0x628c5
movq %r12, %rdi
callq 0x63739
movq (%r12), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe8be2
testq %r14, %r14
movq 0x10(%rsp), %r13
je 0x628f2
cmpb $0x0, 0x13(%r14)
je 0x628e7
leaq 0xc13d3(%rip), %rsi     # 0x123cb0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movq %r13, %rdi
callq 0xf052b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq