// File: tomfunkhouser[P]gaps/pkgs/png/png.c
// Function: png_free_data
void PNGAPI
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
   int num)
{
   png_debug(1, "in png_free_data");

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

#ifdef PNG_TEXT_SUPPORTED
   /* Free text item num or (if num == -1) all text items */
   if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
   {
      if (num != -1)
      {
         if (info_ptr->text && info_ptr->text[num].key)
         {
            png_free(png_ptr, info_ptr->text[num].key);
            info_ptr->text[num].key = NULL;
         }
      }
      else
      {
         int i;
         for (i = 0; i < info_ptr->num_text; i++)
             png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
         png_free(png_ptr, info_ptr->text);
         info_ptr->text = NULL;
         info_ptr->num_text=0;
      }
   }
#endif

#ifdef PNG_tRNS_SUPPORTED
   /* Free any tRNS entry */
   if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
   {
      png_free(png_ptr, info_ptr->trans_alpha);
      info_ptr->trans_alpha = NULL;
      info_ptr->valid &= ~PNG_INFO_tRNS;
   }
#endif

#ifdef PNG_sCAL_SUPPORTED
   /* Free any sCAL entry */
   if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
   {
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
      png_free(png_ptr, info_ptr->scal_s_width);
      png_free(png_ptr, info_ptr->scal_s_height);
      info_ptr->scal_s_width = NULL;
      info_ptr->scal_s_height = NULL;
#endif
      info_ptr->valid &= ~PNG_INFO_sCAL;
   }
#endif

#ifdef PNG_pCAL_SUPPORTED
   /* Free any pCAL entry */
   if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
   {
      png_free(png_ptr, info_ptr->pcal_purpose);
      png_free(png_ptr, info_ptr->pcal_units);
      info_ptr->pcal_purpose = NULL;
      info_ptr->pcal_units = NULL;
      if (info_ptr->pcal_params != NULL)
         {
            int i;
            for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
            {
               png_free(png_ptr, info_ptr->pcal_params[i]);
               info_ptr->pcal_params[i] = NULL;
            }
            png_free(png_ptr, info_ptr->pcal_params);
            info_ptr->pcal_params = NULL;
         }
      info_ptr->valid &= ~PNG_INFO_pCAL;
   }
#endif

#ifdef PNG_iCCP_SUPPORTED
   /* Free any iCCP entry */
   if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
   {
      png_free(png_ptr, info_ptr->iccp_name);
      png_free(png_ptr, info_ptr->iccp_profile);
      info_ptr->iccp_name = NULL;
      info_ptr->iccp_profile = NULL;
      info_ptr->valid &= ~PNG_INFO_iCCP;
   }
#endif

#ifdef PNG_sPLT_SUPPORTED
   /* Free a given sPLT entry, or (if num == -1) all sPLT entries */
   if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
   {
      if (num != -1)
      {
         if (info_ptr->splt_palettes)
         {
            png_free(png_ptr, info_ptr->splt_palettes[num].name);
            png_free(png_ptr, info_ptr->splt_palettes[num].entries);
            info_ptr->splt_palettes[num].name = NULL;
            info_ptr->splt_palettes[num].entries = NULL;
         }
      }
      else
      {
         if (info_ptr->splt_palettes_num)
         {
            int i;
            for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
               png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);

            png_free(png_ptr, info_ptr->splt_palettes);
            info_ptr->splt_palettes = NULL;
            info_ptr->splt_palettes_num = 0;
         }
         info_ptr->valid &= ~PNG_INFO_sPLT;
      }
   }
#endif

#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
   if (png_ptr->unknown_chunk.data)
   {
      png_free(png_ptr, png_ptr->unknown_chunk.data);
      png_ptr->unknown_chunk.data = NULL;
   }

   if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
   {
      if (num != -1)
      {
          if (info_ptr->unknown_chunks)
          {
             png_free(png_ptr, info_ptr->unknown_chunks[num].data);
             info_ptr->unknown_chunks[num].data = NULL;
          }
      }
      else
      {
         int i;

         if (info_ptr->unknown_chunks_num)
         {
            for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
               png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);

            png_free(png_ptr, info_ptr->unknown_chunks);
            info_ptr->unknown_chunks = NULL;
            info_ptr->unknown_chunks_num = 0;
         }
      }
   }
