// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/bintext.c
// Function: de_run_grabber
static void de_run_grabber(deark *c, de_module_params *mparams)
{
	struct grabber_ctx *gctx = NULL;
	lctx *d = NULL;
	UI sig;

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

	sig = (UI)de_getu16le(0);
	if(sig==0x5a4d || sig==0x4d5a) {
		d->need_errmsg = 1;
		goto done;
	}

	grabber_id_com(c, (sig&0xff), &gctx->gi);
	if(!gctx->gi.is_grabber) {
		d->need_errmsg = 1;
		goto done;
	}

	de_dbg(c, "format class: %u", gctx->gi.fmt_class);
	decode_grabber_com(c, d, gctx);
	if(d->errflag) goto done;

	gctx->charctx->screen_image_flag = 1;
	d->csctx.height_in_chars = de_pad_to_n(gctx->data_len, d->csctx.width_in_chars*2) /
		(d->csctx.width_in_chars*2);
	de_dbg(c, "screen size: %"I64_FMT DE_CHAR_TIMES "%"I64_FMT, d->csctx.width_in_chars,
		d->csctx.height_in_chars);
	if(gctx->data_pos+gctx->data_len > c->infile->len) {
		d->need_errmsg = 1;
		goto done;
	}

	if(d->csctx.width_in_chars>80 || d->csctx.height_in_chars>25) {
		gctx->charctx->no_density = 1;
	}

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

done:
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Unsupported GRABBER format");
		}
		free_lctx(c, d);
	}
	if(gctx) {
		de_free_charctx(c, gctx->charctx);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
pushq $0x30
popq %rsi
callq 0xdecaf
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe88f4
movq %rax, 0x18(%r14)
pushq $0x70
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r12
movq %rax, %r15
pushq $0xd
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x48(%r12)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe3fa3
cmpl $0x5a4d, %eax           # imm = 0x5A4D
je 0x30921
cmpl $0x4d5a, %eax           # imm = 0x4D5A
je 0x30921
movq %r14, %rdx
addq $0x20, %rdx
movzbl %al, %esi
movq %rbx, %rdi
callq 0x31146
cmpb $0x0, 0x20(%r14)
je 0x30921
movl 0x24(%r14), %edx
leaq 0xd9d7e(%rip), %rsi     # 0x10a521
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq %rsp, %rbp
andq $0x0, (%rbp)
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r13
movq 0x18(%rbx), %rdi
pushq $0x70
popq %rdx
movl $0x400, %ecx            # imm = 0x400
movq %rax, %rsi
callq 0xe3cb7
leaq 0xd97a3(%rip), %rdx     # 0x109f83
pushq $0x6
popq %rcx
pushq $0x3f
popq %r8
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq %rbp, %r9
callq 0xe1021
testl %eax, %eax
je 0x308b4
movq (%rsp), %rbp
addq $0x76, %rbp
leaq 0xd9d55(%rip), %rsi     # 0x10a563
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3fa3
leaq -0x100(%rax), %rdx
movq %rdx, 0x8(%r14)
leaq 0xe85fc(%rip), %rsi     # 0x118e35
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpl $0x12c, 0x24(%r14)      # imm = 0x12C
pushq $-0x7
popq %rax
pushq $-0x11
popq %rbp
cmovbq %rax, %rbp
addq 0x8(%r14), %rbp
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xe3eb4
movb %al, (%r14)
movzbl %al, %edx
leaq 0x10dfe3(%rip), %rsi    # 0x13e855
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpb $0x3, (%r14)
jne 0x308b4
movq 0x18(%rbx), %rdi
addq $0x2, %rbp
movq %rbp, %rsi
callq 0xe3fa3
movq %rax, 0x10(%r14)
leaq 0xf5046(%rip), %rsi     # 0x1258e3
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq $0x50, 0x50(%r15)
jmp 0x308ba
movw $0x101, (%r15)          # imm = 0x101
movq %rbx, %rdi
movq %r13, %rsi
callq 0xded32
cmpb $0x0, (%r15)
jne 0x30926
movq 0x18(%r14), %rax
movb $0x1, 0x2(%rax)
movq 0x10(%r14), %rdi
movq 0x50(%r15), %rsi
addq %rsi, %rsi
callq 0xdfbb6
movq 0x50(%r15), %rcx
leaq (%rcx,%rcx), %rsi
cqto
idivq %rsi
movq %rax, 0x58(%r15)
leaq 0xd9c37(%rip), %rsi     # 0x10a532
movq %rbx, %rdi
movq %rcx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
leaq (%rcx,%rax), %rdx
movq 0x18(%rbx), %rsi
cmpq 0x18(%rsi), %rdx
jle 0x30964
movb $0x1, 0x1(%r15)
cmpb $0x0, 0x1(%r15)
je 0x3093e
leaq 0xd9c14(%rip), %rsi     # 0x10a548
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r15, %rsi
callq 0x30db6
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq 0xe89d2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x30, %r12
cmpq $0x50, 0x50(%r15)
jg 0x30976
cmpq $0x19, 0x58(%r15)
jle 0x30980
movq 0x18(%r14), %rdx
movb $0x1, 0x3(%rdx)
jmp 0x30984
movq 0x18(%r14), %rdx
movb $0x1, 0x4c(%r15)
movq %rsi, 0x30(%r15)
movq %rax, 0x38(%r15)
movq %rcx, 0x40(%r15)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xee2e5
jmp 0x30926