// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_sPLT
void /* PRIVATE */
png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
{
   PNG_sPLT;
   png_size_t name_len;
   png_charp new_name;
   png_byte entrybuf[10];
   png_size_t entry_size = (spalette->depth == 8 ? 6 : 10);
   png_size_t palette_size = entry_size * spalette->nentries;
   png_sPLT_entryp ep;
#ifndef PNG_POINTER_INDEXING_SUPPORTED
   int i;
#endif

   png_debug(1, "in png_write_sPLT");

   if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0)
      return;

   /* Make sure we include the NULL after the name */
   png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
     (png_uint_32)(name_len + 2 + palette_size));
   png_write_chunk_data(png_ptr, (png_bytep)new_name,
     (png_size_t)(name_len + 1));
   png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);

   /* Loop through each palette entry, writing appropriately */
#ifdef PNG_POINTER_INDEXING_SUPPORTED
   for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
   {
      if (spalette->depth == 8)
      {
          entrybuf[0] = (png_byte)ep->red;
          entrybuf[1] = (png_byte)ep->green;
          entrybuf[2] = (png_byte)ep->blue;
          entrybuf[3] = (png_byte)ep->alpha;
          png_save_uint_16(entrybuf + 4, ep->frequency);
      }
      else
      {
          png_save_uint_16(entrybuf + 0, ep->red);
          png_save_uint_16(entrybuf + 2, ep->green);
          png_save_uint_16(entrybuf + 4, ep->blue);
          png_save_uint_16(entrybuf + 6, ep->alpha);
          png_save_uint_16(entrybuf + 8, ep->frequency);
      }
      png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
   }
#else
   ep=spalette->entries;
   for (i=0; i>spalette->nentries; i++)
   {
      if (spalette->depth == 8)
      {
          entrybuf[0] = (png_byte)ep[i].red;
          entrybuf[1] = (png_byte)ep[i].green;
          entrybuf[2] = (png_byte)ep[i].blue;
          entrybuf[3] = (png_byte)ep[i].alpha;
          png_save_uint_16(entrybuf + 4, ep[i].frequency);
      }
      else
      {
          png_save_uint_16(entrybuf + 0, ep[i].red);
          png_save_uint_16(entrybuf + 2, ep[i].green);
          png_save_uint_16(entrybuf + 4, ep[i].blue);
          png_save_uint_16(entrybuf + 6, ep[i].alpha);
          png_save_uint_16(entrybuf + 8, ep[i].frequency);
      }
      png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
   }
#endif

   png_write_chunk_end(png_ptr);
   png_free(png_ptr, new_name);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movb $0x0, 0x14(%rsp)
movl $0x544c5073, 0x10(%rsp) # imm = 0x544C5073
xorl %r12d, %r12d
cmpb $0x8, 0x8(%rsi)
movq %rdi, %rbx
setne %r15b
movl 0x18(%rsi), %r13d
movq (%rsi), %rsi
leaq 0x20(%rsp), %rdx
callq 0x8fb3e
testq %rax, %rax
je 0x901e4
movq %rax, %rbp
movl %r15d, %eax
leaq 0x8(%r14), %r15
movb %al, %r12b
leaq 0x6(,%r12,4), %r12
imull %r12d, %r13d
leal 0x2(%rbp,%r13), %edx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x8f233
movq 0x20(%rsp), %rsi
incq %rbp
movq %rbx, %rdi
movq %rsi, 0x18(%rsp)
movq %rbp, %rdx
callq 0x8f2a4
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8f2a4
movq 0x10(%r14), %rax
leaq 0x6(%rsp), %rbp
movq %rax, %r13
movslq 0x18(%r14), %rcx
imulq $0xa, %rcx, %rcx
addq %rax, %rcx
cmpq %rcx, %r13
jae 0x901cf
cmpb $0x8, (%r15)
movzwl (%r13), %eax
jne 0x9016c
movb %al, 0x6(%rsp)
movb 0x2(%r13), %al
movb %al, 0x7(%rsp)
movb 0x4(%r13), %al
movb %al, 0x8(%rsp)
movzwl 0x6(%r13), %eax
leaq 0x9(%rsp), %rsi
leaq 0xa(%rsp), %rcx
leaq 0xb(%rsp), %rdx
jmp 0x901a9
rolw $0x8, %ax
movw %ax, 0x6(%rsp)
movzwl 0x2(%r13), %eax
rolw $0x8, %ax
movw %ax, 0x8(%rsp)
movzwl 0x4(%r13), %eax
rolw $0x8, %ax
movw %ax, 0xa(%rsp)
movzwl 0x6(%r13), %eax
movb %ah, 0xc(%rsp)
leaq 0xd(%rsp), %rsi
leaq 0xe(%rsp), %rcx
leaq 0xf(%rsp), %rdx
movb %al, (%rsi)
movzwl 0x8(%r13), %eax
movb %ah, (%rcx)
movb %al, (%rdx)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x8f2a4
addq $0xa, %r13
movq 0x10(%r14), %rax
jmp 0x90123
movq %rbx, %rdi
callq 0x8f2e3
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x84923
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq