// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x4a0, %esi            # imm = 0x4A0
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xd, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
leaq 0xc014d(%rip), %rsi     # 0x1c1515
callq 0x15cb30
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x10143f
movq -0x18(%rbp), %rdi
leaq 0xc06ba(%rip), %rsi     # 0x1c1a9d
callq 0x191a0
cmpl $0x0, %eax
jne 0x1013f9
movq -0x38(%rbp), %rax
movl $0x1, (%rax)
jmp 0x10143d
movq -0x18(%rbp), %rdi
leaq 0xad8cc(%rip), %rsi     # 0x1aecd0
callq 0x191a0
cmpl $0x0, %eax
jne 0x10141a
movq -0x38(%rbp), %rax
movl $0x2, (%rax)
jmp 0x10143b
movq -0x18(%rbp), %rdi
leaq 0xc00fc(%rip), %rsi     # 0x1c1521
callq 0x191a0
cmpl $0x0, %eax
jne 0x101439
movq -0x38(%rbp), %rax
movl $0x2, (%rax)
jmp 0x10143b
jmp 0x10143d
jmp 0x10143f
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1014d7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0x10, %ecx
callq 0x164d10
movzbl -0x30(%rbp), %eax
cmpl $0x34, %eax
jne 0x1014cb
movzbl -0x2f(%rbp), %eax
cmpl $0x12, %eax
jne 0x1014cb
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x1234, 0x18(%rax)     # imm = 0x1234
jne 0x1014bf
movzbl -0x26(%rbp), %eax
cmpl $0xff, %eax
jne 0x1014a1
movq -0x38(%rbp), %rax
movl $0x2, (%rax)
jmp 0x1014bd
movq -0x8(%rbp), %rdi
leaq 0xc007a(%rip), %rsi     # 0x1c1526
movb $0x0, %al
callq 0x15bc10
movq -0x38(%rbp), %rax
movl $0x1, (%rax)
jmp 0x1014c9
movq -0x38(%rbp), %rax
movl $0x1, (%rax)
jmp 0x1014d5
movq -0x38(%rbp), %rax
movl $0x2, (%rax)
jmp 0x1014d7
movq -0x8(%rbp), %rdi
leaq 0xc0092(%rip), %rsi     # 0x1c1574
xorl %edx, %edx
callq 0x15cbc0
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x10150e
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x1018e0
jmp 0x10151f
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x101cb0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1020d0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)