// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/macpaint.c
// Function: de_run_macpaint
static void de_run_macpaint(deark *c, de_module_params *mparams)
{
	lctx *d;
	struct validity_info *vi1 = NULL;
	struct validity_info *vi2 = NULL;

	d = de_malloc(c, sizeof(lctx));
	d->has_macbinary_header = de_get_ext_option_bool(c, "macpaint:macbinary", -1);

	if(d->has_macbinary_header == -1) {
		d->is_fmac2com = is_fmac2com(c);
	}

	if(d->is_fmac2com) {
		d->has_macbinary_header = 1;
	}

	if(d->has_macbinary_header == -1) {
		int v512;
		int v640;

		de_dbg(c, "trying to determine if file has a MacBinary header");
		de_dbg_indent(c, 1);

		vi1 = de_malloc(c, sizeof(struct validity_info));
		vi1->pos = 0;
		test_valid_image(c, d, vi1);
		v512 = vi1->retval;

		vi2 = de_malloc(c, sizeof(struct validity_info));
		vi2->pos = 128;
		test_valid_image(c, d, vi2);
		v640 = vi2->retval;

		de_dbg_indent(c, -1);

		if(v512 > v640) {
			de_dbg(c, "assuming it has no MacBinary header");
			d->has_macbinary_header = 0;
		}
		else if(v640 > v512) {
			de_dbg(c, "assuming it has a MacBinary header");
			d->has_macbinary_header = 1;
		}
		else if(v512 && v640) {
			de_warn(c, "Can't determine if this file has a MacBinary header. "
				"Try \"-opt macpaint:macbinary=0\".");
			d->has_macbinary_header = 1;
		}
		else {
			de_warn(c, "This is probably not a MacPaint file.");
			d->has_macbinary_header = 1;
		}
	}

	if(d->is_fmac2com)
		de_declare_fmt(c, "FMAC2COM self-displaying MacPaint");
	else if(d->has_macbinary_header)
		de_declare_fmt(c, "MacPaint with MacBinary header");
	else
		de_declare_fmt(c, "MacPaint without MacBinary header");

	if(d->has_macbinary_header) {
		d->hdr_pos = 128;
	}
	else {
		d->hdr_pos = 0;
	}
	d->img_data_pos = d->hdr_pos + 512;

	if(d->has_macbinary_header) {
		do_macbinary(c, d);
	}

	do_read_bitmap(c, d);

	if(!d->is_fmac2com) {
		do_read_patterns(c, d);
	}

	if(d) {
		ucstring_destroy(d->filename);
		de_free(c, d);
	}
	de_free(c, vi1);
	de_free(c, vi2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl $0x50, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xe289a(%rip), %rsi     # 0x1bb497
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x15cbc0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0xd8c2a
movq -0x8(%rbp), %rdi
callq 0xd8fd0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0xd8c3e
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0xd8d81
movq -0x8(%rbp), %rdi
leaq 0xe2854(%rip), %rsi     # 0x1bb4aa
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movl $0x60, %esi
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xd9040
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
movl $0x60, %esi
callq 0x15b780
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq $0x80, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xd9040
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jle 0xd8d0f
movq -0x8(%rbp), %rdi
leaq 0xe27e1(%rip), %rsi     # 0x1bb4dd
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
jmp 0xd8d7f
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0xd8d35
movq -0x8(%rbp), %rdi
leaq 0xe27df(%rip), %rsi     # 0x1bb501
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0xd8d7d
cmpl $0x0, -0x2c(%rbp)
je 0xd8d5f
cmpl $0x0, -0x30(%rbp)
je 0xd8d5f
movq -0x8(%rbp), %rdi
leaq 0xe27d8(%rip), %rsi     # 0x1bb524
movb $0x0, %al
callq 0x15bc10
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0xd8d7b
movq -0x8(%rbp), %rdi
leaq 0xe2810(%rip), %rsi     # 0x1bb57a
movb $0x0, %al
callq 0x15bc10
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0xd8d7d
jmp 0xd8d7f
jmp 0xd8d81
movq -0x18(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0xd8d9d
movq -0x8(%rbp), %rdi
leaq 0xe280a(%rip), %rsi     # 0x1bb5a0
callq 0x15e380
jmp 0xd8dca
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xd8db8
movq -0x8(%rbp), %rdi
leaq 0xe2811(%rip), %rsi     # 0x1bb5c2
callq 0x15e380
jmp 0xd8dc8
movq -0x8(%rbp), %rdi
leaq 0xe281e(%rip), %rsi     # 0x1bb5e1
callq 0x15e380
jmp 0xd8dca
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xd8de1
movq -0x18(%rbp), %rax
movq $0x80, 0x40(%rax)
jmp 0xd8ded
movq -0x18(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
addq $0x200, %rcx            # imm = 0x200
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xd8e1a
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xd9330
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xd95c0
movq -0x18(%rbp), %rax
cmpb $0x0, 0x4(%rax)
jne 0xd8e3e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xd9930
cmpq $0x0, -0x18(%rbp)
je 0xd8e5f
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq
nop