// File: tomfunkhouser[P]gaps/pkgs/png/pngset.c
// Function: png_set_sPLT
void PNGAPI
png_set_sPLT(png_structp png_ptr,
             png_infop info_ptr, png_sPLT_tp entries, int nentries)
/*
 *  entries        - array of png_sPLT_t structures
 *                   to be added to the list of palettes
 *                   in the info structure.
 *  nentries       - number of palette structures to be
 *                   added.
 */
{
   png_sPLT_tp np;
   int i;

   if (png_ptr == NULL || info_ptr == NULL)
      return;

   np = (png_sPLT_tp)png_malloc_warn(png_ptr,
       (info_ptr->splt_palettes_num + nentries) *
        (png_size_t)png_sizeof(png_sPLT_t));
   if (np == NULL)
   {
      png_warning(png_ptr, "No memory for sPLT palettes");
      return;
   }

   png_memcpy(np, info_ptr->splt_palettes,
       info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
   png_free(png_ptr, info_ptr->splt_palettes);
   info_ptr->splt_palettes=NULL;

   for (i = 0; i < nentries; i++)
   {
      png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
      png_sPLT_tp from = entries + i;
      png_uint_32 length;

      length = png_strlen(from->name) + 1;
      to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
      if (to->name == NULL)
      {
         png_warning(png_ptr,
           "Out of memory while processing sPLT chunk");
         continue;
      }
      png_memcpy(to->name, from->name, length);
      to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
          (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
      if (to->entries == NULL)
      {
         png_warning(png_ptr,
           "Out of memory while processing sPLT chunk");
         png_free(png_ptr, to->name);
         to->name = NULL;
         continue;
      }
      png_memcpy(to->entries, from->entries,
          from->nentries * png_sizeof(png_sPLT_entry));
      to->nentries = from->nentries;
      to->depth = from->depth;
   }

   info_ptr->splt_palettes = np;
   info_ptr->splt_palettes_num += nentries;
   info_ptr->valid |= PNG_INFO_sPLT;
   info_ptr->free_me |= PNG_FREE_SPLT;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movl %ecx, 0x2c(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0xfe6c7
cmpq $0x0, 0x38(%rsp)
jne 0xfe6cc
jmp 0xfe91c
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0x118(%rax), %eax
addl 0x2c(%rsp), %eax
movl %eax, %eax
movl %eax, %esi
shlq $0x5, %rsi
callq 0x113760
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0xfe710
movq 0x40(%rsp), %rdi
leaq 0x3a8a2(%rip), %rsi     # 0x138fa8
callq 0x113940
jmp 0xfe91c
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x110(%rax), %rsi
movq 0x38(%rsp), %rax
movl 0x118(%rax), %eax
movl %eax, %edx
shlq $0x5, %rdx
callq 0xf3d0
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x110(%rax), %rsi
callq 0x1136d0
movq 0x38(%rsp), %rax
movq $0x0, 0x110(%rax)
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0xfe8d1
movq 0x20(%rsp), %rax
movq 0x38(%rsp), %rcx
movl 0x118(%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x1c(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
movslq 0x1c(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
callq 0xf200
addq $0x1, %rax
movl %eax, 0x4(%rsp)
movq 0x40(%rsp), %rdi
movl 0x4(%rsp), %eax
movl %eax, %esi
callq 0x113760
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
jne 0xfe802
movq 0x40(%rsp), %rdi
leaq 0x3a7cc(%rip), %rsi     # 0x138fc4
callq 0x113940
jmp 0xfe8c1
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movl 0x4(%rsp), %eax
movl %eax, %edx
callq 0xf3d0
movq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rax
movslq 0x18(%rax), %rax
imulq $0xa, %rax, %rsi
callq 0x113760
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xfe87d
movq 0x40(%rsp), %rdi
leaq 0x3a76c(%rip), %rsi     # 0x138fc4
callq 0x113940
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rax
movq (%rax), %rsi
callq 0x1136d0
movq 0x10(%rsp), %rax
movq $0x0, (%rax)
jmp 0xfe8c1
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x8(%rsp), %rax
movslq 0x18(%rax), %rax
imulq $0xa, %rax, %rdx
callq 0xf3d0
movq 0x8(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x18(%rax)
movq 0x8(%rsp), %rax
movb 0x8(%rax), %cl
movq 0x10(%rsp), %rax
movb %cl, 0x8(%rax)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xfe765
movq 0x20(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x110(%rax)
movl 0x2c(%rsp), %ecx
movq 0x38(%rsp), %rax
addl 0x118(%rax), %ecx
movl %ecx, 0x118(%rax)
movq 0x38(%rsp), %rax
movl 0x8(%rax), %ecx
orl $0x2000, %ecx           # imm = 0x2000
movl %ecx, 0x8(%rax)
movq 0x38(%rsp), %rax
movl 0xe4(%rax), %ecx
orl $0x20, %ecx
movl %ecx, 0xe4(%rax)
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)