// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/bintext.c
// Function: de_run_aciddraw_com
static void de_run_aciddraw_com(deark *c, de_module_params *mparams)
{
	struct aciddraw_ctx *adctx = NULL;
	lctx *d = NULL;
	u8 b;
	UI fmtver = 0;
	struct aciddraw_id_data adi;
	i64 data_pos, data_len;
	i64 num_rows;

	adctx = de_malloc(c, sizeof(struct aciddraw_ctx));
	d = de_malloc(c, sizeof(lctx));
	d->csctx.input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437);
	adctx->charctx = de_create_charctx(c, 0);

	if(de_get_ext_option(c, "ansiart:noblink")) {
		adctx->opt_disable_blink = 1;
	}

	aciddraw_id(c, de_getbyte(0), &adi);
	if(!adi.is_aciddraw) {
		d->need_errmsg = 1;
		goto done;
	}

	aciddraw_handle_SAUCE(c, adctx);

	d->csctx.nonblink = adctx->opt_disable_blink;

	de_dbg(c, "jmp pos: %"I64_FMT, adi.jmppos);

	b = de_getbyte(adi.jmppos+224);
	if(b==0xe8) {
		fmtver = 20;
	}
	else if(b==0xb4) {
		fmtver = 25;
	}
	else {
		d->need_errmsg = 1;
		goto done;
	}
	de_dbg(c, "version: v1.%u-like", fmtver);

	data_pos = de_getu16le(adi.jmppos-24);
	data_pos -= 0x100;
	de_dbg(c, "data pos: %"I64_FMT, data_pos);

	num_rows = de_getu16le(adi.jmppos+16);
	if(fmtver==25) num_rows++;
	de_dbg(c, "num rows: %"I64_FMT, num_rows);

	d->csctx.width_in_chars = 80;
	d->csctx.height_in_chars = num_rows;

	data_len = num_rows * d->csctx.width_in_chars * 2;
	de_dbg(c, "data endpos: %"I64_FMT, data_pos + data_len);

	if(data_pos+data_len > c->infile->len) {
		d->need_errmsg = 1;
		goto done;
	}

	d->csctx.use_default_pal = 1;
	d->csctx.inf = c->infile;
	d->csctx.inf_pos = data_pos;
	d->csctx.inf_len = data_len;
	fmtutil_char_simple_run(c, &d->csctx, adctx->charctx);

done:
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Unsupported ACiDDraw format");
		}
		free_lctx(c, d);
	}
	if(adctx) {
		de_free_charctx(c, adctx->charctx);
		fmtutil_free_SAUCE(c, adctx->si);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0x18, %esi
callq 0xe969b
movq %rax, %r14
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r15
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, 0x48(%r15)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xf43cc
movq %rax, 0x10(%r14)
leaq 0xe072b(%rip), %rsi     # 0x111b89
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0x31472
movl $0x1, (%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef0d5
movzbl %al, %esi
leaq 0x18(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x323aa
cmpb $0x0, (%r12)
je 0x31628
movq 0x18(%rbx), %rsi
leaq 0xd(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
movl $0x1, %ecx
callq 0xf840d
cmpb $0x0, (%r12)
je 0x31534
movq %rbx, %rdi
callq 0xf84f4
movq %rax, 0x8(%r14)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf84ad
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x8(%r14), %rax
cmpl $0x0, (%rax)
je 0x31534
movq 0x8(%rax), %rcx
movq 0x10(%r14), %rdx
movq %rcx, 0x68(%rdx)
movq 0x10(%rax), %rcx
movq %rcx, 0x70(%rdx)
movq 0x18(%rax), %rcx
movq %rcx, 0x78(%rdx)
movups 0x20(%rax), %xmm0
movups %xmm0, 0x80(%rdx)
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
movq 0x60(%rax), %rax
movq %rax, 0x90(%rcx)
movb (%r14), %al
movb %al, 0x4d(%r15)
movq 0x20(%rsp), %r12
leaq 0xe5f52(%rip), %rsi     # 0x117499
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0xe0(%r12), %rsi
callq 0xef0d5
movl $0x14, %edx
cmpb $-0x18, %al
je 0x3157b
movl $0x19, %edx
cmpb $-0x4c, %al
jne 0x31628
xorl %r13d, %r13d
cmpb $-0x18, %al
setne %r13b
leaq 0xe5f1b(%rip), %rsi     # 0x1174a6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq -0x18(%r12), %rsi
callq 0xef1ca
movq %rax, %rbp
leaq -0x100(%rax), %rdx
leaq 0xf4851(%rip), %rsi     # 0x125e05
movq %rbx, %rdi
movq %rdx, 0x10(%rsp)
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
addq $0x10, %r12
movq %r12, %rsi
callq 0xef1ca
addq %rax, %r13
leaq 0xe5edd(%rip), %rsi     # 0x1174ba
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe9226
movq $0x50, 0x50(%r15)
movq %r13, 0x58(%r15)
shlq $0x5, %r13
leaq (%r13,%r13,4), %r13
leaq -0x100(,%r13), %r12
addq %rbp, %r12
leaq 0xe5eb7(%rip), %rsi     # 0x1174c8
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jle 0x3162f
movb $0x1, 0x1(%r15)
jmp 0x31655
leaq 0x30(%r15), %rsi
movb $0x1, 0x4c(%r15)
movq %rax, 0x30(%r15)
movq 0x10(%rsp), %rax
movq %rax, 0x38(%r15)
movq %r13, 0x40(%r15)
movq 0x10(%r14), %rdx
movq %rbx, %rdi
callq 0xfa176
testq %r15, %r15
je 0x3167d
cmpb $0x0, 0x1(%r15)
je 0x31672
leaq 0xe5e71(%rip), %rsi     # 0x1174d9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x31fe3
testq %r14, %r14
je 0x3169a
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xf44c8
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0xf84fe
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq