// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_zTXt
void /* PRIVATE */
png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   png_textp text_ptr;
   png_charp text;
   int comp_type;
   int ret;
   png_size_t slength, prefix_len, data_len;

   png_debug(1, "in png_handle_zTXt");

#ifdef PNG_USER_LIMITS_SUPPORTED
   if (png_ptr->user_chunk_cache_max != 0)
   {
      if (png_ptr->user_chunk_cache_max == 1)
      {
         png_crc_finish(png_ptr, length);
         return;
      }
      if (--png_ptr->user_chunk_cache_max == 1)
      {
         png_warning(png_ptr, "No space in chunk cache for zTXt");
         png_crc_finish(png_ptr, length);
         return;
      }
   }
#endif

   if (!(png_ptr->mode & PNG_HAVE_IHDR))
      png_error(png_ptr, "Missing IHDR before zTXt");

   if (png_ptr->mode & PNG_HAVE_IDAT)
      png_ptr->mode |= PNG_AFTER_IDAT;

#ifdef PNG_MAX_MALLOC_64K
   /* We will no doubt have problems with chunks even half this size, but
      there is no hard and fast rule to tell us where to stop. */
   if (length > (png_uint_32)65535L)
   {
     png_warning(png_ptr, "zTXt chunk too large to fit in memory");
     png_crc_finish(png_ptr, length);
     return;
   }
#endif

   png_free(png_ptr, png_ptr->chunkdata);
   png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
   if (png_ptr->chunkdata == NULL)
   {
     png_warning(png_ptr, "Out of memory processing zTXt chunk");
     return;
   }
   slength = (png_size_t)length;
   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
   if (png_crc_finish(png_ptr, 0))
   {
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }

   png_ptr->chunkdata[slength] = 0x00;

   for (text = png_ptr->chunkdata; *text; text++)
      /* Empty loop */ ;

   /* zTXt must have some text after the chunkdataword */
   if (text >= png_ptr->chunkdata + slength - 2)
   {
      png_warning(png_ptr, "Truncated zTXt chunk");
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }
   else
   {
       comp_type = *(++text);
       if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
       {
          png_warning(png_ptr, "Unknown compression type in zTXt chunk");
          comp_type = PNG_TEXT_COMPRESSION_zTXt;
       }
       text++;        /* Skip the compression_method byte */
   }
   prefix_len = text - png_ptr->chunkdata;

   png_decompress_chunk(png_ptr, comp_type,
     (png_size_t)length, prefix_len, &data_len);

   text_ptr = (png_textp)png_malloc_warn(png_ptr,
      png_sizeof(png_text));
   if (text_ptr == NULL)
   {
     png_warning(png_ptr, "Not enough memory to process zTXt chunk");
     png_free(png_ptr, png_ptr->chunkdata);
     png_ptr->chunkdata = NULL;
     return;
   }
   text_ptr->compression = comp_type;
   text_ptr->key = png_ptr->chunkdata;
#ifdef PNG_iTXt_SUPPORTED
   text_ptr->lang = NULL;
   text_ptr->lang_key = NULL;
   text_ptr->itxt_length = 0;
#endif
   text_ptr->text = png_ptr->chunkdata + prefix_len;
   text_ptr->text_length = data_len;

   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);

   png_free(png_ptr, text_ptr);
   png_free(png_ptr, png_ptr->chunkdata);
   png_ptr->chunkdata = NULL;
   if (ret)
     png_error(png_ptr, "Insufficient memory to store zTXt chunk");
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movq 0x40(%rsp), %rax
cmpl $0x0, 0x45c(%rax)
je 0x126d10
movq 0x40(%rsp), %rax
cmpl $0x1, 0x45c(%rax)
jne 0x126cd1
movq 0x40(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x122b90
jmp 0x127063
movq 0x40(%rsp), %rcx
movl 0x45c(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x45c(%rcx)
cmpl $0x1, %eax
jne 0x126d0e
movq 0x40(%rsp), %rdi
leaq 0x19074(%rip), %rsi     # 0x13fd6a
callq 0x113940
movq 0x40(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x122b90
jmp 0x127063
jmp 0x126d10
movq 0x40(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x126d34
movq 0x40(%rsp), %rdi
leaq 0x1905c(%rip), %rsi     # 0x13fd8b
callq 0x113860
movq 0x40(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x126d5b
movq 0x40(%rsp), %rax
movl 0x11c(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x11c(%rax)
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
callq 0x1136d0
movq 0x40(%rsp), %rdi
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x113760
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x488(%rax)
movq 0x40(%rsp), %rax
cmpq $0x0, 0x488(%rax)
jne 0x126dba
movq 0x40(%rsp), %rdi
leaq 0x18ff4(%rip), %rsi     # 0x13fda4
callq 0x113940
jmp 0x127063
movl 0x34(%rsp), %eax
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
movq 0x10(%rsp), %rdx
callq 0x122b40
movq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x122b90
cmpl $0x0, %eax
je 0x126e1a
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
callq 0x1136d0
movq 0x40(%rsp), %rax
movq $0x0, 0x488(%rax)
jmp 0x127063
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rax
movq 0x10(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpb $0x0, (%rax)
je 0x126e5c
jmp 0x126e4c
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x126e40
movq 0x20(%rsp), %rax
movq 0x40(%rsp), %rcx
movq 0x488(%rcx), %rcx
addq 0x10(%rsp), %rcx
addq $-0x2, %rcx
cmpq %rcx, %rax
jb 0x126eb7
movq 0x40(%rsp), %rdi
leaq 0x18f41(%rip), %rsi     # 0x13fdc8
callq 0x113940
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
callq 0x1136d0
movq 0x40(%rsp), %rax
movq $0x0, 0x488(%rax)
jmp 0x127063
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rsp)
movsbl 0x1(%rax), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
je 0x126ef0
movq 0x40(%rsp), %rdi
leaq 0x18efa(%rip), %rsi     # 0x13fddd
callq 0x113940
movl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x40(%rsp), %rcx
movq 0x488(%rcx), %rcx
subq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movl 0x1c(%rsp), %esi
movl 0x34(%rsp), %eax
movl %eax, %edx
movq 0x8(%rsp), %rcx
movq %rsp, %r8
callq 0x122dc0
movq 0x40(%rsp), %rdi
movl $0x38, %esi
callq 0x113760
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x126f8b
movq 0x40(%rsp), %rdi
leaq 0x18ea9(%rip), %rsi     # 0x13fe04
callq 0x113940
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
callq 0x1136d0
movq 0x40(%rsp), %rax
movq $0x0, 0x488(%rax)
jmp 0x127063
movl 0x1c(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, (%rax)
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0x28(%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0x30(%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0x20(%rax)
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rcx
addq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x10(%rax)
movq (%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl $0x1, %ecx
callq 0xfdf00
movl %eax, 0x18(%rsp)
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x1136d0
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
callq 0x1136d0
movq 0x40(%rsp), %rax
movq $0x0, 0x488(%rax)
cmpl $0x0, 0x18(%rsp)
je 0x127063
movq 0x40(%rsp), %rdi
leaq 0x18dce(%rip), %rsi     # 0x13fe2c
callq 0x113860
addq $0x48, %rsp
retq
nopl (%rax,%rax)