// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x4(%rsp), %rsi
callq 0xdebae
movl $0x438, %esi            # imm = 0x438
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r14
pushq $0x1
popq %rbp
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0xe08d2
movl %eax, 0xc(%r14)
leaq 0x91dca(%rip), %rsi     # 0x123447
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
movb %al, 0x4(%r14)
leaq 0x91dc2(%rip), %rsi     # 0x123454
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x916b0
movq %rax, %rdi
callq 0xdfb36
movl %eax, 0x8(%r14)
movb $0x1, 0x6(%r14)
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x28(%r14)
movq $-0x1000000, 0x30(%r14) # imm = 0xFF000000
leaq 0x71eb1(%rip), %rsi     # 0x10357c
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x9179f
movb $0x1, 0x5(%r14)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xe600b
movb $0x1, %r13b
testq %rax, %rax
je 0x917aa
movq %rax, %r15
movq %rbx, %rdi
callq 0xfacc0
movq %rax, %r12
movq %r14, 0x10(%rax)
movl $0x1, 0x58(%rax)
leaq 0x2e3(%rip), %rax       # 0x919fb
movq %rax, 0x20(%r12)
leaq 0xf7b(%rip), %rax       # 0x9269f
movq %rax, 0x40(%r12)
leaq 0xfed(%rip), %rax       # 0x9271d
movq %rax, 0x28(%r12)
movq %r15, 0x18(%r12)
movl $0x64, (%r14)
leaq 0x91d8e(%rip), %rsi     # 0x1234d6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%r15), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0xface4
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
cmpb $0x0, 0x20(%r14)
jne 0x917a5
cmpb $0x0, 0x6(%r14)
je 0x9194a
movl 0x8(%r14), %edx
leaq 0x91ccb(%rip), %rsi     # 0x12345e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x917b0
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0x917b0
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r12, %rdi
callq 0xfacd3
movq %r15, %rdi
callq 0xe5591
movb $0x0, 0x10(%r14)
andq $0x0, 0x14(%r14)
testb %r13b, %r13b
je 0x917d7
xorl %r15d, %r15d
jmp 0x918e9
movq %rbx, %rdi
callq 0xfacc0
movq %rax, %r15
movq %r14, 0x10(%rax)
movl %ebp, 0x58(%rax)
leaq 0x20b(%rip), %rax       # 0x919fb
movq %rax, 0x20(%r15)
leaq 0xea4(%rip), %rax       # 0x9269f
movq %rax, 0x40(%r15)
leaq 0xf17(%rip), %rax       # 0x9271d
movq %rax, 0x28(%r15)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r15)
movl %ebp, (%r14)
leaq 0x8272b(%rip), %rsi     # 0x113f47
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0xface4
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
cmpb $0x0, 0x10(%r14)
jne 0x918e9
movb 0x6(%r14), %al
testb %al, %al
je 0x91874
cmpb $0x0, 0x20(%r14)
jne 0x91874
cmpb $0x0, 0x4(%r14)
je 0x91960
cmpl $0x2, 0x14(%r14)
jl 0x918a6
cmpl $0x0, 0x18(%r14)
jle 0x918a6
orb 0x4(%r14), %al
jne 0x918a6
leaq 0x91be4(%rip), %rsi     # 0x123473
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
callq 0x919ed
movb $0x1, 0x11(%r14)
movl $0x2, (%r14)
leaq 0x82693(%rip), %rsi     # 0x113f47
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0xface4
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %r15, %rdi
callq 0xfacd3
movl 0x18(%r14), %edx
leaq 0x91bbd(%rip), %rsi     # 0x1234b9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x14(%r14), %edx
leaq 0x91bb6(%rip), %rsi     # 0x1234c7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x28(%r14), %rdi
callq 0xeaf3c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x91b9a(%rip), %rsi     # 0x1234eb
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x917b0
movl 0x8(%r14), %edx
leaq 0x91af3(%rip), %rsi     # 0x12345e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x918e9