// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
movq %rax, %r14
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r15
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb220
movl %eax, 0x48(%r15)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xf3eb8
movq %rax, 0x10(%r14)
leaq 0xe08a0(%rip), %rsi     # 0x111b99
movq %rbx, %rdi
callq 0xe9b74
testq %rax, %rax
je 0x3130d
movl $0x1, (%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeead3
movzbl %al, %esi
leaq 0x18(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x32189
cmpb $0x0, (%r12)
je 0x314bb
movq 0x18(%rbx), %rsi
leaq 0xd(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
movl $0x1, %ecx
callq 0xf7f3d
cmpb $0x0, (%r12)
je 0x313c7
movq %rbx, %rdi
callq 0xf8028
movq %rax, 0x8(%r14)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xf7fdd
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x8(%r14), %rax
cmpl $0x0, (%rax)
je 0x313c7
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 0xe615f(%rip), %rsi     # 0x117539
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0xe0(%r12), %rsi
callq 0xeead3
movl $0x14, %edx
cmpb $-0x18, %al
je 0x3140e
movl $0x19, %edx
cmpb $-0x4c, %al
jne 0x314bb
xorl %r13d, %r13d
cmpb $-0x18, %al
setne %r13b
leaq 0xe6128(%rip), %rsi     # 0x117546
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq -0x18(%r12), %rsi
callq 0xeebc8
movq %rax, %rbp
leaq -0x100(%rax), %rdx
leaq 0xf4bee(%rip), %rsi     # 0x126035
movq %rbx, %rdi
movq %rdx, 0x10(%rsp)
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
addq $0x10, %r12
movq %r12, %rsi
callq 0xeebc8
addq %rax, %r13
leaq 0xe60ea(%rip), %rsi     # 0x11755a
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq $0x50, 0x50(%r15)
movq %r13, 0x58(%r15)
shlq $0x5, %r13
leaq (%r13,%r13,4), %r13
leaq -0x100(,%r13), %r12
addq %rbp, %r12
leaq 0xe60c4(%rip), %rsi     # 0x117568
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jle 0x31503
movb $0x1, 0x1(%r15)
leaq 0xe60b2(%rip), %rsi     # 0x117579
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r15, %rsi
callq 0x31e6b
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xf3fb8
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0xf8032
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 0xf9c77
cmpb $0x0, 0x1(%r15)
jne 0x314c0
jmp 0x314d1