// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r15
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, 0x8(%r15)
leaq 0x86069(%rip), %rsi     # 0x135855
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0xaf844
movq %rax, %r12
leaq 0x865da(%rip), %rsi     # 0x135ddd
movq %rax, %rdi
callq 0x181a0
testl %eax, %eax
je 0xaf83c
leaq 0x738f6(%rip), %rsi     # 0x12310c
movq %r12, %rdi
callq 0x181a0
movl $0x2, %ebp
testl %eax, %eax
je 0xaf841
leaq 0x86033(%rip), %rsi     # 0x135861
movq %r12, %rdi
callq 0x181a0
testl %eax, %eax
jne 0xaf844
jmp 0xaf841
movl $0x1, %ebp
movl %ebp, (%r14)
cmpl $0x0, (%r14)
jne 0xaf8a3
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r12
movl $0x10, %ecx
movq %r12, %rsi
xorl %edx, %edx
callq 0xeeee8
cmpb $0x34, (%r12)
movl $0x2, %eax
jne 0xaf8a0
cmpb $0x12, 0x11(%rsp)
jne 0xaf8a0
movq 0x18(%rbx), %rcx
cmpq $0x1234, 0x18(%rcx)     # imm = 0x1234
jne 0xaf89b
cmpb $-0x1, 0x1a(%rsp)
je 0xaf8a0
leaq 0x85fd5(%rip), %rsi     # 0x135866
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movl $0x1, %eax
movl %eax, (%r14)
leaq 0x8600a(%rip), %rsi     # 0x1358b4
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
movl %eax, 0xc(%r14)
cmpl $0x2, (%r14)
jne 0xaf954
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xe958c
leaq 0x85ff0(%rip), %rsi     # 0x1358c6
movq %rbx, %rdi
callq 0xeb6d6
leaq 0x89a79(%rip), %rsi     # 0x13935e
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef1ca
movq %rax, %r12
leaq 0x6bdbe(%rip), %rsi     # 0x11b6d1
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rcx
cmpq %rcx, %r12
je 0xafabb
cmpq $0x1234, %r12           # imm = 0x1234
jne 0xafaa7
leaq 0x85f8d(%rip), %rsi     # 0x1358d2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
jmp 0xafabb
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0xe958c
leaq 0x862ee(%rip), %rsi     # 0x135c56
movq %rbx, %rdi
callq 0xeb6d6
movq %rbx, %rdi
callq 0xea9a9
movq %rax, 0x10(%r14)
leaq 0x899db(%rip), %rsi     # 0x13935e
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xef1ca
movq %rax, 0x20(%r14)
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef1ca
movq %rax, 0x28(%r14)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xe9b05
movq 0x18(%rbx), %rdi
movl $0xa, %esi
callq 0xef0d5
movb %al, 0x38(%r14)
movq 0x18(%rbx), %rdi
movl $0xb, %esi
callq 0xef0d5
movb %al, 0x39(%r14)
movzbl 0x38(%r14), %edx
leaq 0x85f59(%rip), %rsi     # 0x13595c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movzbl 0x39(%r14), %edx
leaq 0x86249(%rip), %rsi     # 0x135c62
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movzbl 0x39(%r14), %eax
cmpl $0xff, %eax
je 0xafa41
testl %eax, %eax
jne 0xafa4a
movl $0x1, %eax
cmpb $0x1, 0x38(%r14)
je 0xafa46
jmp 0xafa4a
movl $0x2, %eax
movl %eax, 0x4(%r14)
movl 0x4(%r14), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0xafa91
cmpl $0x2, %eax
je 0xafa6c
leaq 0x86242(%rip), %rsi     # 0x135ca4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
cmpl $0x1, 0x4(%r14)
jne 0xafbfb
movb $0x0, 0x3a(%r14)
movl $0x0, 0x48(%r14)
movq $0xa, 0x50(%r14)
jmp 0xafc5b
leaq 0x861df(%rip), %rsi     # 0x135c77
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xaff32
leaq 0x85e53(%rip), %rsi     # 0x135901
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9b27
movq 0x18(%rbx), %rdi
movl $0x2, %esi
callq 0xef1ca
movq %rax, 0x20(%r14)
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef1ca
movq %rax, 0x28(%r14)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xe9b05
movq 0x18(%rbx), %rdi
movl $0xa, %esi
callq 0xef0d5
movl %eax, %ebp
movb %al, 0x38(%r14)
xorl %r12d, %r12d
cmpb $-0x1, %al
sete %r12b
je 0xafb1b
movq $0xb, 0x18(%r14)
jmp 0xafb35
movq $0xd, 0x18(%r14)
movq 0x18(%rbx), %rdi
movl $0xb, %esi
callq 0xef0d5
movb %al, 0x38(%r14)
leaq 0x88304(%rip), %rsi     # 0x137e40
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
movzbl 0x38(%r14), %edx
leaq 0x85e07(%rip), %rsi     # 0x13595c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movb $0x0, 0x3a(%r14)
addq $0x48, %r15
movl $0x0, 0x48(%r14)
movq $0x0, 0x50(%r14)
movq %r15, 0x78(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb0217
testl %eax, %eax
je 0xaff04
movq 0x18(%r14), %rdx
leaq 0x8b178(%rip), %rsi     # 0x13ad1f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb02ed
testl %eax, %eax
je 0xaff04
movq 0x18(%rbx), %rdi
cmpb $-0x1, %bpl
je 0xafe48
movq 0x18(%r14), %rsi
movq 0x18(%rdi), %rdx
subq %rsi, %rdx
callq 0xf1988
movq %rax, 0x88(%r14)
jmp 0xafef7
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xef0d5
movb %al, 0x3a(%r14)
movzbl %al, %edx
leaq 0x860ca(%rip), %rsi     # 0x135ce1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rsi
leaq 0x48(%r15), %rdx
movq %rbx, %rdi
callq 0xb0500
movl 0x48(%r14), %edx
leaq 0x860b8(%rip), %rsi     # 0x135cf4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x50(%r14), %edx
leaq 0x6a752(%rip), %rsi     # 0x11a3a3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpq $0x0, 0x50(%r14)
jle 0xafc78
leaq 0x86095(%rip), %rsi     # 0x135cfe
movq %rbx, %rdi
movl $0x11, %edx
xorl %eax, %eax
callq 0xe9226
addq $0x48, %r15
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xafcd7
cmpl $0x2, 0x4(%r14)
jl 0xafcd7
movb 0x3a(%r14), %cl
addb $-0x41, %cl
cmpb $0x11, %cl
ja 0xafcd7
movzbl %cl, %ecx
movl $0x22fff, %edx          # imm = 0x22FFF
btl %ecx, %edx
jae 0xafcd7
shll $0x3, %ecx
leaq 0x85a41(%rip), %rdx     # 0x1356f0
movsd (%rcx,%rdx), %xmm0
leaq 0x85ac5(%rip), %rdx     # 0x135780
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 0xb0217
testl %eax, %eax
je 0xaff32
movq 0x18(%rbx), %rdi
movq 0x50(%r14), %rsi
addq $0x11, %rsi
callq 0xef1ca
movq %rax, 0x80(%r14)
movq 0x50(%r14), %rcx
addq $0x13, %rcx
movq %rcx, 0x18(%r14)
leaq 0x86001(%rip), %rsi     # 0x135d1a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl 0x18(%r14), %edx
leaq 0x7013c(%rip), %rsi     # 0x11fe79
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb02ed
testl %eax, %eax
je 0xaff32
cmpl $0x1, 0x98(%r14)
jne 0xafd89
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
movq %rbx, %rdi
callq 0xf241d
testl %eax, %eax
je 0xaff32
cmpq $0x0, 0x80(%r14)
jle 0xaff0a
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xe958c
cmpq $0x0, 0x80(%r14)
jle 0xafe37
movl $0x4000, %esi           # imm = 0x4000
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0faf
movq %rax, 0x88(%r14)
movq 0x30(%r14), %rsi
addq $0x7, %rsi
imulq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0xf1066
leaq 0x85b9e(%rip), %rsi     # 0x135982
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r14), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb104b
testl %eax, %eax
je 0xafe37
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x88(%r14), %rax
movq 0x18(%rax), %rdx
leaq 0x639e9(%rip), %rsi     # 0x113816
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x8(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
jmp 0xaff25
movl $0xc, %esi
callq 0xef0d5
movzbl %al, %ebp
leaq 0x85b13(%rip), %rsi     # 0x13596f
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9461
leaq 0x85b13(%rip), %rsi     # 0x135982
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movl $0x4000, %esi           # imm = 0x4000
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0faf
movq %rax, 0x88(%r14)
movq 0x30(%r14), %rsi
addq $0x7, %rsi
imulq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0xf1066
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 0xb044f
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x88(%r14), %rax
movq 0x18(%rax), %rdx
leaq 0x63929(%rip), %rsi     # 0x113816
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq %r14, %rsi
callq *0x90(%r14)
movl 0x8(%rsp), %esi
jmp 0xaff36
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
movq 0x18(%rdi), %rdx
subq %rsi, %rdx
callq 0xf1988
movq %rax, 0x88(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq *0x90(%r14)
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb01c0
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq