// File: tomfunkhouser[P]gaps/pkgs/png/pngset.c
// Function: png_set_keep_unknown_chunks
void PNGAPI
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
   chunk_list, int num_chunks)
{
   png_bytep new_list, p;
   int i, old_num_chunks;
   if (png_ptr == NULL)
      return;
   if (num_chunks == 0)
   {
      if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
         png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
      else
         png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;

      if (keep == PNG_HANDLE_CHUNK_ALWAYS)
         png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
      else
         png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
      return;
   }
   if (chunk_list == NULL)
      return;
   old_num_chunks = png_ptr->num_chunk_list;
   new_list=(png_bytep)png_malloc(png_ptr,
      (png_size_t)
       (5*(num_chunks + old_num_chunks)));
   if (png_ptr->chunk_list != NULL)
   {
      png_memcpy(new_list, png_ptr->chunk_list,
          (png_size_t)(5*old_num_chunks));
      png_free(png_ptr, png_ptr->chunk_list);
      png_ptr->chunk_list=NULL;
   }
   png_memcpy(new_list + 5*old_num_chunks, chunk_list,
       (png_size_t)(5*num_chunks));
   for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
      *p=(png_byte)keep;
   png_ptr->num_chunk_list = old_num_chunks + num_chunks;
   png_ptr->chunk_list = new_list;
   png_ptr->free_me |= PNG_FREE_LIST;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movq %rdx, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0xfec53
jmp 0xfee0d
cmpl $0x0, 0x1c(%rsp)
jne 0xfecd8
cmpl $0x3, 0x2c(%rsp)
je 0xfec68
cmpl $0x2, 0x2c(%rsp)
jne 0xfec82
movq 0x30(%rsp), %rax
movl 0x120(%rax), %ecx
orq $0x8000, %rcx           # imm = 0x8000
movl %ecx, 0x120(%rax)
jmp 0xfec9a
movq 0x30(%rsp), %rax
movl 0x120(%rax), %ecx
andq $-0x8001, %rcx          # imm = 0xFFFF7FFF
movl %ecx, 0x120(%rax)
cmpl $0x3, 0x2c(%rsp)
jne 0xfecbb
movq 0x30(%rsp), %rax
movl 0x120(%rax), %ecx
orq $0x10000, %rcx          # imm = 0x10000
movl %ecx, 0x120(%rax)
jmp 0xfecd3
movq 0x30(%rsp), %rax
movl 0x120(%rax), %ecx
andq $-0x10001, %rcx         # imm = 0xFFFEFFFF
movl %ecx, 0x120(%rax)
jmp 0xfee0d
cmpq $0x0, 0x20(%rsp)
jne 0xfece5
jmp 0xfee0d
movq 0x30(%rsp), %rax
movl 0x3f0(%rax), %eax
movl %eax, (%rsp)
movq 0x30(%rsp), %rdi
movl 0x1c(%rsp), %eax
addl (%rsp), %eax
imull $0x5, %eax, %eax
movslq %eax, %rsi
callq 0x1135b0
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
cmpq $0x0, 0x3f8(%rax)
je 0xfed61
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x3f8(%rax), %rsi
imull $0x5, (%rsp), %eax
movslq %eax, %rdx
callq 0xf3d0
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x3f8(%rax), %rsi
callq 0x1136d0
movq 0x30(%rsp), %rax
movq $0x0, 0x3f8(%rax)
movq 0x10(%rsp), %rdi
imull $0x5, (%rsp), %eax
cltq
addq %rax, %rdi
movq 0x20(%rsp), %rsi
imull $0x5, 0x1c(%rsp), %eax
movslq %eax, %rdx
callq 0xf3d0
movq 0x10(%rsp), %rax
imull $0x5, (%rsp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
addq $0x4, %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jge 0xfedd3
movl 0x2c(%rsp), %eax
movb %al, %cl
movq 0x8(%rsp), %rax
movb %cl, (%rax)
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rax
addq $0x5, %rax
movq %rax, 0x8(%rsp)
jmp 0xfeda1
movl (%rsp), %ecx
addl 0x1c(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x3f0(%rax)
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x3f8(%rax)
movq 0x30(%rsp), %rax
movl 0x3d8(%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movl %ecx, 0x3d8(%rax)
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)