// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pcx.c
// Function: do_read_alt_palette_file
static int do_read_alt_palette_file(deark *c, lctx *d)
{
	const char *palfn;
	dbuf *palfile = NULL;
	int retval = 0;
	i64 k,z;
	u8 b1[3];
	u8 b2[3];
	int badflag = 0;
	char tmps[64];

	palfn = de_get_ext_option(c, "file2");
	if(!palfn) goto done;

	palfile = dbuf_open_input_file(c, palfn);
	if(!palfile) goto done;
	de_dbg(c, "using palette from separate file");

	if(palfile->len != d->ncolors*3) {
		badflag = 1;
	}

	de_dbg_indent(c, 1);
	for(k=0; k<d->ncolors && k*3<palfile->len; k++) {
		dbuf_read(palfile, b1, 3*k, 3);
		for(z=0; z<3; z++) {
			if(b1[z]>0x3f) badflag = 1;
			b2[z] = de_scale_63_to_255(b1[z]);
		}
		d->pal[k] = DE_MAKE_RGB(b2[0],b2[1],b2[2]);

		de_snprintf(tmps, sizeof(tmps), "(%2d,%2d,%2d) "DE_CHAR_RIGHTARROW" ",
			(int)b1[0], (int)b1[1], (int)b1[2]);
		de_dbg_pal_entry2(c, k, d->pal[k], tmps, NULL, NULL);
	}
	de_dbg_indent(c, -1);

	if(badflag) {
		de_warn(c, "%s doesn't look like the right kind of palette file", palfn);
	}

	retval = 1;

done:
	dbuf_close(palfile);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x96dd4(%rip), %rsi     # 0x19c578
callq 0x15cb30
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1057b9
jmp 0x105977
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x168de0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1057d6
jmp 0x105977
movq -0x8(%rbp), %rdi
leaq 0xbc6b3(%rip), %rsi     # 0x1c1e94
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
imulq $0x3, 0x60(%rcx), %rcx
cmpq %rcx, %rax
je 0x105805
movl $0x1, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpq 0x60(%rdx), %rcx
movb %al, -0x91(%rbp)
jge 0x105847
imulq $0x3, -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
setl %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x105856
jmp 0x105946
movq -0x20(%rbp), %rdi
leaq -0x3b(%rbp), %rsi
imulq $0x3, -0x30(%rbp), %rdx
movl $0x3, %ecx
callq 0x164d10
movq $0x0, -0x38(%rbp)
cmpq $0x3, -0x38(%rbp)
jge 0x1058b7
movq -0x38(%rbp), %rax
movzbl -0x3b(%rbp,%rax), %eax
cmpl $0x3f, %eax
jle 0x105891
movl $0x1, -0x44(%rbp)
movq -0x38(%rbp), %rax
movzbl -0x3b(%rbp,%rax), %edi
callq 0x161710
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, -0x3e(%rbp,%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x105875
movzbl -0x3e(%rbp), %edx
shll $0x10, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movzbl -0x3d(%rbp), %eax
shll $0x8, %eax
orl %eax, %edx
movzbl -0x3c(%rbp), %eax
orl %eax, %edx
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl %edx, 0xb8(%rax,%rcx,4)
leaq -0x90(%rbp), %rdi
movzbl -0x3b(%rbp), %ecx
movzbl -0x3a(%rbp), %r8d
movzbl -0x39(%rbp), %r9d
movl $0x40, %esi
leaq 0x9766e(%rip), %rdx     # 0x19cf71
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0xb8(%rax,%rcx,4), %edx
leaq -0x90(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
callq 0x15bdb0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x10581b
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpl $0x0, -0x44(%rbp)
je 0x105970
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0xbc54c(%rip), %rsi     # 0x1c1eb5
movb $0x0, %al
callq 0x15bc10
movl $0x1, -0x24(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1676a0
movl -0x24(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)