// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/msp.c
// Function: de_run_msp
static void de_run_msp(deark *c, de_module_params *mparams)
{
	lctx *d;

	d = de_malloc(c, sizeof(lctx));

	d->ver = de_getbyte(0) == 0x4c ? 2 : 1;
	de_dbg(c, "version: %d", d->ver);
	de_declare_fmtf(c, "MS Paint v%d", d->ver);

	d->width = de_getu16le(4);
	d->height = de_getu16le(6);
	de_dbg_dimensions(c, d->width, d->height);

	if(d->ver==1) {
		do_ver1(c, d);
	}
	else {
		do_ver2(c, d);
	}

	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbp
movl $0x20, %esi
callq 0xe8b2b
movq %rax, %r12
movq 0x18(%rbp), %rdi
xorl %esi, %esi
callq 0xeead3
xorl %edx, %edx
cmpb $0x4c, %al
sete %dl
incl %edx
movl %edx, (%r12)
leaq 0x996e4(%rip), %rsi     # 0x1347c9
movq %rbp, %rdi
xorl %eax, %eax
callq 0xe8617
movl (%r12), %edx
leaq 0x964c0(%rip), %rsi     # 0x1315ba
movq %rbp, %rdi
xorl %eax, %eax
callq 0xeb152
movq 0x18(%rbp), %rdi
movl $0x4, %esi
callq 0xeebc8
movq %rax, 0x8(%r12)
movq 0x18(%rbp), %rdi
movl $0x6, %esi
callq 0xeebc8
movq %rax, 0x10(%r12)
movq 0x8(%r12), %rsi
movq %rbp, %rdi
movq %rax, %rdx
callq 0xe8f88
cmpl $0x1, (%r12)
jne 0x9b17c
movq 0x18(%rbp), %rdi
movq 0x8(%r12), %rdx
movq 0x10(%r12), %rcx
leaq 0x7(%rdx), %rax
leaq 0xe(%rdx), %r8
testq %rax, %rax
cmovnsq %rax, %r8
sarq $0x3, %r8
movl $0x20, %esi
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
callq 0xf2a98
addq $0x10, %rsp
jmp 0x9b401
movq 0x10(%r12), %rsi
movl $0x8, %edx
movq %rbp, %rdi
callq 0xe96f7
movq %rax, 0x8(%rsp)
movq 0x10(%r12), %rsi
movl $0x8, %edx
movq %rbp, %rdi
callq 0xe96f7
movq %rax, %r14
movq 0x10(%r12), %rdx
testq %rdx, %rdx
jle 0x9b23b
movq %r14, %r15
xorl %r14d, %r14d
movq 0x18(%rbp), %rdi
leaq 0x20(,%r14,2), %rsi
callq 0xeebc8
movq %rax, (%r15,%r14,8)
incq %r14
movq 0x10(%r12), %rdx
cmpq %rdx, %r14
jl 0x9b1bc
movq %r15, %r14
testq %rdx, %rdx
jle 0x9b23b
leaq 0x963da(%rip), %r15     # 0x1315c7
xorl %r13d, %r13d
testq %r13, %r13
je 0x9b20a
movq -0x8(%r14,%r13,8), %rcx
movq 0x8(%rsp), %rax
addq -0x8(%rax,%r13,8), %rcx
movq %rcx, (%rax,%r13,8)
jmp 0x9b21a
leaq 0x20(,%rdx,2), %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movl (%r14,%r13,8), %r8d
movq %rbp, %rdi
movq %r15, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe87e4
incq %r13
movq 0x10(%r12), %rdx
cmpq %rdx, %r13
jl 0x9b1f0
movq 0x8(%r12), %rsi
movq %rbp, %rdi
movl $0x1, %ecx
callq 0xf266a
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%r12)
jle 0x9b3bd
xorl %r15d, %r15d
movq %rbp, 0x30(%rsp)
movq %r14, 0x18(%rsp)
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %r13
movq (%r14,%r15,8), %rbx
movq %rbp, %rdi
leaq 0x9635e(%rip), %rsi     # 0x1315e0
movq %r15, 0x20(%rsp)
movl %r15d, %edx
xorl %eax, %eax
callq 0xe87e4
movq 0x18(%r12), %rdi
testq %rdi, %rdi
jne 0x9b2c8
movq 0x8(%r12), %rsi
leaq 0x7(%rsi), %rax
addq $0xe, %rsi
testq %rax, %rax
cmovnsq %rax, %rsi
sarq $0x3, %rsi
movq %rbp, %rdi
movl $0x1, %edx
callq 0xf09c5
movq %rax, %rdi
movq %rax, 0x18(%r12)
movq %r12, %r14
callq 0xf145f
testq %rbx, %rbx
jle 0x9b38d
leaq 0x2(%r13), %rax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
movq 0x18(%rbp), %rdi
leaq (%r15,%r13), %rsi
callq 0xeead3
leaq 0x1(%r15), %r12
testb %al, %al
je 0x9b32f
movq %rbp, %r15
movzbl %al, %ebp
movq %r15, %rdi
leaq 0x96306(%rip), %rsi     # 0x131610
movl %ebp, %edx
xorl %eax, %eax
callq 0xe87e4
movq 0x18(%r15), %rdi
leaq (%r12,%r13), %rsi
movq 0x18(%r14), %rcx
movq %rbp, %rdx
callq 0xef481
addq %rbp, %r12
movq %r12, %r15
jmp 0x9b37f
movq 0x18(%rbp), %rdi
addq %r13, %r12
movq %r12, %rsi
callq 0xeead3
movzbl %al, %r12d
movq 0x18(%rbp), %rdi
movq 0x28(%rsp), %rax
leaq (%rax,%r15), %rsi
callq 0xeead3
addq $0x3, %r15
movq %rbp, %rdi
movzbl %al, %ebp
leaq 0x96290(%rip), %rsi     # 0x1315f5
movl %r12d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe87e4
movq 0x18(%r14), %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0xf0eba
cmpq %rbx, %r15
movq 0x30(%rsp), %rbp
jl 0x9b2e5
movq %r14, %r12
movq 0x18(%r14), %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %r15
movq %r15, %rcx
xorl %r8d, %r8d
callq 0xf2a28
incq %r15
cmpq 0x10(%r14), %r15
movq 0x18(%rsp), %r14
jl 0x9b26b
movq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf22dc
movq %rbp, %rdi
movq %r14, %rsi
callq 0xe8be2
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
callq 0xe8be2
movq 0x18(%r12), %rdi
callq 0xf052b
movq $0x0, 0x18(%r12)
movq %r15, %rdi
callq 0xf228d
movq %rbp, %rdi
movq %r12, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8be2