// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/exectext.c
// Function: de_run_textlife
static void de_run_textlife(deark *c, de_module_params *mparams)
{
	struct textlife_ctx *tctx = NULL;
	lctx *d = NULL;

	d = create_lctx(c);
	tctx = de_malloc(c, sizeof(struct textlife_ctx));
	tctx->msgpfx = "[TextLife] ";
	tctx->ei = de_malloc(c, sizeof(struct fmtutil_exe_info));

	exectext_set_common_enc_opts(c, d, DE_ENCODING_CP437);

	// TextLife filters/optimizes the data before storing it. Known filters:
	// * Convert CR+LF to CR.
	// * Replace runs of 8 spaces with TAB.
	// I don't think extracting the raw bytes from the file is a useful thing
	// to do. So we always at least undo the filtering.
	// Files can contain C0 control characters used for special purposes (e.g.
	// italics), but I don't think they will cause serious problems with
	// encoding translation. So we just leave them as-is.
	if(d->proctype==ET_PROCTYPE_RAW) {
		d->proctype = ET_PROCTYPE_FMTCONV_ONLY;
	}

	d->chartypes[3] = ETCT_CONTROL;
	d->chartypes[4] = ETCT_CONTROL;
	d->chartypes[5] = ETCT_CONTROL;
	d->chartypes[6] = ETCT_CONTROL;
	d->chartypes[9] = ETCT_8SPACES;
	d->chartypes[0x0d] = ETCT_CRLF;
	d->chartypes[0x0f] = ETCT_CONTROL;
	d->chartypes[0x10] = ETCT_CONTROL;
	d->chartypes[0x11] = ETCT_CONTROL;

	fmtutil_collect_exe_info(c, c->infile, tctx->ei);

	tctx->edd.restrict_to_fmt = DE_SPECIALEXEFMT_TEXTLIFE;
	fmtutil_detect_specialexe(c, tctx->ei, &tctx->edd);
	if(tctx->edd.detected_fmt!=DE_SPECIALEXEFMT_TEXTLIFE) {
		d->need_errmsg = 1;
		goto done;
	}

	de_dbg(c, "text marker pos: %"I64_FMT, tctx->edd.special_pos_1);
	d->tpos = tctx->edd.special_pos_1+6;
	de_dbg(c, "tpos: %"I64_FMT, d->tpos);
	d->tlen = de_getu16le(tctx->edd.special_pos_1 - 2) - 1;
	de_dbg(c, "tlen: %"I64_FMT, d->tlen);

	exectext_extract_default(c, d);

done:
	if(d) {
		if(d->need_errmsg && tctx) {
			de_err(c, "%sBad or unsupported TextLife file", tctx->msgpfx);
		}
		de_free(c, d);
		d = NULL;
	}
	if(tctx) {
		de_free(c, tctx->ei);
		de_free(c, tctx);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0x5fc9f
movq %rax, %r15
movl $0x88, %esi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r14
leaq 0xb7093(%rip), %rax     # 0x116c02
movq %rax, (%r14)
movl $0xf0, %esi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, 0x8(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5fcb7
cmpl $0x1, 0x18(%r15)
jne 0x5fb9d
movl $0x2, 0x18(%r15)
movl $0x1010101, 0x3b(%r15)  # imm = 0x1010101
movb $0x64, 0x41(%r15)
movb $0x66, 0x45(%r15)
movw $0x101, 0x47(%r15)      # imm = 0x101
movb $0x1, 0x49(%r15)
movq 0x18(%rbx), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf8849
movq %r14, %rdx
addq $0x10, %rdx
movb $-0x33, 0x10(%r14)
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0xf90d3
cmpb $-0x33, 0x11(%r14)
jne 0x5fc5a
movq 0x30(%r14), %rdx
leaq 0xb7019(%rip), %rsi     # 0x116c0e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x30(%r14), %rdx
addq $0x6, %rdx
movq %rdx, 0x28(%r15)
leaq 0xb6e6e(%rip), %rsi     # 0x116a80
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq 0x30(%r14), %rsi
addq $-0x2, %rsi
callq 0xe3fa3
leaq -0x1(%rax), %rdx
movq %rdx, 0x30(%r15)
leaq 0xb6c30(%rip), %rsi     # 0x11686c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5fd39
cmpb $0x0, 0x13(%r15)
jne 0x5fc5f
jmp 0x5fc73
movb $0x1, 0x13(%r15)
movq (%r14), %rdx
leaq 0xb6fba(%rip), %rsi     # 0x116c23
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r15, %rsi
callq 0xded32
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0xded32
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xded32