// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8dcb0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x88, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
leaq 0x121c59(%rip), %rcx    # 0x1af6f3
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl $0xf0, %esi
callq 0x15b780
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0xd, %edx
callq 0x8dcf0
movq -0x20(%rbp), %rax
cmpl $0x1, 0x18(%rax)
jne 0x8dadd
movq -0x20(%rbp), %rax
movl $0x2, 0x18(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x3b(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x3c(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x3d(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x3e(%rax)
movq -0x20(%rbp), %rax
movb $0x64, 0x41(%rax)
movq -0x20(%rbp), %rax
movb $0x66, 0x45(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x47(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x48(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x49(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x188930
movq -0x18(%rbp), %rax
movb $-0x33, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rdx
addq $0x10, %rdx
callq 0x189890
movq -0x18(%rbp), %rax
movzbl 0x11(%rax), %eax
cmpl $0xcd, %eax
je 0x8db7b
movq -0x20(%rbp), %rax
movb $0x1, 0x13(%rax)
jmp 0x8dc12
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdx
leaq 0x121b71(%rip), %rsi    # 0x1af6ff
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x6, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x1219b5(%rip), %rsi    # 0x1af571
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rsi
subq $0x2, %rsi
callq 0x165280
movq %rax, %rcx
subq $0x1, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdx
leaq 0x12175f(%rip), %rsi    # 0x1af35d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x8df30
cmpq $0x0, -0x20(%rbp)
je 0x8dc5b
movq -0x20(%rbp), %rax
movzbl 0x13(%rax), %eax
cmpl $0x0, %eax
je 0x8dc46
cmpq $0x0, -0x18(%rbp)
je 0x8dc46
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq 0x121ad5(%rip), %rsi    # 0x1af714
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
movq $0x0, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x8dc80
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)