// File: tomfunkhouser[P]gaps/pkgs/png/pngset.c
// Function: png_set_unknown_chunks
void PNGAPI
png_set_unknown_chunks(png_structp png_ptr,
   png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
{
   png_unknown_chunkp np;
   int i;

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

   np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
       (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
       png_sizeof(png_unknown_chunk)));
   if (np == NULL)
   {
      png_warning(png_ptr,
          "Out of memory while processing unknown chunk");
      return;
   }

   png_memcpy(np, info_ptr->unknown_chunks,
       info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
   png_free(png_ptr, info_ptr->unknown_chunks);
   info_ptr->unknown_chunks = NULL;

   for (i = 0; i < num_unknowns; i++)
   {
      png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
      png_unknown_chunkp from = unknowns + i;

      png_memcpy((png_charp)to->name, (png_charp)from->name,
          png_sizeof(from->name));
      to->name[png_sizeof(to->name)-1] = '\0';
      to->size = from->size;
      /* Note our location in the read or write sequence */
      to->location = (png_byte)(png_ptr->mode & 0xff);

      if (from->size == 0)
         to->data=NULL;
      else
      {
         to->data = (png_bytep)png_malloc_warn(png_ptr,
           (png_size_t)from->size);
         if (to->data == NULL)
         {
            png_warning(png_ptr,
             "Out of memory while processing unknown chunk");
            to->size = 0;
         }
         else
            png_memcpy(to->data, from->data, from->size);
      }
   }

   info_ptr->unknown_chunks = np;
   info_ptr->unknown_chunks_num += num_unknowns;
   info_ptr->free_me |= PNG_FREE_UNKN;
}

// 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 0xfe95e
cmpq $0x0, 0x38(%rsp)
je 0xfe95e
cmpl $0x0, 0x2c(%rsp)
jne 0xfe963
jmp 0xfeb6c
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0xf0(%rax), %rsi
movslq 0x2c(%rsp), %rax
addq %rax, %rsi
shlq $0x5, %rsi
callq 0x113760
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0xfe9a8
movq 0x40(%rsp), %rdi
leaq 0x3a650(%rip), %rsi     # 0x138fee
callq 0x113940
jmp 0xfeb6c
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0xe8(%rax), %rsi
movq 0x38(%rsp), %rax
movq 0xf0(%rax), %rdx
shlq $0x5, %rdx
callq 0xf3d0
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0xe8(%rax), %rsi
callq 0x1136d0
movq 0x38(%rsp), %rax
movq $0x0, 0xe8(%rax)
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0xfeb2c
movq 0x20(%rsp), %rax
movq 0x38(%rsp), %rcx
movq 0xf0(%rcx), %rcx
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 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
movl (%rcx), %edx
movl %edx, (%rax)
movb 0x4(%rcx), %cl
movb %cl, 0x4(%rax)
movq 0x10(%rsp), %rax
movb $0x0, 0x4(%rax)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x40(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, 0x18(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xfeaad
movq 0x10(%rsp), %rax
movq $0x0, 0x8(%rax)
jmp 0xfeb1a
movq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x113760
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xfeaf8
movq 0x40(%rsp), %rdi
leaq 0x3a50a(%rip), %rsi     # 0x138fee
callq 0x113940
movq 0x10(%rsp), %rax
movq $0x0, 0x10(%rax)
jmp 0xfeb18
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0xf3d0
jmp 0xfeb1a
jmp 0xfeb1c
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xfe9fc
movq 0x20(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0xe8(%rax)
movslq 0x2c(%rsp), %rcx
movq 0x38(%rsp), %rax
addq 0xf0(%rax), %rcx
movq %rcx, 0xf0(%rax)
movq 0x38(%rsp), %rax
movl 0xe4(%rax), %ecx
orl $0x200, %ecx            # imm = 0x200
movl %ecx, 0xe4(%rax)
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)