// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_decompress_chunk
void /* PRIVATE */
png_decompress_chunk(png_structp png_ptr, int comp_type,
    png_size_t chunklength,
    png_size_t prefix_size, png_size_t *newlength)
{
   /* The caller should guarantee this */
   if (prefix_size > chunklength)
   {
      /* The recovery is to delete the chunk. */
      png_warning(png_ptr, "invalid chunklength");
      prefix_size = 0; /* To delete everything */
   }

   else if (comp_type == PNG_COMPRESSION_TYPE_BASE)
   {
      png_size_t expanded_size = png_inflate(png_ptr,
                (png_bytep)(png_ptr->chunkdata + prefix_size),
                chunklength - prefix_size,
                0/*output*/, 0/*output size*/);

      /* Now check the limits on this chunk - if the limit fails the
       * compressed data will be removed, the prefix will remain.
       */
#ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
      if (png_ptr->user_chunk_malloc_max &&
          (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1))
#else
#  ifdef PNG_USER_CHUNK_MALLOC_MAX
      if ((PNG_USER_CHUNK_MALLOC_MAX > 0) &&
          prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1)
#  endif
#endif
         png_warning(png_ptr, "Exceeded size limit while expanding chunk");

      /* If the size is zero either there was an error and a message
       * has already been output (warning) or the size really is zero
       * and we have nothing to do - the code will exit through the
       * error case below.
       */
#if defined(PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED) || \
    defined(PNG_USER_CHUNK_MALLOC_MAX)
      else
#endif
      if (expanded_size > 0)
      {
         /* Success (maybe) - really uncompress the chunk. */
         png_size_t new_size = 0;
         png_charp text = png_malloc_warn(png_ptr,
                        prefix_size + expanded_size + 1);

         if (text != NULL)
         {
            png_memcpy(text, png_ptr->chunkdata, prefix_size);
            new_size = png_inflate(png_ptr,
                (png_bytep)(png_ptr->chunkdata + prefix_size),
                chunklength - prefix_size,
                (png_bytep)(text + prefix_size), expanded_size);
            text[prefix_size + expanded_size] = 0; /* just in case */

            if (new_size == expanded_size)
            {
               png_free(png_ptr, png_ptr->chunkdata);
               png_ptr->chunkdata = text;
               *newlength = prefix_size + expanded_size;
               return; /* The success return! */
            }

            png_warning(png_ptr, "png_inflate logic error");
            png_free(png_ptr, text);
         }
         else
          png_warning(png_ptr, "Not enough memory to decompress chunk");
      }
   }

   else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
   {
#ifdef PNG_STDIO_SUPPORTED
      char umsg[50];

      png_snprintf(umsg, sizeof umsg, "Unknown zTXt compression type %d",
          comp_type);
      png_warning(png_ptr, umsg);
#else
      png_warning(png_ptr, "Unknown zTXt compression type");
#endif

      /* The recovery is to simply drop the data. */
   }

   /* Generic error return - leave the prefix, delete the compressed
    * data, reallocate the chunkdata to remove the potentially large
    * amount of compressed data.
    */
   {
      png_charp text = png_malloc_warn(png_ptr, prefix_size + 1);
      if (text != NULL)
      {
         if (prefix_size > 0)
            png_memcpy(text, png_ptr->chunkdata, prefix_size);
         png_free(png_ptr, png_ptr->chunkdata);
         png_ptr->chunkdata = text;

         /* This is an extra zero in the 'uncompressed' part. */
         *(png_ptr->chunkdata + prefix_size) = 0x00;
      }
      /* Ignore a malloc error here - it is safe. */
   }

   *newlength = prefix_size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %r14
subq %rcx, %r12
jae 0x8b83d
leaq 0x17cf5(%rip), %rsi     # 0xa3522
movq %r14, %rdi
callq 0x84a53
xorl %r15d, %r15d
jmp 0x8b940
movl %esi, %ecx
testl %esi, %esi
je 0x8b867
leaq 0x17d54(%rip), %rdx     # 0xa359e
leaq 0x10(%rsp), %r12
pushq $0x32
popq %rsi
movq %r12, %rdi
xorl %eax, %eax
callq 0xe780
movq %r14, %rdi
movq %r12, %rsi
jmp 0x8b93b
movq 0x488(%r14), %rsi
addq %r15, %rsi
movq %r14, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x8b9b4
movq %rax, %r13
movq 0x1d8(%r14), %rax
testq %rax, %rax
je 0x8b8a0
leaq (%r15,%r13), %rcx
decq %rax
cmpq %rax, %rcx
jae 0x8b928
testq %r13, %r13
je 0x8b940
leaq (%r15,%r13), %rsi
incq %rsi
movq %r14, %rdi
callq 0x84960
testq %rax, %rax
je 0x8b931
movq %rax, %rbp
leaq (%r15,%r13), %rax
movq %rax, 0x8(%rsp)
movq 0x488(%r14), %rsi
movq %rbp, %rdi
movq %r15, %rdx
callq 0xe380
movq 0x488(%r14), %rsi
addq %r15, %rsi
movq %rbp, %rcx
addq %r15, %rcx
movq %r14, %rdi
movq %r12, %rdx
movq 0x8(%rsp), %r12
movq %r13, %r8
callq 0x8b9b4
movb $0x0, (%rbp,%r12)
cmpq %r13, %rax
jne 0x8b998
movq 0x488(%r14), %rsi
movq %r14, %rdi
callq 0x84923
movq %rbp, 0x488(%r14)
movq %r12, %r15
jmp 0x8b986
leaq 0x17c07(%rip), %rsi     # 0xa3536
jmp 0x8b938
leaq 0x17c40(%rip), %rsi     # 0xa3578
movq %r14, %rdi
callq 0x84a53
leaq 0x1(%r15), %rsi
movq %r14, %rdi
callq 0x84960
testq %rax, %rax
je 0x8b986
movq %rax, %r12
testq %r15, %r15
je 0x8b96b
movq 0x488(%r14), %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0xe380
movq 0x488(%r14), %rsi
movq %r14, %rdi
callq 0x84923
movq %r12, 0x488(%r14)
movb $0x0, (%r12,%r15)
movq %r15, (%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17bc1(%rip), %rsi     # 0xa3560
movq %r14, %rdi
callq 0x84a53
movq %r14, %rdi
movq %rbp, %rsi
callq 0x84923
jmp 0x8b940