// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x18
popq %rsi
callq 0xdecaf
movq %rax, %r14
pushq $0x70
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r15
pushq $0xd
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x48(%r15)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe88f4
movq %rax, 0x10(%r14)
leaq 0xd48ef(%rip), %rsi     # 0x104b79
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x3029e
movl $0x1, (%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe3eb4
movzbl %al, %esi
leaq 0x18(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x310d8
cmpb $0x0, (%r12)
je 0x30441
movq 0x18(%rbx), %rsi
leaq 0xd(%rsp), %r12
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xec67d
cmpb $0x0, (%r12)
je 0x30352
movq %rbx, %rdi
callq 0xec762
movq %rax, 0x8(%r14)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xec71a
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x8(%r14), %rax
cmpl $0x0, (%rax)
je 0x30352
movq 0x10(%r14), %rcx
movups 0x8(%rax), %xmm0
movups %xmm0, 0x68(%rcx)
movq 0x18(%rax), %rdx
movq %rdx, 0x78(%rcx)
movups 0x20(%rax), %xmm0
movups %xmm0, 0x80(%rcx)
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 0xda144(%rip), %rsi     # 0x10a4a9
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0xe0(%r12), %rsi
callq 0xe3eb4
cmpb $-0x18, %al
je 0x30393
cmpb $-0x4c, %al
jne 0x30441
pushq $0x19
jmp 0x30395
pushq $0x14
popq %rdx
xorl %r13d, %r13d
cmpb $-0x18, %al
setne %r13b
leaq 0xda110(%rip), %rsi     # 0x10a4b6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq -0x18(%r12), %rsi
callq 0xe3fa3
movq %rax, %rbp
leaq -0x100(%rax), %rdx
leaq 0xe8a66(%rip), %rsi     # 0x118e35
movq %rbx, %rdi
movq %rdx, 0x10(%rsp)
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
addq $0x10, %r12
movq %r12, %rsi
callq 0xe3fa3
addq %rax, %r13
leaq 0xda0d2(%rip), %rsi     # 0x10a4ca
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xde896
movq $0x50, 0x50(%r15)
movq %r13, 0x58(%r15)
imulq $0xa0, %r13, %r13
leaq -0x100(,%rbp), %r12
addq %r13, %r12
leaq 0xda0ae(%rip), %rsi     # 0x10a4d8
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jle 0x30489
movb $0x1, 0x1(%r15)
leaq 0xda09c(%rip), %rsi     # 0x10a4e9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r15, %rsi
callq 0x30db6
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xe89d2
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0xec76a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rsi
addq $0x30, %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 0xee2e5
cmpb $0x0, 0x1(%r15)
jne 0x30446
jmp 0x30457