// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/pcpaint.c
// Function: de_run_pcpaint
static void de_run_pcpaint(deark *c, de_module_params *mparams)
{
	// 0=unknown, 1=pic, 2=clp
	const char *pcpaintfmt;
	u8 buf[16];
	lctx *d;

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

	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437_G);

	pcpaintfmt = de_get_ext_option(c, "pcpaint:fmt");
	if(pcpaintfmt) {
		if(!de_strcmp(pcpaintfmt, "pic")) {
			d->file_fmt = FMT_PIC;
		}
		else if(!de_strcmp(pcpaintfmt, "clp")) {
			d->file_fmt = FMT_CLP;
		}
		else if(!de_strcmp(pcpaintfmt, "clip")) {
			d->file_fmt = FMT_CLP;
		}
	}

	if(!d->file_fmt) {
		// File subtype not given by user. Try to detect it.
		de_read(buf, 0, 16);
		if(buf[0]==0x34 && buf[1]==0x12) {
			if(c->infile->len==0x1234) {
				// Pathological case where both formats could start with 0x1234.
				if(buf[10]==0xff) { // definitely a compressed CLP
					d->file_fmt = FMT_CLP;
				}
				else {
					de_warn(c, "Format can't be reliably identified. Try \"-opt pcpaint:fmt=clp\" if necessary.");
					d->file_fmt = FMT_PIC;
				}
			}
			else {
				d->file_fmt = FMT_PIC;
			}
		}
		else {
			d->file_fmt = FMT_CLP;
		}
	}

	d->opt_keep_invis_chars = de_get_ext_option_bool(c, "pcpaint:invistext", 0);

	if(d->file_fmt==FMT_CLP) {
		de_run_pcpaint_clp(c, d, mparams);
	}
	else {
		de_run_pcpaint_pic(c, d, mparams);
	}

	destroy_lctx(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movl $0x4a0, %esi            # imm = 0x4A0
callq 0xdecaf
movq %rax, %r14
pushq $0xd
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x8(%r14)
leaq 0x806b2(%rip), %rsi     # 0x1288fd
movq %rbx, %rdi
callq 0xdfa87
pushq $0x2
popq %rbp
pushq $0x1
popq %r12
testq %rax, %rax
je 0xa829b
movq %rax, %r15
leaq 0x80c1c(%rip), %rsi     # 0x128e85
movq %rax, %rdi
callq 0x181a0
testl %eax, %eax
je 0xa82ea
leaq 0x6deb0(%rip), %rsi     # 0x11612c
movq %r15, %rdi
callq 0x181a0
testl %eax, %eax
je 0xa82ed
leaq 0x8067a(%rip), %rsi     # 0x128909
movq %r15, %rdi
callq 0x181a0
testl %eax, %eax
je 0xa82ed
cmpl $0x0, (%r14)
jne 0xa82f0
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r15
pushq $0x10
popq %rcx
movq %r15, %rsi
xorl %edx, %edx
callq 0xe3cb7
cmpb $0x34, (%r15)
jne 0xa82ed
cmpb $0x12, 0x11(%rsp)
jne 0xa82ed
movq 0x18(%rbx), %rax
cmpq $0x1234, 0x18(%rax)     # imm = 0x1234
jne 0xa82ea
cmpb $-0x1, 0x1a(%rsp)
je 0xa82ed
leaq 0x8062e(%rip), %rsi     # 0x12890e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
movl %r12d, %ebp
movl %ebp, (%r14)
leaq 0x80665(%rip), %rsi     # 0x12895c
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
movl %eax, 0xc(%r14)
cmpl $0x2, (%r14)
jne 0xa839f
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xdebae
leaq 0x8064b(%rip), %rsi     # 0x12896e
movq %rbx, %rdi
callq 0xe07f7
leaq 0x840bc(%rip), %rsi     # 0x12c3ee
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe3fa3
movq %rax, %r15
leaq 0x663ab(%rip), %rsi     # 0x10e709
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rcx
cmpq %rcx, %r15
je 0xa873a
cmpq $0x1234, %r15           # imm = 0x1234
jne 0xa8726
leaq 0x805ea(%rip), %rsi     # 0x12897a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
jmp 0xa873a
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0xdebae
leaq 0x8094b(%rip), %rsi     # 0x128cfe
movq %rbx, %rdi
callq 0xe07f7
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, 0x10(%r14)
leaq 0x84020(%rip), %rsi     # 0x12c3ee
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x18(%rbx), %rdi
pushq $0x2
popq %rsi
callq 0xe3fa3
movq %rax, 0x20(%r14)
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rsi
callq 0xe3fa3
movq %rax, 0x28(%r14)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xdf038
movq 0x18(%rbx), %rdi
pushq $0xa
popq %rsi
callq 0xe3eb4
movb %al, 0x38(%r14)
movq 0x18(%rbx), %rdi
pushq $0xb
popq %rsi
callq 0xe3eb4
movb %al, 0x39(%r14)
movzbl 0x38(%r14), %edx
leaq 0x805be(%rip), %rsi     # 0x128a04
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movzbl 0x39(%r14), %edx
leaq 0x808ae(%rip), %rsi     # 0x128d0a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movzbl 0x39(%r14), %eax
cmpl $0xff, %eax
je 0xa847f
testl %eax, %eax
jne 0xa8486
cmpb $0x1, 0x38(%r14)
je 0xa8482
jmp 0xa8486
pushq $0x2
popq %rbp
movl %ebp, 0x4(%r14)
movl 0x4(%r14), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0xa84cd
cmpl $0x2, %eax
je 0xa84e3
leaq 0x808ae(%rip), %rsi     # 0x128d4c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
cmpl $0x1, 0x4(%r14)
jne 0xa84e3
movb $0x0, 0x3a(%r14)
movq %r14, %r15
addq $0x48, %r15
andl $0x0, 0x48(%r14)
movq $0xa, 0x50(%r14)
jmp 0xa854e
leaq 0x8084b(%rip), %rsi     # 0x128d1f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0xa894b
movq 0x18(%rbx), %rdi
pushq $0xc
popq %rsi
callq 0xe3eb4
movb %al, 0x3a(%r14)
movzbl %al, %edx
leaq 0x8088c(%rip), %rsi     # 0x128d89
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rsi
movq %r14, %r15
addq $0x48, %r15
movq %rbx, %rdi
movq %r15, %rdx
callq 0xa8efe
movl 0x48(%r14), %edx
leaq 0x80874(%rip), %rsi     # 0x128d9c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x50(%r14), %edx
leaq 0x64e96(%rip), %rsi     # 0x10d3d3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpq $0x0, 0x50(%r14)
jle 0xa8562
leaq 0x80851(%rip), %rsi     # 0x128da6
pushq $0x11
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xa85bd
cmpl $0x2, 0x4(%r14)
jl 0xa85bd
movb 0x3a(%r14), %cl
addb $-0x41, %cl
cmpb $0x11, %cl
ja 0xa85bd
movzbl %cl, %ecx
movl $0x22fff, %edx          # imm = 0x22FFF
btl %ecx, %edx
jae 0xa85bd
shll $0x3, %ecx
leaq 0x80203(%rip), %rdx     # 0x128798
movsd (%rcx,%rdx), %xmm0
leaq 0x80287(%rip), %rdx     # 0x128828
movsd (%rcx,%rdx), %xmm1
movl $0x1, 0x78(%rax)
movsd %xmm0, 0x80(%rax)
movsd %xmm1, 0x88(%rax)
movq %r15, 0x78(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa8c1c
testl %eax, %eax
je 0xa894b
movq 0x18(%rbx), %rdi
movq 0x50(%r14), %rsi
addq $0x11, %rsi
callq 0xe3fa3
movq %rax, 0x80(%r14)
movq 0x50(%r14), %rcx
addq $0x13, %rcx
movq %rcx, 0x18(%r14)
leaq 0x807c3(%rip), %rsi     # 0x128dc2
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movl 0x18(%r14), %edx
leaq 0x6a8d4(%rip), %rsi     # 0x112ef5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa8cf3
testl %eax, %eax
je 0xa894b
cmpl $0x1, 0x98(%r14)
jne 0xa866b
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
movq %rbx, %rdi
callq 0xe6be1
testl %eax, %eax
je 0xa894b
cmpq $0x0, 0x80(%r14)
jle 0xa8923
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xdebae
cmpq $0x0, 0x80(%r14)
jle 0xa8715
movl $0x4000, %esi           # imm = 0x4000
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe59cd
movq %rax, 0x88(%r14)
movq 0x30(%r14), %rsi
addq $0x7, %rsi
imulq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0xe5a74
leaq 0x80364(%rip), %rsi     # 0x128a2a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%r14), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa9991
testl %eax, %eax
je 0xa8715
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x88(%r14), %rax
movq 0x18(%rax), %rdx
leaq 0x5e15b(%rip), %rsi     # 0x106866
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x8(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
jmp 0xa893e
leaq 0x8027c(%rip), %rsi     # 0x1289a9
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xdf05a
movq 0x18(%rbx), %rdi
pushq $0x2
popq %rsi
callq 0xe3fa3
movq %rax, 0x20(%r14)
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rsi
callq 0xe3fa3
movq %rax, 0x28(%r14)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xdf038
movq 0x18(%rbx), %rdi
pushq $0xa
popq %rsi
callq 0xe3eb4
movl %eax, %ebp
movb %al, 0x38(%r14)
xorl %r15d, %r15d
cmpb $-0x1, %al
sete %r15b
je 0xa8794
movq $0xb, 0x18(%r14)
jmp 0xa87ac
movq $0xd, 0x18(%r14)
movq 0x18(%rbx), %rdi
pushq $0xb
popq %rsi
callq 0xe3eb4
movb %al, 0x38(%r14)
leaq 0x82719(%rip), %rsi     # 0x12aecc
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
movzbl 0x38(%r14), %edx
leaq 0x80238(%rip), %rsi     # 0x128a04
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movb $0x0, 0x3a(%r14)
movq %r14, %rax
addq $0x48, %rax
andl $0x0, 0x48(%r14)
andq $0x0, 0x50(%r14)
movq %rax, 0x78(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa8c1c
testl %eax, %eax
je 0xa891d
movq 0x18(%r14), %rdx
leaq 0x855ae(%rip), %rsi     # 0x12ddc7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa8cf3
testl %eax, %eax
je 0xa891d
movq 0x18(%rbx), %rdi
cmpb $-0x1, %bpl
je 0xa8867
movq 0x18(%r14), %rsi
movq 0x18(%rdi), %rdx
subq %rsi, %rdx
callq 0xe6248
movq %rax, 0x88(%r14)
jmp 0xa8910
pushq $0xc
popq %rsi
callq 0xe3eb4
movzbl %al, %ebp
leaq 0x8019e(%rip), %rsi     # 0x128a17
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xdea83
leaq 0x8019e(%rip), %rsi     # 0x128a2a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movl $0x4000, %esi           # imm = 0x4000
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe59cd
movq %rax, 0x88(%r14)
movq 0x30(%r14), %rsi
addq $0x7, %rsi
imulq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0xe5a74
movq 0x18(%r14), %rdx
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rcx
subq %rdx, %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %r8d
callq 0xa8e4d
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x88(%r14), %rax
movq 0x18(%rax), %rdx
leaq 0x5df60(%rip), %rsi     # 0x106866
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq %r14, %rsi
callq *0x90(%r14)
movl 0x8(%rsp), %esi
jmp 0xa894f
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
movq 0x18(%rdi), %rdx
subq %rsi, %rdx
callq 0xe6248
movq %rax, 0x88(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq *0x90(%r14)
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa8bc5
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq