// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rdi, %rbx
pushq $0x20
popq %r15
movq %r15, %rsi
callq 0xdecaf
movq %rax, %r13
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe3eb4
xorl %edx, %edx
cmpb $0x4c, %al
sete %dl
incl %edx
movl %edx, (%r13)
leaq 0x91d42(%rip), %rsi     # 0x1274f1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl (%r13), %edx
leaq 0x8eb06(%rip), %rsi     # 0x1242ca
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe0824
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rsi
callq 0xe3fa3
movq %rax, 0x8(%r13)
movq 0x18(%rbx), %rdi
pushq $0x6
popq %rsi
callq 0xe3fa3
movq %rax, 0x10(%r13)
movq 0x8(%r13), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xdf038
cmpl $0x1, (%r13)
jne 0x9583c
movq 0x8(%r13), %r8
movq 0x10(%r13), %rcx
leaq 0x7(%r8), %rax
pushq $0x8
popq %rsi
cqto
idivq %rsi
movq 0x18(%rbx), %rdi
andl $0x0, 0x8(%rsp)
andq $0x0, (%rsp)
pushq $0x20
popq %rsi
movq %r8, %rdx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xe7804
jmp 0x95a8b
movq 0x10(%r13), %rsi
pushq $0x8
popq %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0xdf66f
movq %rax, %rbp
movq 0x10(%r13), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0xdf66f
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movq 0x10(%r13), %rdx
cmpq %rdx, %r14
jge 0x95891
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fa3
movq 0x18(%rsp), %rcx
movq %rax, -0x80(%rcx,%r15,4)
incq %r14
addq $0x2, %r15
jmp 0x95869
leaq 0x8ea3f(%rip), %r15     # 0x1242d7
xorl %r12d, %r12d
movq 0x18(%rsp), %r14
cmpq %rdx, %r12
jge 0x958e4
testq %r12, %r12
je 0x958bb
movq -0x8(%r14,%r12,8), %rcx
addq -0x8(%rbp,%r12,8), %rcx
movq %rcx, (%rbp,%r12,8)
jmp 0x958c7
leaq 0x20(,%rdx,2), %rcx
movq %rcx, (%rbp)
movl (%r14,%r12,8), %r8d
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde9f1
incq %r12
movq 0x10(%r13), %rdx
jmp 0x958a0
movq 0x8(%r13), %rsi
pushq $0x1
popq %rcx
movq %rbx, %rdi
callq 0xe7437
movq %rax, 0x20(%rsp)
xorl %edx, %edx
movq %rbp, 0x28(%rsp)
cmpq 0x10(%r13), %rdx
jge 0x95a4e
movq (%rbp,%rdx,8), %r15
movq (%r14,%rdx,8), %rax
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
leaq 0x8e9cf(%rip), %rsi     # 0x1242f0
movq %rdx, 0x30(%rsp)
xorl %eax, %eax
callq 0xde9f1
movq 0x18(%r13), %rdi
testq %rdi, %rdi
jne 0x9595b
movq 0x8(%r13), %rax
addq $0x7, %rax
cqto
pushq $0x8
popq %rcx
idivq %rcx
movq %rbx, %rdi
movq %rax, %rsi
pushq $0x1
popq %rdx
callq 0xe59cd
movq %rax, %rdi
movq %rax, 0x18(%r13)
movq %r13, %rbp
callq 0xe62cf
leaq 0x2(%r15), %rax
movq %rax, 0x38(%rsp)
xorl %r14d, %r14d
cmpq 0x40(%rsp), %r14
jge 0x95a1b
movq 0x18(%rbx), %rdi
leaq (%r14,%r15), %rsi
callq 0xe3eb4
leaq 0x1(%r14), %r13
testb %al, %al
je 0x959c3
movzbl %al, %r12d
movq %rbx, %rdi
leaq 0x8e983(%rip), %rsi     # 0x124320
movl %r12d, %edx
xorl %eax, %eax
callq 0xde9f1
movq 0x18(%rbx), %rdi
leaq (%r15,%r13), %rsi
movq 0x18(%rbp), %rcx
movq %r12, %rdx
callq 0xe45f4
addq %r12, %r13
movq %r13, %r14
jmp 0x9596f
movq 0x18(%rbx), %rdi
addq %r15, %r13
movq %r13, %rsi
callq 0xe3eb4
movzbl %al, %r13d
movq 0x18(%rbx), %rdi
movq 0x38(%rsp), %rax
leaq (%rax,%r14), %rsi
callq 0xe3eb4
addq $0x3, %r14
movzbl %al, %r12d
movq %rbx, %rdi
leaq 0x8e90b(%rip), %rsi     # 0x124305
movl %r13d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xde9f1
movq 0x18(%rbp), %rdi
movl %r12d, %esi
movq %r13, %rdx
callq 0xe5e40
jmp 0x9596f
movq %rbp, %r13
movq 0x18(%rbp), %rdi
xorl %esi, %esi
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %r14
movq %r14, %rcx
xorl %r8d, %r8d
callq 0xe779f
movq %r14, %rdx
incq %rdx
movq 0x28(%rsp), %rbp
movq 0x18(%rsp), %r14
jmp 0x958ff
movq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe70b7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xded32
movq 0x18(%r13), %rdi
callq 0xe5591
andq $0x0, 0x18(%r13)
movq %r15, %rdi
callq 0xe7084
movq %rbx, %rdi
movq %r13, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xded32