// File: /workspace/github_c_makefile_star2_O3/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
movl $0x50, %edx
cmovlq %rax, %rdx
movq 0x18(%rdi), %rdi
movl $0x4f, %ecx
movq %r12, %rsi
movl $0x1, %r8d
movl $0x5, %r9d
callq 0xef87c
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x34(%rax)
je 0xb641a
movq 0x10(%rsp), %r14
movq 0x18(%r14), %rdi
callq 0xf705c
leaq 0x81930(%rip), %rsi     # 0x137b90
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq (%r14), %r14
leaq (%r14,%r12), %r13
movq 0x8(%r15), %rax
addq (%r15), %rax
cmpq %rax, %r13
jge 0xb641a
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeead3
movb %al, 0x7(%rsp)
movzbl %al, %ebp
leaq 0x6bfe9(%rip), %rsi     # 0x122287
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
cmpb $0x10, %bpl
je 0xb62b9
cmpl $0x8, %ebp
jne 0xb641a
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 0x60795(%rip), %rsi     # 0x116a7e
movq %rbx, %rdi
movq %rax, 0x18(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
cmpl $0x2, (%rbx)
jl 0xb641a
cmpq $0x0, 0x18(%rsp)
jle 0xb641a
addq %r14, %r12
addq $0x4, %r12
xorl %r13d, %r13d
leaq -0x3(%r12), %rsi
movq 0x18(%rbx), %rdi
cmpb $0x8, 0x7(%rsp)
jne 0xb6392
callq 0xeead3
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq -0x2(%r12), %rsi
callq 0xeead3
movzbl %al, %ebp
movq 0x18(%rbx), %rdi
leaq -0x1(%r12), %rsi
callq 0xeead3
movzbl %al, %r15d
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeead3
movzbl %al, %r14d
movq 0x18(%rbx), %rdi
leaq 0x1(%r12), %rsi
callq 0xeeb67
movq %rax, %r10
movq %rbx, %rdi
leaq 0x81820(%rip), %rsi     # 0x137ba3
movl %r13d, %edx
movl 0x8(%rsp), %ecx
movl %ebp, %r8d
movl %r15d, %r9d
jmp 0xb63f8
callq 0xeeb67
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq -0x1(%r12), %rsi
callq 0xeeb67
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq 0x1(%r12), %rsi
callq 0xeeb67
movq %rax, %r15
movq 0x18(%rbx), %rdi
leaq 0x3(%r12), %rsi
callq 0xeeb67
movq %rax, %r14
movq 0x18(%rbx), %rdi
leaq 0x5(%r12), %rsi
callq 0xeeb67
movq %rax, %r10
movq %rbx, %rdi
leaq 0x817dc(%rip), %rsi     # 0x137bc6
movl %r13d, %edx
movq 0x8(%rsp), %rcx
movl %ebp, %r8d
movl %r15d, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
callq 0xe87e4
addq $0x10, %rsp
incq %r13
addq 0x20(%rsp), %r12
cmpq %r13, 0x18(%rsp)
jne 0xb6319
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xefaca