// File: 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:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movl %ecx, 0x44(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0xfdf2e
cmpq $0x0, 0x50(%rsp)
je 0xfdf2e
cmpl $0x0, 0x44(%rsp)
jne 0xfdf3b
movl $0x0, 0x64(%rsp)
jmp 0xfe489
movq 0x50(%rsp), %rax
movl 0x3c(%rax), %eax
addl 0x44(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl 0x40(%rcx), %eax
jle 0xfe07e
movq 0x50(%rsp), %rax
cmpq $0x0, 0x48(%rax)
je 0xfe00e
movq 0x50(%rsp), %rax
movl 0x40(%rax), %eax
movl %eax, 0x34(%rsp)
movq 0x50(%rsp), %rax
movl 0x3c(%rax), %ecx
addl 0x44(%rsp), %ecx
addl $0x8, %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x40(%rax)
movq 0x50(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rax
movslq 0x40(%rax), %rax
imulq $0x38, %rax, %rsi
callq 0x113760
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x50(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jne 0xfdfe1
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1136d0
movl $0x1, 0x64(%rsp)
jmp 0xfe489
movq 0x50(%rsp), %rax
movq 0x48(%rax), %rdi
movq 0x38(%rsp), %rsi
movslq 0x34(%rsp), %rax
imulq $0x38, %rax, %rdx
callq 0xf3d0
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1136d0
jmp 0xfe07c
movl 0x44(%rsp), %ecx
addl $0x8, %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x40(%rax)
movq 0x50(%rsp), %rax
movl $0x0, 0x3c(%rax)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rax
movslq 0x40(%rax), %rax
imulq $0x38, %rax, %rsi
callq 0x113760
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x50(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jne 0xfe065
movl $0x1, 0x64(%rsp)
jmp 0xfe489
movq 0x50(%rsp), %rax
movl 0xe4(%rax), %ecx
orl $0x4000, %ecx           # imm = 0x4000
movl %ecx, 0xe4(%rax)
jmp 0xfe07e
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0xfe481
movq 0x50(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x50(%rsp), %rcx
movslq 0x3c(%rcx), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0xfe0cf
jmp 0xfe471
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0xf200
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jg 0xfe11b
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
jmp 0xfe1a1
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x28(%rax)
je 0xfe154
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rdi
callq 0xf200
movq %rax, 0x18(%rsp)
jmp 0xfe15d
movq $0x0, 0x18(%rsp)
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x30(%rax)
je 0xfe196
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rdi
callq 0xf200
movq %rax, 0x10(%rsp)
jmp 0xfe19f
movq $0x0, 0x10(%rsp)
jmp 0xfe1a1
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x10(%rax)
je 0xfe1d6
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xfe20f
movq $0x0, 0x28(%rsp)
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jle 0xfe202
movq 0x8(%rsp), %rax
movl $0x1, (%rax)
jmp 0xfe20d
movq 0x8(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0xfe248
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
callq 0xf200
movq %rax, 0x28(%rsp)
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movq 0x58(%rsp), %rdi
movq 0x20(%rsp), %rsi
addq 0x28(%rsp), %rsi
addq 0x18(%rsp), %rsi
addq 0x10(%rsp), %rsi
addq $0x4, %rsi
callq 0x113760
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xfe28f
movl $0x1, 0x64(%rsp)
jmp 0xfe489
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
movq 0x20(%rsp), %rdx
callq 0xf3d0
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jle 0xfe3aa
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rcx
addq 0x20(%rsp), %rcx
addq $0x1, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rsi
movq 0x18(%rsp), %rdx
callq 0xf3d0
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x18(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rcx
addq 0x18(%rsp), %rcx
addq $0x1, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rsi
movq 0x10(%rsp), %rdx
callq 0xf3d0
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x10(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rcx
addq 0x10(%rsp), %rcx
addq $0x1, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0xfe3df
movq 0x8(%rsp), %rax
movq $0x0, 0x28(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x30(%rax)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rcx
addq 0x20(%rsp), %rcx
addq $0x1, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, 0x28(%rsp)
je 0xfe40f
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
movq 0x28(%rsp), %rdx
callq 0xf3d0
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x28(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jle 0xfe448
movq 0x8(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x28(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x20(%rax)
jmp 0xfe463
movq 0x28(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x20(%rax)
movq 0x50(%rsp), %rax
movl 0x3c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x3c(%rax)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xfe086
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)