// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_iTXt
void /* PRIVATE */
png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   png_textp text_ptr;
   png_charp key, lang, text, lang_key;
   int comp_flag;
   int comp_type = 0;
   int ret;
   png_size_t slength, prefix_len, data_len;

   png_debug(1, "in png_handle_iTXt");

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

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

   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, "iTXt 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, "No memory to process iTXt 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 (lang = png_ptr->chunkdata; *lang; lang++)
      /* Empty loop */ ;
   lang++;        /* Skip NUL separator */

   /* iTXt must have a language tag (possibly empty), two compression bytes,
    * translated keyword (possibly empty), and possibly some text after the
    * keyword
    */

   if (lang >= png_ptr->chunkdata + slength - 3)
   {
      png_warning(png_ptr, "Truncated iTXt chunk");
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }
   else
   {
       comp_flag = *lang++;
       comp_type = *lang++;
   }

   for (lang_key = lang; *lang_key; lang_key++)
      /* Empty loop */ ;
   lang_key++;        /* Skip NUL separator */

   if (lang_key >= png_ptr->chunkdata + slength)
   {
      png_warning(png_ptr, "Truncated iTXt chunk");
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }

   for (text = lang_key; *text; text++)
      /* Empty loop */ ;
   text++;        /* Skip NUL separator */
   if (text >= png_ptr->chunkdata + slength)
   {
      png_warning(png_ptr, "Malformed iTXt chunk");
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }

   prefix_len = text - png_ptr->chunkdata;

   key=png_ptr->chunkdata;
   if (comp_flag)
       png_decompress_chunk(png_ptr, comp_type,
         (size_t)length, prefix_len, &data_len);
   else
       data_len = png_strlen(png_ptr->chunkdata + prefix_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 iTXt chunk");
     png_free(png_ptr, png_ptr->chunkdata);
     png_ptr->chunkdata = NULL;
     return;
   }
   text_ptr->compression = (int)comp_flag + 1;
   text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key);
   text_ptr->lang = png_ptr->chunkdata + (lang - key);
   text_ptr->itxt_length = data_len;
   text_ptr->text_length = 0;
   text_ptr->key = png_ptr->chunkdata;
   text_ptr->text = png_ptr->chunkdata + prefix_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 iTXt chunk");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl 0x45c(%rdi), %eax
testl %eax, %eax
je 0x8dbb4
cmpl $0x1, %eax
je 0x8db9b
decl %eax
movl %eax, 0x45c(%rbx)
cmpl $0x1, %eax
jne 0x8dbb4
leaq 0x16661(%rip), %rsi     # 0xa41f4
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
movl %r15d, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b703
movl 0x11c(%rbx), %eax
testb $0x1, %al
jne 0x8dbd3
leaq 0x16650(%rip), %rsi     # 0xa4215
movq %rbx, %rdi
callq 0x849c0
movl 0x11c(%rbx), %eax
testb $0x4, %al
je 0x8dbe0
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 0x8dcc0
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 0x8dcf3
movb $0x0, (%rsi,%r15)
movq 0x488(%rbx), %rdi
pushq $0x2
popq %r13
cmpb $0x0, -0x2(%rdi,%r13)
leaq 0x1(%r13), %r13
jne 0x8dc45
leaq (%rdi,%r15), %rax
addq $-0x3, %rax
leaq (%rdi,%r13), %rcx
addq $-0x2, %rcx
cmpq %rax, %rcx
jae 0x8dcdd
leaq (%rdi,%r15), %rax
movsbl -0x2(%rdi,%r13), %edx
movsbl -0x1(%rdi,%r13), %esi
movq %r13, %r12
cmpb $0x0, (%rdi,%r12)
leaq 0x1(%r12), %r12
jne 0x8dc79
leaq (%rdi,%r12), %rcx
cmpq %rax, %rcx
jae 0x8dcdd
movq %r12, %rbp
cmpb $0x0, (%rdi,%rbp)
leaq 0x1(%rbp), %rbp
jne 0x8dc91
addq %rbp, %rdi
cmpq %rax, %rdi
jae 0x8dd12
movl %edx, 0xc(%rsp)
testb %dl, %dl
je 0x8dd1b
leaq 0x10(%rsp), %r8
movq %rbx, %rdi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x8b807
jmp 0x8dd25
leaq 0x16567(%rip), %rsi     # 0xa422e
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x84a53
leaq 0x1656a(%rip), %rsi     # 0xa424e
movq %rbx, %rdi
callq 0x84a53
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
andq $0x0, 0x488(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1654a(%rip), %rsi     # 0xa4263
jmp 0x8dce4
callq 0xe1e0
movq %rax, 0x10(%rsp)
pushq $0x38
popq %rsi
movq %rbx, %rdi
callq 0x84960
testq %rax, %rax
je 0x8ddcd
movq %rax, %r15
movl 0xc(%rsp), %eax
incl %eax
movl %eax, (%r15)
movq 0x488(%rbx), %rax
addq %rax, %r12
movq %r12, 0x30(%r15)
addq %rax, %r13
movq %r13, 0x28(%r15)
movq 0x10(%rsp), %rcx
movq %rcx, 0x20(%r15)
andq $0x0, 0x18(%r15)
movq %rax, 0x8(%r15)
addq %rax, %rbp
movq %rbp, 0x10(%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 0x8dd03
leaq 0x164e9(%rip), %rsi     # 0xa42a0
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x849c0
leaq 0x164a4(%rip), %rsi     # 0xa4278
jmp 0x8dce4