// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl 0x45c(%rdi), %eax
testl %eax, %eax
je 0x8d97f
cmpl $0x1, %eax
je 0x8d966
decl %eax
movl %eax, 0x45c(%rbx)
cmpl $0x1, %eax
jne 0x8d97f
leaq 0x167ac(%rip), %rsi     # 0xa410a
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
movl %r15d, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b703
movl 0x11c(%rbx), %eax
testb $0x1, %al
jne 0x8d99e
leaq 0x1679b(%rip), %rsi     # 0xa412b
movq %rbx, %rdi
callq 0x849c0
movl 0x11c(%rbx), %eax
testb $0x4, %al
je 0x8d9ab
orl $0x8, %eax
movl %eax, 0x11c(%rbx)
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x84960
movq %rax, 0x488(%rbx)
testq %rax, %rax
je 0x8dafe
movl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x8b6d7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8b703
movq 0x488(%rbx), %rsi
testl %eax, %eax
jne 0x8db3a
movb $0x0, (%rsi,%r15)
movq 0x488(%rbx), %r13
leaq 0x1(%r13), %r12
leaq -0x1(%r13), %rax
incq %r12
cmpb $0x0, 0x1(%rax)
leaq 0x1(%rax), %rax
jne 0x8da14
leaq (%r15,%r13), %rcx
addq $-0x2, %rcx
cmpq %rcx, %rax
jae 0x8db1b
cmpb $0x0, 0x1(%rax)
je 0x8da4e
leaq 0x1673e(%rip), %rsi     # 0xa417d
movq %rbx, %rdi
callq 0x84a53
movq 0x488(%rbx), %r13
movq %r12, %rcx
subq %r13, %rcx
movq %rsp, %r8
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x8b807
pushq $0x38
popq %rsi
movq %rbx, %rdi
callq 0x84960
testq %rax, %rax
je 0x8db24
movq %rax, %r15
andl $0x0, (%rax)
movq 0x488(%rbx), %rax
movq %rax, 0x8(%r15)
subq %r13, %rax
addq %r12, %rax
xorps %xmm0, %xmm0
andq $0x0, 0x30(%r15)
movups %xmm0, 0x20(%r15)
movq %rax, 0x10(%r15)
movq (%rsp), %rax
movq %rax, 0x18(%r15)
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7b6e5
movl %eax, %ebp
movq %rbx, %rdi
movq %r15, %rsi
callq 0x84923
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
andq $0x0, 0x488(%rbx)
testl %ebp, %ebp
je 0x8db4a
leaq 0x166e4(%rip), %rsi     # 0xa41cc
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x849c0
leaq 0x1663f(%rip), %rsi     # 0xa4144
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x84a53
leaq 0x16646(%rip), %rsi     # 0xa4168
jmp 0x8db2b
leaq 0x16679(%rip), %rsi     # 0xa41a4
movq %rbx, %rdi
callq 0x84a53
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
andq $0x0, 0x488(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq