// File: /workspace/github_cpp_makefile_star2_O1/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 0x9a651
leaq 0x181dd(%rip), %rsi     # 0xb281e
movq %r14, %rdi
callq 0x92e6e
xorl %r15d, %r15d
jmp 0x9a756
movl %esi, %ecx
testl %esi, %esi
je 0x9a67d
leaq 0x1823c(%rip), %rdx     # 0xb289a
leaq 0x10(%rsp), %r12
movl $0x32, %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0xe750
movq %r14, %rdi
movq %r12, %rsi
jmp 0x9a751
movq 0x488(%r14), %rsi
addq %r15, %rsi
movq %r14, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x9a7ca
movq %rax, %r13
movq 0x1d8(%r14), %rax
testq %rax, %rax
je 0x9a6b6
leaq (%r15,%r13), %rcx
decq %rax
cmpq %rax, %rcx
jae 0x9a73e
testq %r13, %r13
je 0x9a756
leaq (%r15,%r13), %rsi
incq %rsi
movq %r14, %rdi
callq 0x92d72
testq %rax, %rax
je 0x9a747
movq %rax, %rbp
leaq (%r15,%r13), %rax
movq %rax, 0x8(%rsp)
movq 0x488(%r14), %rsi
movq %rbp, %rdi
movq %r15, %rdx
callq 0xe370
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 0x9a7ca
movb $0x0, (%rbp,%r12)
cmpq %r13, %rax
jne 0x9a7ae
movq 0x488(%r14), %rsi
movq %r14, %rdi
callq 0x92d32
movq %rbp, 0x488(%r14)
movq %r12, %r15
jmp 0x9a79c
leaq 0x180ed(%rip), %rsi     # 0xb2832
jmp 0x9a74e
leaq 0x18126(%rip), %rsi     # 0xb2874
movq %r14, %rdi
callq 0x92e6e
leaq 0x1(%r15), %rsi
movq %r14, %rdi
callq 0x92d72
testq %rax, %rax
je 0x9a79c
movq %rax, %r12
testq %r15, %r15
je 0x9a781
movq 0x488(%r14), %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0xe370
movq 0x488(%r14), %rsi
movq %r14, %rdi
callq 0x92d32
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 0x180a7(%rip), %rsi     # 0xb285c
movq %r14, %rdi
callq 0x92e6e
movq %r14, %rdi
movq %rbp, %rsi
callq 0x92d32
jmp 0x9a756