// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %r12
pushq $0x50
popq %rsi
callq 0xdecaf
movq %rax, %r13
leaq 0x944f3(%rip), %rsi     # 0x122744
pushq $-0x1
popq %rdx
movq %r12, %rdi
callq 0xdfae5
movl %eax, (%r13)
cmpl $-0x1, %eax
je 0x8e26b
movb 0x4(%r13), %al
jmp 0x8e277
movq %r12, %rdi
callq 0x8ed5e
movb %al, 0x4(%r13)
testb %al, %al
je 0x8e2a1
movl $0x1, (%r13)
leaq 0x945c3(%rip), %rsi     # 0x12284d
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
jmp 0x8e3c7
movl (%r13), %r14d
cmpl $-0x1, %r14d
je 0x8e2d7
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
testl %r14d, %r14d
leaq 0x945c7(%rip), %rax     # 0x12288e
leaq 0x945a1(%rip), %rsi     # 0x12286f
cmoveq %rax, %rsi
jmp 0x8e3c7
leaq 0x94479(%rip), %rsi     # 0x122757
xorl %r14d, %r14d
movq %r12, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
callq 0xdeba7
pushq $0x60
popq %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0xdecaf
movq %rax, %rbx
andq $0x0, (%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x8edaa
movq %rbx, 0x38(%rsp)
movl 0x8(%rbx), %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0xdecaf
movq %rax, %r15
movq $0x80, (%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x8edaa
movq %r15, 0x30(%rsp)
movl 0x8(%r15), %r15d
pushq $-0x1
popq %rsi
movq %r12, %rdi
callq 0xdeba7
cmpl %r15d, %ebx
jle 0x8e36d
leaq 0x94429(%rip), %rsi     # 0x12278a
movq %r12, %rdi
xorl %eax, %eax
callq 0xde896
jmp 0x8e3b1
jge 0x8e382
leaq 0x94438(%rip), %rsi     # 0x1227ae
movq %r12, %rdi
xorl %eax, %eax
callq 0xde896
jmp 0x8e3ae
testl %ebx, %ebx
setne %al
testl %r15d, %r15d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x8e39d
leaq 0x94436(%rip), %rsi     # 0x1227d1
jmp 0x8e3a4
leaq 0x94483(%rip), %rsi     # 0x122827
movq %r12, %rdi
xorl %eax, %eax
callq 0xdf05a
movl %ebp, %r14d
movl %r14d, (%r13)
cmpb $0x0, 0x4(%r13)
je 0x8e2bd
leaq 0x94486(%rip), %rsi     # 0x12284d
movq %r12, %rdi
callq 0xe07f7
cmpl $0x0, (%r13)
je 0x8e5c1
movq $0x80, 0x40(%r13)
movq $0x280, 0x48(%r13)      # imm = 0x280
movq 0x18(%r12), %rdi
xorl %esi, %esi
callq 0xe3eb4
movl %eax, %ebp
movq 0x18(%r12), %rdi
pushq $0x1
popq %rsi
callq 0xe3eb4
testb %bpl, %bpl
jne 0x8e5ce
addb $-0x40, %al
cmpb $-0x3f, %al
jb 0x8e5ce
leaq 0x9474b(%rip), %rsi     # 0x122b6a
movq %r12, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0xdeba7
pushq $0x70
popq %rsi
movq %r12, %rdi
callq 0xdecaf
movq %rax, %r15
leaq 0xb0757(%rip), %rax     # 0x13eba0
movq %rax, (%r15)
movq %r12, %rdi
callq 0xdfd1a
movq %rax, 0x60(%r15)
movq %r12, %rdi
callq 0xeac74
movq 0x60(%r15), %rcx
movq %rax, 0x90(%rcx)
movq 0x18(%r12), %rcx
movq 0x18(%rcx), %r9
leaq 0x942d2(%rip), %rsi     # 0x12274d
movq %r12, %rdi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0xdf9b8
pushq $-0x1
popq %rsi
movq %r12, %rdi
callq 0xdeba7
movl 0x44(%r15), %eax
testq %rax, %rax
je 0x8e4ae
movb $0x1, 0x5(%r13)
movq %rax, 0x8(%r13)
movl 0x48(%r15), %eax
movq %rax, 0x18(%r13)
movl 0x4c(%r15), %eax
testq %rax, %rax
je 0x8e4c8
movb $0x1, 0x6(%r13)
movq %rax, 0x10(%r13)
movl 0x50(%r15), %eax
movq %rax, 0x20(%r13)
movq 0x60(%r15), %rax
cmpb $0x0, 0x18(%rax)
je 0x8e4de
addq $0x18, %rax
movups (%rax), %xmm0
movups %xmm0, 0x30(%r13)
cmpb $0x0, 0x5(%r13)
je 0x8e511
movq 0x18(%r13), %rdx
addq 0x8(%r13), %rdx
movq 0x18(%r12), %rax
movq 0x18(%rax), %rcx
cmpq %rcx, %rdx
jle 0x8e511
leaq 0x94457(%rip), %rsi     # 0x122959
movq %r12, %rdi
xorl %eax, %eax
callq 0xdf05a
movb $0x0, 0x5(%r13)
movq 0x60(%r15), %rax
movq 0x90(%rax), %rdi
callq 0xeaf8a
testl %eax, %eax
je 0x8e540
cmpq $0x0, 0x28(%r13)
jne 0x8e540
movq 0x60(%r15), %rax
movq 0x90(%rax), %rdi
callq 0xeaf0b
movq %rax, 0x28(%r13)
cmpb $0x0, 0x6(%r13)
je 0x8e5a8
movq 0x20(%r13), %rcx
testq %rcx, %rcx
jle 0x8e5a8
movq 0x10(%r13), %rdx
leaq (%rdx,%rcx), %rax
movq 0x18(%r12), %rsi
cmpq 0x18(%rsi), %rax
jg 0x8e5a8
leaq 0x9442d(%rip), %rsi     # 0x122997
movq %r12, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0xdeba7
movq 0x18(%r12), %rcx
movq 0x10(%r13), %r8
movq 0x20(%r13), %r9
leaq 0x7b5a9(%rip), %rsi     # 0x109b3c
movq %r12, %rdi
xorl %edx, %edx
callq 0xdfa28
pushq $-0x1
popq %rsi
movq %r12, %rdi
callq 0xdeba7
movq 0x60(%r15), %rsi
movq %r12, %rdi
callq 0xdfd24
movq %r12, %rdi
movq %r15, %rsi
callq 0xded32
jmp 0x8e5ce
andq $0x0, 0x40(%r13)
movq $0x200, 0x48(%r13)      # imm = 0x200
leaq 0x54(%rsp), %rsi
movq %r12, %rdi
callq 0xdebae
cmpb $0x0, 0x4(%r13)
jne 0x8e652
movq 0x40(%r13), %rdx
leaq 0x87bd2(%rip), %rsi     # 0x1161bf
movq %r12, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0xdeba7
movq 0x18(%r12), %rdi
movq 0x40(%r13), %rsi
callq 0xe404f
movq %rax, %r15
leaq 0x78eb2(%rip), %rsi     # 0x1074cc
movq %r12, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
cmpq $0x3, %r15
ja 0x8e633
cmpq $0x1, %r15
jne 0x8e647
leaq 0x9437b(%rip), %rsi     # 0x1229b5
movq %r12, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xdf05a
pushq $-0x1
popq %rsi
movq %r12, %rdi
callq 0xdeba7
movq 0x48(%r13), %r15
leaq 0x9f76a(%rip), %rsi     # 0x12ddc7
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
callq 0xdeba7
movl $0xca80, %esi           # imm = 0xCA80
movq %r12, %rdi
movl %ebp, %edx
callq 0xe59cd
movq %rax, %r14
movq %rax, %rdi
callq 0xe589c
movq %r12, %rbx
leaq 0x88(%rsp), %r12
leaq 0x70(%rsp), %rbp
leaq 0xa8(%rsp), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0xee7ee
movq 0x18(%rbx), %rax
movq %rax, (%r12)
movq %r15, 0x8(%r12)
movq 0x18(%rax), %rax
movq %r15, 0x40(%rsp)
subq %r15, %rax
movq %rax, 0x10(%r12)
movq %r14, 0x28(%rsp)
movq %r14, (%rbp)
movb $0x1, 0x8(%rbp)
movq $0xca80, 0x10(%rbp)     # imm = 0xCA80
pushq $0x4
popq %rsi
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
xorl %ebx, %ebx
callq 0xdecaf
movq 0x8(%r12), %r15
leaq 0x18(%rsp), %rbp
movq %r15, (%rbp)
addq 0x10(%r12), %r15
movq %rax, 0x48(%rsp)
movq %r13, 0x20(%rsp)
movb $0x0, 0x7(%r13)
pushq $0x48
popq %r14
xorl %r13d, %r13d
cmpb $0x0, 0x78(%rsp)
je 0x8e73a
cmpq 0x80(%rsp), %r13
jge 0x8e807
movq 0x18(%rsp), %rax
addq $0x2, %rax
cmpq %r15, %rax
jg 0x8e807
movq 0x88(%rsp), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movzbl %al, %r12d
testb %al, %al
jns 0x8e79a
negb %al
jo 0x8e725
movl $0x101, %r14d           # imm = 0x101
subq %r12, %r14
movq 0x88(%rsp), %rdi
movq %rbp, %rsi
callq 0xe3f2a
movq 0x70(%rsp), %rdi
movzbl %al, %esi
movq %r14, %rdx
callq 0xe5e40
movq %r14, %r12
pushq $0x48
popq %r14
jmp 0x8e7c8
movq 0x18(%rsp), %rsi
leaq (%rsi,%r12), %rax
incq %rax
cmpq %r15, %rax
jg 0x8e7ff
incq %r12
movq 0x88(%rsp), %rdi
movq 0x70(%rsp), %rcx
movq %r12, %rdx
callq 0xe45f4
addq %r12, 0x18(%rsp)
addq %r12, %r13
movq %rbx, %rax
addq %r12, %rax
movl $0x0, %ebx
cmpq $0x48, %rax
je 0x8e725
movq %rax, %rbx
jle 0x8e725
movq 0x20(%rsp), %rcx
movb $0x1, 0x7(%rcx)
xorl %edx, %edx
divq %r14
movq %rdx, %rbx
jmp 0x8e725
decq %rsi
movq %rsi, 0x18(%rsp)
movq 0x70(%rsp), %rdi
callq 0xe58e8
movq 0x18(%rsp), %rax
subq 0x90(%rsp), %rax
movq %rax, 0xb0(%rsp)
movb $0x1, 0xac(%rsp)
movq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0xe58e8
movq 0xb0(%rsp), %r12
movq 0x18(%r13), %rcx
leaq 0x85c11(%rip), %rsi     # 0x11445f
movq 0x10(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x20(%rsp), %r14
cmpb $0x0, 0x5(%r14)
je 0x8e891
addq 0x40(%rsp), %r12
movq 0x18(%r14), %rcx
addq 0x8(%r14), %rcx
cmpq %rcx, %r12
jle 0x8e891
leaq 0x94153(%rip), %rsi     # 0x1229d5
movq 0x10(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xdf05a
movq 0x18(%r13), %rdx
cmpq $0xca7f, %rdx           # imm = 0xCA7F
jg 0x8e8bb
leaq 0x94179(%rip), %rsi     # 0x122a1e
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0xca80, %ecx           # imm = 0xCA80
xorl %eax, %eax
callq 0xdf05a
jmp 0x8e8d8
cmpb $0x0, 0x7(%r14)
movq 0x10(%rsp), %rbx
je 0x8e8d8
leaq 0x9417e(%rip), %rsi     # 0x122a4c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r15
movq 0x28(%r14), %rdx
testq %rdx, %rdx
je 0x8e902
cmpb $0x0, 0xd0(%rbx)
je 0x8e902
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xdfd55
cmpb $0x0, 0x30(%r14)
je 0x8e918
movq %r14, %rax
addq $0x30, %rax
movups (%rax), %xmm0
movups %xmm0, 0x68(%r15)
movq %r15, (%rsp)
andl $0x0, 0x8(%rsp)
pushq $0x48
popq %r8
pushq $0x1
popq %r9
movl $0x240, %edx            # imm = 0x240
movl $0x2d0, %ecx            # imm = 0x2D0
movq %r13, %rdi
xorl %esi, %esi
callq 0xe7804
movq %r13, %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r15, %rsi
callq 0xdfd24
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
callq 0xded32
movl 0x54(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
cmpb $0x0, 0x4(%r14)
jne 0x8ec58
leaq 0xa8(%rsp), %rsi
movq %rbx, %rdi
callq 0xdebae
leaq 0x94103(%rip), %rsi     # 0x122a8e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x40(%r14), %r12
addq $0x4, %r12
leaq 0x940f0(%rip), %rsi     # 0x122aa1
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl $0x130, %ecx            # imm = 0x130
movq %rax, %rdi
movq %r12, %rdx
callq 0xe0f33
movq %r14, %rdi
callq 0xe0e95
movl %eax, %ebp
movq %r14, %rdi
callq 0xe0e8d
cmpl $0xb5348fd2, %ebp       # imm = 0xB5348FD2
je 0x8ea39
movb $0x1, %bl
cmpl $0x284a7a15, %ebp       # imm = 0x284A7A15
je 0x8ea27
cmpl $0x47514647, %ebp       # imm = 0x47514647
je 0x8ea30
cmpl $0x33d2d8d6, %ebp       # imm = 0x33D2D8D6
jne 0x8ea44
leaq 0x992dc(%rip), %rcx     # 0x127d01
jmp 0x8ea4b
leaq 0x940de(%rip), %rcx     # 0x122b0c
jmp 0x8ea4b
leaq 0x940c9(%rip), %rcx     # 0x122b00
jmp 0x8ea40
leaq 0x940c6(%rip), %rcx     # 0x122b06
xorl %ebx, %ebx
jmp 0x8ea4b
leaq 0x7b7d2(%rip), %rcx     # 0x10a21d
leaq 0x94065(%rip), %rsi     # 0x122ab7
xorl %r13d, %r13d
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x8
popq %rsi
pushq $0x1
popq %rbp
movl $0x130, %edx            # imm = 0x130
movq %r14, %rdi
movl %ebp, %ecx
callq 0xe7437
movb $0x1, 0x38(%rax)
movq 0x18(%r14), %rdi
pushq $0x1
popq %rdx
movq %r12, %rsi
movq %rax, 0x28(%rsp)
movq %rax, %rcx
movl %ebp, %r8d
callq 0xe77b7
cmpl $0x2, 0x90(%r14)
jl 0x8eb99
testb %bl, %bl
je 0x8eb85
pushq $0x23
popq %rdx
pushq $0x1
popq %rcx
movl $0x17d, %esi            # imm = 0x17D
movq %r14, %rdi
callq 0xe7437
movq %rax, %r12
xorl %edx, %edx
cmpq $0x26, %rdx
je 0x8eba3
movq %rdx, %rax
subq $0x13, %rax
cmovbq %rdx, %rax
pushq $0x1
popq %rsi
pushq $0x12
popq %rcx
cmovaeq %rcx, %rsi
movq %rsi, 0x68(%rsp)
imulq $0x14, %rax, %rax
leaq (,%rdx,8), %rcx
movq %rcx, 0x58(%rsp)
addq $0x8, %rax
movq %rax, 0x60(%rsp)
xorl %ecx, %ecx
movq %rdx, 0x40(%rsp)
cmpq $0x10, %rcx
je 0x8eb7d
movq 0x68(%rsp), %rax
movq %rcx, 0x48(%rsp)
leaq (%rcx,%rax), %rbp
movl %ebp, %r13d
andl $0x7, %r13d
orq 0x58(%rsp), %r13
xorq $0x4, %r13
pushq $0x13
popq %rbx
movq 0x60(%rsp), %r15
subq $0x1, %rbx
jb 0x8eb6e
leaq -0x7(%r15), %r14
movl %r15d, %esi
andl $0x7, %esi
movq 0x28(%rsp), %rdi
movq %r13, %rdx
callq 0xe735f
shrl $0x10, %eax
movzbl %al, %ecx
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0xe71da
incq %r15
jmp 0x8eb38
movq 0x48(%rsp), %rcx
incq %rcx
movq 0x40(%rsp), %rdx
jmp 0x8eb0c
incq %rdx
jmp 0x8eac7
leaq 0x93f4b(%rip), %rsi     # 0x122ad7
xorl %r13d, %r13d
movq %r14, %rdi
xorl %eax, %eax
callq 0xde896
xorl %ebp, %ebp
movq %r14, %rbx
xorl %r12d, %r12d
jmp 0x8ec1f
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r13
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rsi
testq %rsi, %rsi
je 0x8ebe4
cmpb $0x0, 0xd0(%rbx)
je 0x8ebe4
movq %r13, %rdi
callq 0xead71
leaq 0x9faa5(%rip), %rsi     # 0x12e67e
pushq $0x5
popq %rdx
movq %r13, %rdi
callq 0xeae42
leaq 0x9661c(%rip), %rsi     # 0x125207
pushq $0x5
popq %rdx
movq %r13, %rdi
callq 0xeae42
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xdfd55
pushq $0x9
popq %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0xe70ab
movq %r12, %rdi
callq 0xe7084
movq 0x28(%rsp), %rdi
callq 0xe7084
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xdfd24
movq %r13, %rdi
callq 0xeaf3c
movl 0xa8(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq 0x20(%rsp), %r14
movq 0x28(%r14), %rdi
callq 0xeaf3c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
callq 0xded32
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0xded32
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq