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

   png_debug(1, "in png_handle_tEXt");

#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 tEXt");
         png_crc_finish(png_ptr, length);
         return;
      }
   }
#endif

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

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

#ifdef PNG_MAX_MALLOC_64K
   if (length > (png_uint_32)65535L)
   {
      png_warning(png_ptr, "tEXt chunk too large to fit in memory");
      skip = length - (png_uint_32)65535L;
      length = (png_uint_32)65535L;
   }
#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, "No memory to process text chunk");
     return;
   }
   slength = (png_size_t)length;
   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);

   if (png_crc_finish(png_ptr, skip))
   {
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }

   key = png_ptr->chunkdata;

   key[slength] = 0x00;

   for (text = key; *text; text++)
      /* Empty loop to find end of key */ ;

   if (text != key + slength)
      text++;

   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 text chunk");
     png_free(png_ptr, png_ptr->chunkdata);
     png_ptr->chunkdata = NULL;
     return;
   }
   text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
   text_ptr->key = key;
#ifdef PNG_iTXt_SUPPORTED
   text_ptr->lang = NULL;
   text_ptr->lang_key = NULL;
   text_ptr->itxt_length = 0;
#endif
   text_ptr->text = text;
   text_ptr->text_length = png_strlen(text);

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

   png_free(png_ptr, png_ptr->chunkdata);
   png_ptr->chunkdata = NULL;
   png_free(png_ptr, text_ptr);
   if (ret)
     png_warning(png_ptr, "Insufficient memory to process text chunk");
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x40(%rsp), %rax
cmpl $0x0, 0x45c(%rax)
je 0x1269e8
movq 0x40(%rsp), %rax
cmpl $0x1, 0x45c(%rax)
jne 0x1269a9
movq 0x40(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x122b90
jmp 0x126c81
movq 0x40(%rsp), %rcx
movl 0x45c(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x45c(%rcx)
cmpl $0x1, %eax
jne 0x1269e6
movq 0x40(%rsp), %rdi
leaq 0x192f0(%rip), %rsi     # 0x13fcbe
callq 0x113940
movq 0x40(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x122b90
jmp 0x126c81
jmp 0x1269e8
movq 0x40(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x126a0c
movq 0x40(%rsp), %rdi
leaq 0x192d8(%rip), %rsi     # 0x13fcdf
callq 0x113860
movq 0x40(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x126a33
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 0x126a92
movq 0x40(%rsp), %rdi
leaq 0x19270(%rip), %rsi     # 0x13fcf8
callq 0x113940
jmp 0x126c81
movl 0x34(%rsp), %eax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
movq 0x8(%rsp), %rdx
callq 0x122b40
movq 0x40(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
cmpl $0x0, %eax
je 0x126af4
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
callq 0x1136d0
movq 0x40(%rsp), %rax
movq $0x0, 0x488(%rax)
jmp 0x126c81
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x8(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpb $0x0, (%rax)
je 0x126b39
jmp 0x126b29
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0x126b1d
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
addq 0x8(%rsp), %rcx
cmpq %rcx, %rax
je 0x126b5b
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
movq 0x40(%rsp), %rdi
movl $0x38, %esi
callq 0x113760
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x126bb3
movq 0x40(%rsp), %rdi
leaq 0x19195(%rip), %rsi     # 0x13fd18
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 0x126c81
movq 0x28(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x20(%rsp), %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 0x18(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rdi
callq 0xf200
movq %rax, %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, 0x4(%rsp)
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x488(%rax), %rsi
callq 0x1136d0
movq 0x40(%rsp), %rax
movq $0x0, 0x488(%rax)
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x1136d0
cmpl $0x0, 0x4(%rsp)
je 0x126c81
movq 0x40(%rsp), %rdi
leaq 0x190c4(%rip), %rsi     # 0x13fd40
callq 0x113940
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)