#endif

#ifdef PNG_hIST_SUPPORTED
   /* Free any hIST entry */
   if ((mask & PNG_FREE_HIST)  & info_ptr->free_me)
   {
      png_free(png_ptr, info_ptr->hist);
      info_ptr->hist = NULL;
      info_ptr->valid &= ~PNG_INFO_hIST;
   }
#endif

   /* Free any PLTE entry that was internally allocated */
   if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
   {
      png_zfree(png_ptr, info_ptr->palette);
      info_ptr->palette = NULL;
      info_ptr->valid &= ~PNG_INFO_PLTE;
      info_ptr->num_palette = 0;
   }

#ifdef PNG_INFO_IMAGE_SUPPORTED
   /* Free any image bits attached to the info structure */
   if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
   {
      if (info_ptr->row_pointers)
      {
         int row;
         for (row = 0; row < (int)info_ptr->height; row++)
         {
            png_free(png_ptr, info_ptr->row_pointers[row]);
            info_ptr->row_pointers[row] = NULL;
         }
         png_free(png_ptr, info_ptr->row_pointers);
         info_ptr->row_pointers = NULL;
      }
      info_ptr->valid &= ~PNG_INFO_IDAT;
   }
#endif

   if (num == -1)
      info_ptr->free_me &= ~mask;
   else
      info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl %edx, 0x24(%rsp)
