// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/mmm.c
// Function: de_run_mmm
static void de_run_mmm(deark *c, de_module_params *mparams)
{
	struct mmm_ctx *d = NULL;
	struct de_iffctx *ictx = NULL;
	const char *s;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	d = de_malloc(c, sizeof(struct mmm_ctx));
	d->input_encoding = de_get_input_encoding(c, mparams, DE_ENCODING_ASCII);
	d->opt_allowbad = (u8)de_get_ext_option_bool(c, "mmm:allowbad", 0);
	s = de_get_ext_option(c, "mmm:palid");
	if(s) {
		d->pal_id_to_use = de_atoi(s);
		d->force_pal = 1;
	}

	d->tmp_namestr = ucstring_create(c);

	d->pal1[0] = DE_STOCKCOLOR_BLACK;
	d->pal1[1] = DE_STOCKCOLOR_WHITE;

	if(!read_alt_palette_file(c, d)) goto done;

	ictx = fmtutil_create_iff_decoder(c);
	setup_ictx_for_mmm(c, d, ictx);
	ictx->f = c->infile;

	d->pass = 1;
	de_dbg(c, "pass %d", d->pass);
	de_dbg_indent(c, 1);
	fmtutil_read_iff_format(ictx, 0, c->infile->len);
	de_dbg_indent(c, -1);
	if(d->errflag) goto done;

	if(d->force_pal && !d->have_pal && !d->opt_allowbad) {
		de_err(c, "Palette %d not found", d->pal_id_to_use);
		goto done;
	}

	if(d->clut_count>1 && d->dib_count>0 && !d->opt_allowbad && !d->force_pal) {
		de_err(c, "Multiple palettes found (not supported, "
			"or try \"-opt mmm:palid=...\").");
		mmm_allowbad_note(c);
		d->suppress_dib_pass2 = 1;
	}

	d->pass = 2;
	de_dbg(c, "pass %d", d->pass);
	de_dbg_indent(c, 1);
	fmtutil_read_iff_format(ictx, 0, c->infile->len);
	de_dbg_indent(c, -1);

done:
	fmtutil_destroy_iff_decoder(ictx);
	if(d) {
		de_dbg(c, "dib count: %d", d->dib_count);
		de_dbg(c, "clut count: %d", d->clut_count);
		ucstring_destroy(d->tmp_namestr);
		de_free(c, d);
	}
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xc(%rsp), %rsi
callq 0xe958c
movl $0x438, %esi            # imm = 0x438
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xeb7d1
movl %eax, 0xc(%r14)
leaq 0x98dec(%rip), %rsi     # 0x1303ef
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
movb %al, 0x4(%r14)
leaq 0x98de4(%rip), %rsi     # 0x1303fc
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0x97636
movq %rax, %rdi
callq 0xea781
movl %eax, 0x8(%r14)
movb $0x1, 0x6(%r14)
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x28(%r14)
movq $-0x1000000, 0x30(%r14) # imm = 0xFF000000
leaq 0x78f3f(%rip), %rsi     # 0x110590
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0x97729
movb $0x1, 0x5(%r14)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf1717
movb $0x1, %r13b
testq %rax, %rax
je 0x97734
movq %rax, %r15
movq %rbx, %rdi
callq 0x107b04
movq %rax, %r12
movq %r14, 0x10(%rax)
movl $0x1, 0x58(%rax)
leaq 0x301(%rip), %rax       # 0x9799f
movq %rax, 0x20(%r12)
leaq 0x6e5(%rip), %rax       # 0x97d8f
movq %rax, 0x40(%r12)
leaq 0x768(%rip), %rax       # 0x97e1e
movq %rax, 0x28(%r12)
movq %r15, 0x18(%r12)
movl $0x64, (%r14)
leaq 0x98db0(%rip), %rsi     # 0x13047e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r15), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x107b28
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpb $0x0, 0x20(%r14)
jne 0x9772f
cmpb $0x0, 0x6(%r14)
je 0x978f8
movl 0x8(%r14), %edx
leaq 0x98ce9(%rip), %rsi     # 0x130406
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x9773a
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0x9773a
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x107b17
movq %r15, %rdi
callq 0xf0b13
movb $0x0, 0x10(%r14)
movq $0x0, 0x14(%r14)
testb %r13b, %r13b
je 0x97764
xorl %r15d, %r15d
jmp 0x97893
movq %rbx, %rdi
callq 0x107b04
movq %rax, %r15
movq %r14, 0x10(%rax)
movl $0x1, %eax
movl %eax, 0x58(%r15)
leaq 0x21c(%rip), %rcx       # 0x9799f
movq %rcx, 0x20(%r15)
leaq 0x601(%rip), %rcx       # 0x97d8f
movq %rcx, 0x40(%r15)
leaq 0x685(%rip), %rcx       # 0x97e1e
movq %rcx, 0x28(%r15)
movq 0x18(%rbx), %rcx
movq %rcx, 0x18(%r15)
movl %eax, (%r14)
leaq 0x89760(%rip), %rsi     # 0x120f0f
movq %rbx, %rdi
movl $0x1, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x107b28
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpb $0x0, 0x10(%r14)
jne 0x97893
movb 0x6(%r14), %al
testb %al, %al
je 0x9780f
cmpb $0x0, 0x20(%r14)
jne 0x9780f
cmpb $0x0, 0x4(%r14)
je 0x9790e
cmpl $0x2, 0x14(%r14)
jl 0x9784a
cmpl $0x0, 0x18(%r14)
jle 0x9784a
orb 0x4(%r14), %al
jne 0x9784a
leaq 0x98bf1(%rip), %rsi     # 0x13041b
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
leaq 0x98e7d(%rip), %rsi     # 0x1306b8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9ef5
movb $0x1, 0x11(%r14)
movl $0x2, (%r14)
leaq 0x896b7(%rip), %rsi     # 0x120f0f
movq %rbx, %rdi
movl $0x2, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x107b28
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %r15, %rdi
callq 0x107b17
testq %r14, %r14
je 0x978de
movl 0x18(%r14), %edx
leaq 0x98bb6(%rip), %rsi     # 0x130461
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x14(%r14), %edx
leaq 0x98baf(%rip), %rsi     # 0x13046f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x28(%r14), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x98b94(%rip), %rsi     # 0x130493
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x9773a
movl 0x8(%r14), %edx
leaq 0x98aed(%rip), %rsi     # 0x130406
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x97893