// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/png/pngset.c
// Function: png_set_text_2
int /* PRIVATE */
png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
               int num_text)
{
   int i;

   png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
      png_ptr->chunk_name[0] == '\0') ?
      "text" : (png_const_charp)png_ptr->chunk_name));

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

   /* Make sure we have enough space in the "text" array in info_struct
    * to hold all of the incoming text_ptr objects.
    */
   if (info_ptr->num_text + num_text > info_ptr->max_text)
   {
      if (info_ptr->text != NULL)
      {
         png_textp old_text;
         int old_max;

         old_max = info_ptr->max_text;
         info_ptr->max_text = info_ptr->num_text + num_text + 8;
         old_text = info_ptr->text;
         info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
            (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
         if (info_ptr->text == NULL)
         {
            png_free(png_ptr, old_text);
            return(1);
         }
         png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
            png_sizeof(png_text)));
         png_free(png_ptr, old_text);
      }
      else
      {
         info_ptr->max_text = num_text + 8;
         info_ptr->num_text = 0;
         info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
            (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
         if (info_ptr->text == NULL)
            return(1);
         info_ptr->free_me |= PNG_FREE_TEXT;
      }
      png_debug1(3, "allocated %d entries for info_ptr->text",
         info_ptr->max_text);
   }
   for (i = 0; i < num_text; i++)
   {
      png_size_t text_length, key_len;
      png_size_t lang_len, lang_key_len;
      png_textp textp = &(info_ptr->text[info_ptr->num_text]);

      if (text_ptr[i].key == NULL)
          continue;

      key_len = png_strlen(text_ptr[i].key);

      if (text_ptr[i].compression <= 0)
      {
         lang_len = 0;
         lang_key_len = 0;
      }

      else
#ifdef PNG_iTXt_SUPPORTED
      {
         /* Set iTXt data */

         if (text_ptr[i].lang != NULL)
            lang_len = png_strlen(text_ptr[i].lang);
         else
            lang_len = 0;
         if (text_ptr[i].lang_key != NULL)
            lang_key_len = png_strlen(text_ptr[i].lang_key);
         else
            lang_key_len = 0;
      }
#else /* PNG_iTXt_SUPPORTED */
      {
         png_warning(png_ptr, "iTXt chunk not supported");
         continue;
      }
#endif

      if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
      {
         text_length = 0;
#ifdef PNG_iTXt_SUPPORTED
         if (text_ptr[i].compression > 0)
            textp->compression = PNG_ITXT_COMPRESSION_NONE;
         else
#endif
            textp->compression = PNG_TEXT_COMPRESSION_NONE;
      }

      else
      {
         text_length = png_strlen(text_ptr[i].text);
         textp->compression = text_ptr[i].compression;
      }

      textp->key = (png_charp)png_malloc_warn(png_ptr,
         (png_size_t)
         (key_len + text_length + lang_len + lang_key_len + 4));
      if (textp->key == NULL)
         return(1);
      png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
                 (unsigned long)(png_uint_32)
                 (key_len + lang_len + lang_key_len + text_length + 4),
                 (int)textp->key);

      png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
      *(textp->key + key_len) = '\0';
#ifdef PNG_iTXt_SUPPORTED
      if (text_ptr[i].compression > 0)
      {
         textp->lang = textp->key + key_len + 1;
         png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
         *(textp->lang + lang_len) = '\0';
         textp->lang_key = textp->lang + lang_len + 1;
         png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
         *(textp->lang_key + lang_key_len) = '\0';
         textp->text = textp->lang_key + lang_key_len + 1;
      }
      else
#endif
      {
#ifdef PNG_iTXt_SUPPORTED
         textp->lang=NULL;
         textp->lang_key=NULL;
#endif
         textp->text = textp->key + key_len + 1;
      }
      if (text_length)
         png_memcpy(textp->text, text_ptr[i].text,
            (png_size_t)(text_length));
      *(textp->text + text_length) = '\0';

#ifdef PNG_iTXt_SUPPORTED
      if (textp->compression > 0)
      {
         textp->text_length = 0;
         textp->itxt_length = text_length;
      }
      else
#endif

      {
         textp->text_length = text_length;
#ifdef PNG_iTXt_SUPPORTED
         textp->itxt_length = 0;
#endif
      }
      info_ptr->num_text++;
      png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
   }
   return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r12d
