// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/png.c
// Function: handler_sPLT
static void handler_sPLT(deark *c, lctx *d, struct handler_params *hp)
{
	struct de_stringreaderdata *srd = NULL;
	i64 pos = hp->dpos;
	i64 nbytes_to_scan;
	u8 depth;
	i64 nentries;
	i64 stride;
	i64 i;

	nbytes_to_scan = hp->dlen;
	if(nbytes_to_scan>80) nbytes_to_scan=80;
	srd = dbuf_read_string(c->infile, pos, nbytes_to_scan, 79, DE_CONVFLAG_STOP_AT_NUL,
		DE_ENCODING_LATIN1);
	if(!srd->found_nul) goto done;
	de_dbg(c, "palette name: \"%s\"", ucstring_getpsz(srd->str));
	pos += srd->bytes_consumed;

	if(pos >= hp->dpos+hp->dlen) goto done;
	depth = de_getbyte(pos++);
	de_dbg(c, "depth: %d", (int)depth);
	if(depth!=8 && depth!=16) goto done;

	stride = (depth==8) ? 6 : 10;
	nentries = (hp->dpos+hp->dlen-pos)/stride;
	de_dbg(c, "number of entries: %d", (int)nentries);

	if(c->debug_level<2) goto done;
	for(i=0; i<nentries; i++) {
		unsigned int cr, cg, cb, ca, cf;
		if(depth==8) {
			cr = (unsigned int)de_getbyte(pos);
			cg = (unsigned int)de_getbyte(pos+1);
			cb = (unsigned int)de_getbyte(pos+2);
			ca = (unsigned int)de_getbyte(pos+3);
			cf = (unsigned int)de_getu16be(pos+4);
			de_dbg2(c, "pal[%3d] = (%3u,%3u,%3u,A=%u) F=%u",
				(int)i, cr, cg, cb, ca, cf);
		}
		else {
			cr = (unsigned int)de_getu16be(pos);
			cg = (unsigned int)de_getu16be(pos+2);
			cb = (unsigned int)de_getu16be(pos+4);
			ca = (unsigned int)de_getu16be(pos+6);
			cf = (unsigned int)de_getu16be(pos+8);
			de_dbg2(c, "pal[%3d] = (%5u,%5u,%5u,A=%u) F=%u",
				(int)i, cr, cg, cb, ca, cf);
		}
		pos += stride;
	}

done:
	de_destroy_stringreaderdata(c, srd);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
movq %rdi, %rbx
movq (%rdx), %r12
movq 0x8(%rdx), %rax
cmpq $0x50, %rax
pushq $0x50
popq %rdx
cmovlq %rax, %rdx
movq 0x18(%rdi), %rdi
pushq $0x4f
popq %rcx
pushq $0x1
popq %r8
pushq $0x5
popq %r9
movq %r12, %rsi
callq 0xe495c
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x34(%rax)
je 0xaf1bc
movq 0x10(%rsp), %r14
movq 0x18(%r14), %rdi
callq 0xeb7e4
leaq 0x7b789(%rip), %rsi     # 0x12a8b0
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq (%r14), %r14
leaq (%r14,%r12), %r13
movq 0x8(%r15), %rax
addq (%r15), %rax
cmpq %rax, %r13
jge 0xaf1bc
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3eb4
movb %al, 0x7(%rsp)
movzbl %al, %ebp
leaq 0x65f66(%rip), %rsi     # 0x1150c7
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
cmpb $0x10, %bpl
je 0xaf178
cmpl $0x8, %ebp
jne 0xaf1bc
xorl %eax, %eax
cmpb $0x8, 0x7(%rsp)
setne %al
leaq 0x6(,%rax,4), %rcx
notq %r13
addq (%r15), %r13
addq 0x8(%r15), %r13
movq %r13, %rax
cqto
movq %rcx, 0x20(%rsp)
idivq %rcx
leaq 0x5a846(%rip), %rsi     # 0x1099ee
movq %rbx, %rdi
movq %rax, %r15
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
cmpl $0x2, (%rbx)
jge 0xaf1d7
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe4b94
xorl %eax, %eax
testq %r15, %r15
cmovleq %rax, %r15
movq %r15, 0x18(%rsp)
addq %r14, %r12
addq $0x9, %r12
xorl %r13d, %r13d
cmpq %r13, 0x18(%rsp)
je 0xaf1bc
leaq -0x8(%r12), %rsi
movq 0x18(%rbx), %rdi
cmpb $0x8, 0x7(%rsp)
jne 0xaf271
callq 0xe3eb4
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq -0x7(%r12), %rsi
callq 0xe3eb4
movzbl %al, %ebp
movq 0x18(%rbx), %rdi
leaq -0x6(%r12), %rsi
callq 0xe3eb4
movzbl %al, %r15d
movq 0x18(%rbx), %rdi
leaq -0x5(%r12), %rsi
callq 0xe3eb4
movzbl %al, %r14d
movq 0x18(%rbx), %rdi
leaq -0x4(%r12), %rsi
callq 0xe3f46
movq %rax, %r10
movq %rbx, %rdi
leaq 0x7b661(%rip), %rsi     # 0x12a8c3
movl %r13d, %edx
movl 0x8(%rsp), %ecx
movl %ebp, %r8d
movl %r15d, %r9d
jmp 0xaf2d5
callq 0xe3f46
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq -0x6(%r12), %rsi
callq 0xe3f46
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq -0x4(%r12), %rsi
callq 0xe3f46
movq %rax, %r15
movq 0x18(%rbx), %rdi
leaq -0x2(%r12), %rsi
callq 0xe3f46
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3f46
movq %rax, %r10
movq %rbx, %rdi
leaq 0x7b61f(%rip), %rsi     # 0x12a8e6
movl %r13d, %edx
movq 0x8(%rsp), %rcx
movl %ebp, %r8d
movl %r15d, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
callq 0xde9f1
popq %rax
popq %rcx
incq %r13
addq 0x20(%rsp), %r12
jmp 0xaf1ef