movl %ecx, 0x20(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0xfbaa6
cmpq $0x0, 0x28(%rsp)
jne 0xfbaab
jmp 0xfc1d1
movl 0x24(%rsp), %eax
andl $0x4000, %eax           # imm = 0x4000
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfbba2
cmpl $-0x1, 0x20(%rsp)
je 0xfbb39
movq 0x28(%rsp), %rax
cmpq $0x0, 0x48(%rax)
je 0xfbb37
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x20(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0xfbb37
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x20(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x20(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
jmp 0xfbba0
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl 0x3c(%rcx), %eax
jge 0xfbb74
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x1c(%rsp), %ecx
movl $0x4000, %edx           # imm = 0x4000
callq 0xfba80
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xfbb41
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0x48(%rax)
movq 0x28(%rsp), %rax
movl $0x0, 0x3c(%rax)
jmp 0xfbba2
movl 0x24(%rsp), %eax
andl $0x2000, %eax           # imm = 0x2000
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfbbe9
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x60(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0x60(%rax)
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
andl $-0x11, %ecx
movl %ecx, 0x8(%rax)
movl 0x24(%rsp), %eax
andl $0x100, %eax            # imm = 0x100
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfbc13
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
andl $0xffffbfff, %ecx       # imm = 0xFFFFBFFF
movl %ecx, 0x8(%rax)
movl 0x24(%rsp), %eax
andl $0x80, %eax
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfbd27
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0xc0(%rax), %rsi
callq 0x1136d0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0xd0(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0xc0(%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0xd0(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0xd8(%rax)
je 0xfbd16
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
movq 0x28(%rsp), %rcx
movzbl 0xe1(%rcx), %ecx
cmpl %ecx, %eax
jge 0xfbcf0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0xd8(%rax), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq 0xd8(%rax), %rax
movslq 0x18(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0xfbc97
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0xd8(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0xd8(%rax)
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
andl $0xfffffbff, %ecx       # imm = 0xFFFFFBFF
movl %ecx, 0x8(%rax)
movl 0x24(%rsp), %eax
andl $0x10, %eax
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfbd9b
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0xf8(%rax), %rsi
callq 0x1136d0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x100(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0xf8(%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0x100(%rax)
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
andl $0xffffefff, %ecx       # imm = 0xFFFFEFFF
movl %ecx, 0x8(%rax)
movl 0x24(%rsp), %eax
andl $0x20, %eax
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfbef7
cmpl $-0x1, 0x20(%rsp)
je 0xfbe63
movq 0x28(%rsp), %rax
cmpq $0x0, 0x110(%rax)
je 0xfbe5e
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x110(%rax), %rax
movslq 0x20(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x1136d0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x110(%rax), %rax
movslq 0x20(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq 0x110(%rax), %rax
movslq 0x20(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movq 0x28(%rsp), %rax
movq 0x110(%rax), %rax
movslq 0x20(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq $0x0, 0x10(%rax)
jmp 0xfbef5
movq 0x28(%rsp), %rax
cmpl $0x0, 0x118(%rax)
je 0xfbee4
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl 0x118(%rcx), %eax
jge 0xfbeaf
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x14(%rsp), %ecx
movl $0x20, %edx
callq 0xfba80
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xfbe79
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x110(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0x110(%rax)
movq 0x28(%rsp), %rax
movl $0x0, 0x118(%rax)
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
andl $0xffffdfff, %ecx       # imm = 0xFFFFDFFF
movl %ecx, 0x8(%rax)
jmp 0xfbef7
movq 0x30(%rsp), %rax
cmpq $0x0, 0x468(%rax)
je 0xfbf2c
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x468(%rax), %rsi
callq 0x1136d0
movq 0x30(%rsp), %rax
movq $0x0, 0x468(%rax)
movl 0x24(%rsp), %eax
andl $0x200, %eax            # imm = 0x200
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfc034
cmpl $-0x1, 0x20(%rsp)
je 0xfbfaa
movq 0x28(%rsp), %rax
cmpq $0x0, 0xe8(%rax)
je 0xfbfa5
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0xe8(%rax), %rax
movslq 0x20(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq 0xe8(%rax), %rax
movslq 0x20(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
jmp 0xfc032
movq 0x28(%rsp), %rax
cmpq $0x0, 0xf0(%rax)
je 0xfc030
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x28(%rsp), %rcx
movq 0xf0(%rcx), %rcx
cmpl %ecx, %eax
jge 0xfbffa
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x10(%rsp), %ecx
movl $0x200, %edx            # imm = 0x200
callq 0xfba80
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0xfbfc1
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0xe8(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0xe8(%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0xf0(%rax)
jmp 0xfc032
jmp 0xfc034
movl 0x24(%rsp), %eax
andl $0x8, %eax
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfc07f
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x98(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0x98(%rax)
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
andl $-0x41, %ecx
movl %ecx, 0x8(%rax)
movl 0x24(%rsp), %eax
andl $0x1000, %eax           # imm = 0x1000
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfc0d1
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xfb710
movq 0x28(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
andl $-0x9, %ecx
movl %ecx, 0x8(%rax)
movq 0x28(%rsp), %rax
movw $0x0, 0x20(%rax)
movl 0x24(%rsp), %eax
andl $0x40, %eax
movq 0x28(%rsp), %rcx
andl 0xe4(%rcx), %eax
cmpl $0x0, %eax
je 0xfc192
movq 0x28(%rsp), %rax
cmpq $0x0, 0x140(%rax)
je 0xfc180
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jge 0xfc15a
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x140(%rax), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq 0x140(%rax), %rax
movslq 0xc(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0xfc107
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x140(%rax), %rsi
callq 0x1136d0
movq 0x28(%rsp), %rax
movq $0x0, 0x140(%rax)
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
andq $-0x8001, %rcx          # imm = 0xFFFF7FFF
movl %ecx, 0x8(%rax)
cmpl $-0x1, 0x20(%rsp)
jne 0xfc1b3
movl 0x24(%rsp), %ecx
xorl $-0x1, %ecx
movq 0x28(%rsp), %rax
andl 0xe4(%rax), %ecx
movl %ecx, 0xe4(%rax)
jmp 0xfc1d1
movl 0x24(%rsp), %ecx
andl $0xffffbddf, %ecx       # imm = 0xFFFFBDDF
xorl $-0x1, %ecx
movq 0x28(%rsp), %rax
andl 0xe4(%rax), %ecx
movl %ecx, 0xe4(%rax)
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)