// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r12
movq 0x18(%rbp), %rdi
xorl %esi, %esi
callq 0xef0d5
xorl %edx, %edx
cmpb $0x4c, %al
sete %dl
incl %edx
movl %edx, (%r12)
leaq 0x98980(%rip), %rsi     # 0x1343d1
movq %rbp, %rdi
xorl %eax, %eax
callq 0xe9226
movl (%r12), %edx
leaq 0x957f7(%rip), %rsi     # 0x13125d
movq %rbp, %rdi
xorl %eax, %eax
callq 0xeb703
movq 0x18(%rbp), %rdi
movl $0x4, %esi
callq 0xef1ca
movq %rax, 0x8(%r12)
movq 0x18(%rbp), %rdi
movl $0x6, %esi
callq 0xef1ca
movq %rax, 0x10(%r12)
movq 0x8(%r12), %rsi
movq %rbp, %rdi
movq %rax, %rdx
callq 0xe9b05
cmpl $0x1, (%r12)
jne 0x9bae8
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
movq 0x18(%rbp), %rdi
movl $0x20, %esi
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
callq 0xf30d9
addq $0x10, %rsp
jmp 0x9bd74
movq 0x10(%r12), %rsi
movl $0x8, %edx
movq %rbp, %rdi
callq 0xea259
movq %rax, 0x10(%rsp)
movq 0x10(%r12), %rsi
movl $0x8, %edx
movq %rbp, %rdi
callq 0xea259
movq %rax, %r15
cmpq $0x0, 0x10(%r12)
jle 0x9bb3e
xorl %r14d, %r14d
movq 0x18(%rbp), %rdi
leaq 0x20(,%r14,2), %rsi
callq 0xef1ca
movq %rax, (%r15,%r14,8)
incq %r14
cmpq 0x10(%r12), %r14
jl 0x9bb1f
movq %r15, 0x8(%rsp)
movq 0x10(%r12), %rdx
testq %rdx, %rdx
jle 0x9bbad
leaq 0x95716(%rip), %r15     # 0x13126a
xorl %r13d, %r13d
movq 0x10(%rsp), %r14
testq %r13, %r13
je 0x9bb76
movq 0x8(%rsp), %rdx
movq -0x8(%rdx,%r13,8), %rax
addq -0x8(%r14,%r13,8), %rax
movq %rax, (%r14,%r13,8)
jmp 0x9bb86
leaq 0x20(,%rdx,2), %rax
movq %rax, (%r14)
movq 0x8(%rsp), %rdx
movl (%r14,%r13,8), %ecx
movl (%rdx,%r13,8), %r8d
movq %rbp, %rdi
movq %r15, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe93cf
incq %r13
movq 0x10(%r12), %rdx
cmpq %rdx, %r13
jl 0x9bb5c
jmp 0x9bbb2
movq 0x10(%rsp), %r14
movq 0x8(%r12), %rsi
movq %rbp, %rdi
movl $0x1, %ecx
callq 0xf2cab
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x10(%r12)
jle 0x9bd30
xorl %r15d, %r15d
movq %rbp, 0x30(%rsp)
movq (%r14,%r15,8), %r13
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rbx
movq %rbp, %rdi
leaq 0x9568f(%rip), %rsi     # 0x131283
movq %r15, 0x20(%rsp)
movl %r15d, %edx
xorl %eax, %eax
callq 0xe93cf
cmpq $0x0, 0x18(%r12)
jne 0x9bc35
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 0xf0faf
movq %rax, 0x18(%r12)
movq %r12, %r15
movq 0x18(%r12), %rdi
callq 0xf1a5f
testq %rbx, %rbx
jle 0x9bcff
leaq 0x2(%r13), %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movq 0x18(%rbp), %rdi
leaq (%r14,%r13), %rsi
callq 0xef0d5
leaq 0x1(%r14), %r12
testb %al, %al
je 0x9bca1
movq %rbp, %r14
movzbl %al, %ebp
movq %r14, %rdi
leaq 0x95637(%rip), %rsi     # 0x1312b3
movl %ebp, %edx
xorl %eax, %eax
callq 0xe93cf
movq 0x18(%r14), %rdi
leaq (%r12,%r13), %rsi
movq 0x18(%r15), %rcx
movq %rbp, %rdx
callq 0xefabc
addq %rbp, %r12
movq %r12, %r14
jmp 0x9bcf1
movq 0x18(%rbp), %rdi
addq %r13, %r12
movq %r12, %rsi
callq 0xef0d5
movzbl %al, %r12d
movq 0x18(%rbp), %rdi
movq 0x28(%rsp), %rax
leaq (%rax,%r14), %rsi
callq 0xef0d5
addq $0x3, %r14
movq %rbp, %rdi
movzbl %al, %ebp
leaq 0x955c1(%rip), %rsi     # 0x131298
movl %r12d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe93cf
movq 0x18(%r15), %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0xf14bd
cmpq %rbx, %r14
movq 0x30(%rsp), %rbp
jl 0x9bc57
movq %r15, %r12
movq 0x18(%r15), %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %r15
movq %r15, %rcx
xorl %r8d, %r8d
callq 0xf3069
incq %r15
cmpq 0x10(%r12), %r15
movq 0x10(%rsp), %r14
jl 0x9bbdd
movq 0x18(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf2923
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
callq 0xe9752
movq %rbp, %rdi
movq %r14, %rsi
callq 0xe9752
movq 0x18(%r12), %rdi
callq 0xf0b13
movq $0x0, 0x18(%r12)
movq %r15, %rdi
callq 0xf28d4
movq %rbp, %rdi
movq %r12, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9752