movq %rdx, 0x8(%rsp)
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
testl %r12d, %r12d
sete %al
xorl %ebx, %ebx
orb %cl, %al
jne 0x89441
movq %rsi, %rbp
movq %rdi, %r15
movslq 0x3c(%rsi), %rcx
movslq %r12d, %rax
addq %rcx, %rax
movslq 0x40(%rsi), %r14
cmpl %r14d, %eax
jle 0x89227
movq 0x48(%rbp), %r13
testq %r13, %r13
je 0x891f6
addq $0x8, %rax
movl %eax, 0x40(%rbp)
imulq $0x38, %rax, %rsi
movq %r15, %rdi
callq 0x92d72
movq %rax, 0x48(%rbp)
testq %rax, %rax
je 0x89431
imulq $0x38, %r14, %rdx
movq %rax, %rdi
movq %r13, %rsi
callq 0xe370
movq %r15, %rdi
movq %r13, %rsi
callq 0x92d32
jmp 0x89227
leal 0x8(%r12), %eax
movl %eax, 0x40(%rbp)
movl $0x0, 0x3c(%rbp)
cltq
imulq $0x38, %rax, %rsi
movq %r15, %rdi
callq 0x92d72
movq %rax, 0x48(%rbp)
testq %rax, %rax
je 0x8943c
orb $0x40, 0xe5(%rbp)
testl %r12d, %r12d
jle 0x89441
movq %r15, 0x28(%rsp)
movl %r12d, %eax
imulq $0x38, %rax, %r13
xorl %r15d, %r15d
movq 0x8(%rsp), %rbx
movq %rbp, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movq 0x8(%rbx,%r15), %rdi
testq %rdi, %rdi
je 0x8928a
movslq 0x3c(%rbp), %rax
imulq $0x38, %rax, %r14
addq 0x48(%rbp), %r14
callq 0xe1e0
movq %rax, %r12
movl (%rbx,%r15), %ebp
testl %ebp, %ebp
jle 0x89294
movq 0x28(%rbx,%r15), %rdi
testq %rdi, %rdi
je 0x8929f
callq 0xe1e0
movq %rax, 0x10(%rsp)
jmp 0x892a8
movl $0x4, %eax
jmp 0x8941c
movq $0x0, 0x10(%rsp)
jmp 0x892bc
movq $0x0, 0x10(%rsp)
movq 0x30(%rbx,%r15), %rdi
testq %rdi, %rdi
je 0x892bc
callq 0xe1e0
movq %rax, %rcx
jmp 0x892be
xorl %ecx, %ecx
movq 0x10(%rbx,%r15), %rdi
testq %rdi, %rdi
je 0x892dd
cmpb $0x0, (%rdi)
je 0x892dd
movq %rcx, %rbx
callq 0xe1e0
movq %rbx, %rcx
movq %rax, %rbx
jmp 0x892ed
xorl %eax, %eax
testl %ebp, %ebp
setg %al
leal -0x1(,%rax,2), %ebp
xorl %ebx, %ebx
movl %ebp, (%r14)
movq 0x10(%rsp), %rax
addq %r12, %rax
movq %rcx, 0x30(%rsp)
addq %rcx, %rax
leaq (%rbx,%rax), %rsi
addq $0x4, %rsi
movq 0x28(%rsp), %rdi
callq 0x92d72
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x893a4
leaq 0x8(%r14), %rbp
movq 0x8(%rsp), %r13
movq 0x8(%r13,%r15), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0xe370
movq (%rbp), %rax
movb $0x0, (%rax,%r12)
cmpl $0x0, (%r13,%r15)
jle 0x893b5
movq 0x8(%r14), %rax
leaq (%rax,%r12), %rdi
incq %rdi
movq %rdi, 0x28(%r14)
movq 0x28(%r13,%r15), %rsi
movq 0x10(%rsp), %rbp
movq %rbp, %rdx
callq 0xe370
movq 0x28(%r14), %rax
xorl %r12d, %r12d
movb %r12b, (%rax,%rbp)
movq 0x28(%r14), %rax
leaq (%rax,%rbp), %rdi
incq %rdi
leaq 0x30(%r14), %rbp
movq %rdi, 0x30(%r14)
movq 0x30(%r13,%r15), %rsi
movq 0x30(%rsp), %r13
movq %r13, %rdx
callq 0xe370
movq 0x30(%r14), %rax
movb %r12b, (%rax,%r13)
jmp 0x893c0
movl $0x1, %eax
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %rbp
jmp 0x8941c
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%r14)
movq %r12, %r13
movq (%rbp), %rax
addq %r13, %rax
incq %rax
movq %rax, 0x10(%r14)
testq %rbx, %rbx
movq 0x20(%rsp), %r13
je 0x893ee
movq 0x10(%r14), %rdi
movq 0x8(%rsp), %rax
movq 0x10(%rax,%r15), %rsi
movq %rbx, %rdx
callq 0xe370
movq 0x10(%r14), %rax
movb $0x0, (%rax,%rbx)
xorl %eax, %eax
cmpl $0x0, (%r14)
movq %rbx, %rcx
cmovgq %rax, %rcx
cmovleq %rax, %rbx
movq %rcx, 0x18(%r14)
movq %rbx, 0x20(%r14)
movq 0x18(%rsp), %rbp
incl 0x3c(%rbp)
movq 0x8(%rsp), %rbx
testb $0x3, %al
jne 0x8943c
addq $0x38, %r15
cmpq %r15, %r13
jne 0x8924e
xorl %ebx, %ebx
jmp 0x89441
movq %r15, %rdi
movq %r13, %rsi
callq 0x92d32
movl $0x1, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq