// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movl $0x50, %esi
callq 0xe8b2b
movq %rax, %r13
leaq 0x9c30d(%rip), %rsi     # 0x12f9cc
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xe9bd0
movl %eax, (%r13)
cmpl $-0x1, %eax
je 0x936db
movb 0x4(%r13), %al
jmp 0x936e7
movq %rbx, %rdi
callq 0x94243
movb %al, 0x4(%r13)
testb %al, %al
je 0x93711
movl $0x1, (%r13)
leaq 0x9c3db(%rip), %rsi     # 0x12fad5
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
jmp 0x93848
movl (%r13), %ebp
cmpl $-0x1, %ebp
je 0x93745
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
testl %ebp, %ebp
leaq 0x9c3e1(%rip), %rax     # 0x12fb16
leaq 0x9c3bb(%rip), %rsi     # 0x12faf7
cmoveq %rax, %rsi
jmp 0x93848
leaq 0x9c293(%rip), %rsi     # 0x12f9df
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl $0x60, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r14
movq $0x0, (%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x94293
movq %rbx, %r15
movq %r14, 0x18(%rsp)
movl 0x8(%r14), %ebx
movl $0x60, %esi
movq %r15, %rdi
callq 0xe8b2b
movq %rax, %r14
movq $0x80, (%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x94293
movq %r14, 0x10(%rsp)
movl 0x8(%r14), %r14d
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
cmpl %r14d, %ebx
jle 0x937e6
leaq 0x9c23b(%rip), %rsi     # 0x12fa12
movq %r15, %rdi
xorl %eax, %eax
callq 0xe8617
movq %r15, %rbx
jmp 0x93832
jge 0x937fe
leaq 0x9c247(%rip), %rsi     # 0x12fa36
movq %r15, %rbx
movq %r15, %rdi
xorl %eax, %eax
callq 0xe8617
jmp 0x9382d
testl %ebx, %ebx
setne %al
testl %r14d, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x93819
leaq 0x9c242(%rip), %rsi     # 0x12fa59
jmp 0x93820
leaq 0x9c28f(%rip), %rsi     # 0x12faaf
movq %r15, %rbx
movq %r15, %rdi
xorl %eax, %eax
callq 0xe8faa
movl $0x1, %ebp
movl %ebp, (%r13)
cmpb $0x0, 0x4(%r13)
je 0x9372c
leaq 0x9c28d(%rip), %rsi     # 0x12fad5
movq %rbx, %rdi
callq 0xeb125
cmpl $0x0, (%r13)
je 0x93a48
movq $0x80, 0x40(%r13)
movq $0x280, 0x48(%r13)      # imm = 0x280
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeead3
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movl $0x1, %esi
callq 0xeead3
testb %bpl, %bpl
jne 0x93a58
addb $-0x40, %al
cmpb $-0x3f, %al
jb 0x93a58
leaq 0x9c552(%rip), %rsi     # 0x12fdf2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r15
leaq 0xb87d2(%rip), %rax     # 0x14c0a0
movq %rax, (%r15)
movq %rbx, %rdi
callq 0xea504
movq %rax, 0x60(%r15)
movq %rbx, %rdi
callq 0xf6410
movq 0x60(%r15), %rcx
movq %rax, 0x90(%rcx)
movq 0x18(%rbx), %rcx
movq 0x18(%rcx), %r9
leaq 0x9c0d6(%rip), %rsi     # 0x12f9d5
movq %rbx, %rdi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0xe9aa3
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movl 0x44(%r15), %eax
testq %rax, %rax
je 0x93934
movb $0x1, 0x5(%r13)
movq %rax, 0x8(%r13)
movl 0x48(%r15), %eax
movq %rax, 0x18(%r13)
movl 0x4c(%r15), %eax
testq %rax, %rax
je 0x9394e
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 0x93964
addq $0x18, %rax
movups (%rax), %xmm0
movups %xmm0, 0x30(%r13)
cmpb $0x0, 0x5(%r13)
je 0x93996
movq 0x18(%r13), %rdx
addq 0x8(%r13), %rdx
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rcx
cmpq %rcx, %rdx
jle 0x93996
leaq 0x9c25a(%rip), %rsi     # 0x12fbe1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movb $0x0, 0x5(%r13)
movq 0x60(%r15), %rax
movq 0x90(%rax), %rdi
callq 0xf67a3
testl %eax, %eax
je 0x939c5
cmpq $0x0, 0x28(%r13)
jne 0x939c5
movq 0x60(%r15), %rax
movq 0x90(%rax), %rdi
callq 0xf66ff
movq %rax, 0x28(%r13)
cmpb $0x0, 0x6(%r13)
je 0x93a2f
movq 0x20(%r13), %rcx
testq %rcx, %rcx
jle 0x93a2f
movq 0x10(%r13), %rdx
leaq (%rdx,%rcx), %rax
movq 0x18(%rbx), %rsi
cmpq 0x18(%rsi), %rax
jg 0x93a2f
leaq 0x9c231(%rip), %rsi     # 0x12fc1f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rcx
movq 0x10(%r13), %r8
movq 0x20(%r13), %r9
leaq 0x831b4(%rip), %rsi     # 0x116bcc
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe9b13
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x60(%r15), %rsi
movq %rbx, %rdi
callq 0xea50e
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe8be2
jmp 0x93a58
movq $0x0, 0x40(%r13)
movq $0x200, 0x48(%r13)      # imm = 0x200
leaq 0x3c(%rsp), %rsi
movq %rbx, %rdi
callq 0xe8a1c
cmpb $0x0, 0x4(%r13)
jne 0x93adf
movq 0x40(%r13), %rdx
leaq 0x8f908(%rip), %rsi     # 0x12337f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq 0x40(%r13), %rsi
callq 0xeed0d
movq %rax, %r15
leaq 0x80a87(%rip), %rsi     # 0x11452c
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
cmpq $0x3, %r15
ja 0x93abe
cmpq $0x1, %r15
jne 0x93ad2
leaq 0x9c178(%rip), %rsi     # 0x12fc3d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8faa
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x48(%r13), %rbp
leaq 0xa75cd(%rip), %rsi     # 0x13b0b7
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl $0xca80, %esi           # imm = 0xCA80
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf09c5
movq %rax, %r14
movq %rax, %rdi
callq 0xf0855
leaq 0x88(%rsp), %r15
leaq 0x50(%rsp), %r12
leaq 0xa8(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xfa1dc
movq 0x18(%rbx), %rax
movq %rax, (%r15)
movq %rbp, 0x8(%r15)
movq 0x18(%rax), %rax
movq %rbp, 0x20(%rsp)
subq %rbp, %rax
movq %rax, 0x10(%r15)
movq %r14, 0x30(%rsp)
movq %r14, (%r12)
movb $0x1, 0x8(%r12)
movq $0xca80, 0x10(%r12)     # imm = 0xCA80
movl $0x4, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, 0x28(%rsp)
movq 0x8(%r15), %r14
movq %r14, (%rsp)
addq 0x10(%r15), %r14
movq %r13, 0x8(%rsp)
movb $0x0, 0x7(%r13)
cmpb $0x0, 0x8(%r12)
je 0x93bb3
cmpq $0x0, 0x60(%rsp)
jle 0x93ca1
xorl %r13d, %r13d
movq %rsp, %r12
xorl %ebp, %ebp
movq (%rsp), %rax
addq $0x2, %rax
cmpq %r14, %rax
jg 0x93ca1
movq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0xeeb4b
testb %al, %al
js 0x93c16
movzbl %al, %r15d
movq (%rsp), %rsi
leaq (%rsi,%r15), %rax
incq %rax
cmpq %r14, %rax
jg 0x93c9a
incq %r15
movq 0x88(%rsp), %rdi
movq 0x50(%rsp), %rcx
movq %r15, %rdx
callq 0xef481
addq %r15, (%rsp)
jmp 0x93c48
movl %eax, %ecx
negb %cl
jo 0x93c82
movzbl %al, %eax
movl $0x101, %r15d           # imm = 0x101
subq %rax, %r15
movq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0xeeb4b
movq 0x50(%rsp), %rdi
movzbl %al, %esi
movq %r15, %rdx
callq 0xf0eba
addq %r15, %r13
addq %r15, %rbp
cmpq $0x48, %rbp
jne 0x93c58
xorl %ebp, %ebp
jmp 0x93c82
jle 0x93c82
movq 0x8(%rsp), %rax
movb $0x1, 0x7(%rax)
movq %rbp, %rax
movabsq $-0x1c71c71c71c71c71, %rcx # imm = 0xE38E38E38E38E38F
mulq %rcx
shrq $0x3, %rdx
andq $-0x8, %rdx
leaq (%rdx,%rdx,8), %rax
subq %rax, %rbp
cmpb $0x0, 0x58(%rsp)
je 0x93bbb
cmpq 0x60(%rsp), %r13
jl 0x93bbb
jmp 0x93ca1
decq %rsi
movq %rsi, (%rsp)
movq 0x50(%rsp), %rdi
callq 0xf08ba
movq (%rsp), %rax
subq 0x90(%rsp), %rax
movq %rax, 0xb0(%rsp)
movb $0x1, 0xac(%rsp)
movq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0xf08ba
movq 0xb0(%rsp), %r15
movq 0x18(%r12), %rcx
leaq 0x8d867(%rip), %rsi     # 0x12154f
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%rsp), %r14
cmpb $0x0, 0x5(%r14)
je 0x93d27
addq 0x20(%rsp), %r15
movq 0x18(%r14), %rcx
addq 0x8(%r14), %rcx
cmpq %rcx, %r15
jle 0x93d27
leaq 0x9bf43(%rip), %rsi     # 0x12fc5d
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8faa
movq 0x18(%r12), %rdx
cmpq $0xca7f, %rdx           # imm = 0xCA7F
jg 0x93d4d
leaq 0x9bf6a(%rip), %rsi     # 0x12fca6
movq %rbx, %rdi
movl $0xca80, %ecx           # imm = 0xCA80
xorl %eax, %eax
callq 0xe8faa
jmp 0x93d65
cmpb $0x0, 0x7(%r14)
je 0x93d65
leaq 0x9bf79(%rip), %rsi     # 0x12fcd4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movq %rbx, %rdi
callq 0xea504
movq %rax, %r15
movq 0x28(%r14), %rdx
testq %rdx, %rdx
je 0x93d8f
cmpb $0x0, 0xd0(%rbx)
je 0x93d8f
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0xea53f
cmpb $0x0, 0x30(%r14)
je 0x93da5
movq %r14, %rax
addq $0x30, %rax
movups (%rax), %xmm0
movups %xmm0, 0x68(%r15)
movl $0x240, %edx            # imm = 0x240
movl $0x2d0, %ecx            # imm = 0x2D0
movl $0x48, %r8d
movq %r12, %rdi
xorl %esi, %esi
movl $0x1, %r9d
pushq $0x0
pushq %r15
callq 0xf2a98
addq $0x10, %rsp
movq %r12, %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea50e
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0xe8be2
movl 0x3c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
cmpb $0x0, 0x4(%r14)
jne 0x94123
leaq 0xa8(%rsp), %rsi
movq %rbx, %rdi
callq 0xe8a1c
leaq 0x9befb(%rip), %rsi     # 0x12fd16
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x40(%r14), %r13
addq $0x4, %r13
leaq 0x9bee8(%rip), %rsi     # 0x12fd29
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
movl $0x10, %esi
callq 0xeb499
movq %rax, %r15
movq 0x18(%rbx), %rsi
movl $0x130, %ecx            # imm = 0x130
movq %rax, %rdi
movq %r13, %rdx
callq 0xeb944
movq %r15, %rdi
callq 0xeb865
movl %eax, %ebp
movq %r15, %rdi
callq 0xeb858
movb $0x1, %r14b
cmpl $0x33d2d8d5, %ebp       # imm = 0x33D2D8D5
jg 0x93eb5
cmpl $0xb5348fd2, %ebp       # imm = 0xB5348FD2
je 0x93ed7
cmpl $0x284a7a15, %ebp       # imm = 0x284A7A15
jne 0x93ece
leaq 0x9bee1(%rip), %rcx     # 0x12fd94
jmp 0x93eea
cmpl $0x47514647, %ebp       # imm = 0x47514647
je 0x93ee0
cmpl $0x33d2d8d6, %ebp       # imm = 0x33D2D8D6
jne 0x93ece
leaq 0xa1115(%rip), %rcx     # 0x134fe1
jmp 0x93eea
leaq 0x833d8(%rip), %rcx     # 0x1172ad
jmp 0x93eea
leaq 0x9beb0(%rip), %rcx     # 0x12fd8e
jmp 0x93ee7
leaq 0x9bea1(%rip), %rcx     # 0x12fd88
xorl %r14d, %r14d
leaq 0x9be4e(%rip), %rsi     # 0x12fd3f
xorl %r12d, %r12d
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movl $0x8, %esi
movl $0x130, %edx            # imm = 0x130
movq %rbx, %rdi
movl $0x1, %ecx
callq 0xf266a
movq %rax, %r15
movb $0x1, 0x38(%rax)
movq 0x18(%rbx), %rdi
movl $0x1, %edx
movq %r13, %rsi
movq %rax, %rcx
movl $0x1, %r8d
callq 0xf2a40
cmpl $0x2, 0x90(%rbx)
jl 0x940e7
testb %r14b, %r14b
je 0x940d3
movq %r15, 0x48(%rsp)
movl $0x17d, %esi            # imm = 0x17D
movl $0x23, %edx
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
movl $0x1, %ecx
callq 0xf266a
movq %rax, 0x40(%rsp)
xorl %ecx, %ecx
movq 0x48(%rsp), %r13
movq 0x40(%rsp), %r12
movq %rcx, %rax
subq $0x13, %rax
cmovbq %rcx, %rax
movl $0x1, %esi
movl $0x12, %edx
cmovaeq %rdx, %rsi
movq %rsi, 0x20(%rsp)
leaq (%rax,%rax,4), %rax
movq %rcx, 0x70(%rsp)
leaq (,%rcx,8), %rcx
movq %rcx, 0x80(%rsp)
leaq 0x8(,%rax,4), %rax
movq %rax, 0x78(%rsp)
xorl %ecx, %ecx
movq 0x20(%rsp), %rax
movq %rcx, 0x28(%rsp)
leaq (%rcx,%rax), %rbp
movq %rbp, 0x30(%rsp)
andl $0x7, %ebp
orq 0x80(%rsp), %rbp
xorq $0x4, %rbp
movl $0x13, %ebx
movq 0x78(%rsp), %r15
leaq -0x7(%r15), %r14
movl %r15d, %esi
andl $0x7, %esi
movq %r13, %rdi
movq %rbp, %rdx
callq 0xf2592
shrl $0x10, %eax
movzbl %al, %ecx
movq %r12, %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
callq 0xf2405
incq %r15
decq %rbx
jne 0x93ff2
movq 0x28(%rsp), %rcx
incq %rcx
cmpq $0x10, %rcx
jne 0x93fc6
movq 0x70(%rsp), %rcx
incq %rcx
cmpq $0x26, %rcx
jne 0x93f80
movq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r12
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rsi
testq %rsi, %rsi
je 0x94088
cmpb $0x0, 0xd0(%rbx)
je 0x94088
movq %r12, %rdi
callq 0xf6509
leaq 0xa78f3(%rip), %rsi     # 0x13b96e
movq %r12, %rdi
movl $0x5, %edx
callq 0xf65e3
leaq 0x9e464(%rip), %rsi     # 0x1324f3
movq %r12, %rdi
movl $0x5, %edx
callq 0xf65e3
movq %rbx, %rdi
callq 0xea504
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xea53f
movq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
movl $0x9, %edx
callq 0xf22d0
movq 0x48(%rsp), %r15
jmp 0x940ec
leaq 0x9bc85(%rip), %rsi     # 0x12fd5f
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
xorl %ebp, %ebp
xorl %r14d, %r14d
movq %r14, %rdi
callq 0xf228d
movq %r15, %rdi
callq 0xf228d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xea50e
movq %r12, %rdi
callq 0xf6753
movl 0xa8(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq 0x8(%rsp), %r14
movq 0x28(%r14), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0xe8be2
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xe8be2
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq