// File: /workspace/github_c_makefile_star2_O1/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 0xefe67
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x34(%rax)
je 0xb6f96
movq 0x10(%rsp), %r14
movq 0x18(%r14), %rdi
callq 0xf74bd
leaq 0x80a2c(%rip), %rsi     # 0x137808
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq (%r14), %r14
leaq (%r14,%r12), %r13
movq 0x8(%r15), %rax
addq (%r15), %rax
cmpq %rax, %r13
jge 0xb6f96
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef0d5
movb %al, 0x7(%rsp)
movzbl %al, %ebp
leaq 0x6b265(%rip), %rsi     # 0x12207f
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
cmpb $0x10, %bpl
je 0xb6e35
cmpl $0x8, %ebp
jne 0xb6f96
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 0x5fb69(%rip), %rsi     # 0x1169ce
movq %rbx, %rdi
movq %rax, 0x18(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
cmpl $0x2, (%rbx)
jl 0xb6f96
cmpq $0x0, 0x18(%rsp)
jle 0xb6f96
addq %r14, %r12
addq $0x4, %r12
xorl %r13d, %r13d
leaq -0x3(%r12), %rsi
movq 0x18(%rbx), %rdi
cmpb $0x8, 0x7(%rsp)
jne 0xb6f0e
callq 0xef0d5
movzbl %al, %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq -0x2(%r12), %rsi
callq 0xef0d5
movzbl %al, %ebp
movq 0x18(%rbx), %rdi
leaq -0x1(%r12), %rsi
callq 0xef0d5
movzbl %al, %r15d
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef0d5
movzbl %al, %r14d
movq 0x18(%rbx), %rdi
leaq 0x1(%r12), %rsi
callq 0xef169
movq %rax, %r10
movq %rbx, %rdi
leaq 0x8091c(%rip), %rsi     # 0x13781b
movl %r13d, %edx
movl 0x8(%rsp), %ecx
movl %ebp, %r8d
movl %r15d, %r9d
jmp 0xb6f74
callq 0xef169
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq -0x1(%r12), %rsi
callq 0xef169
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq 0x1(%r12), %rsi
callq 0xef169
movq %rax, %r15
movq 0x18(%rbx), %rdi
leaq 0x3(%r12), %rsi
callq 0xef169
movq %rax, %r14
movq 0x18(%rbx), %rdi
leaq 0x5(%r12), %rsi
callq 0xef169
movq %rax, %r10
movq %rbx, %rdi
leaq 0x808d8(%rip), %rsi     # 0x13783e
movl %r13d, %edx
movq 0x8(%rsp), %rcx
movl %ebp, %r8d
movl %r15d, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
callq 0xe93cf
addq $0x10, %rsp
incq %r13
addq 0x20(%rsp), %r12
cmpq %r13, 0x18(%rsp)
jne 0xb6e95
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf00aa