// File: /workspace/github_cpp_makefile_star2_O3/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 0x99c93
leaq 0x18bef(%rip), %rsi     # 0xb2872
movq %r14, %rdi
callq 0x9214d
xorl %r15d, %r15d
jmp 0x99d98
movl %esi, %ecx
testl %esi, %esi
je 0x99cbf
leaq 0x18c4e(%rip), %rdx     # 0xb28ee
leaq 0x10(%rsp), %r12
movl $0x32, %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0xe750
movq %r14, %rdi
movq %r12, %rsi
jmp 0x99d93
movq 0x488(%r14), %rsi
addq %r15, %rsi
movq %r14, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x99e0c
movq %rax, %r13
movq 0x1d8(%r14), %rax
testq %rax, %rax
je 0x99cf8
leaq (%r15,%r13), %rcx
decq %rax
cmpq %rax, %rcx
jae 0x99d80
testq %r13, %r13
je 0x99d98
leaq (%r15,%r13), %rsi
incq %rsi
movq %r14, %rdi
callq 0x92056
testq %rax, %rax
je 0x99d89
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 0x99e0c
movb $0x0, (%rbp,%r12)
cmpq %r13, %rax
jne 0x99df0
movq 0x488(%r14), %rsi
movq %r14, %rdi
callq 0x92016
movq %rbp, 0x488(%r14)
movq %r12, %r15
jmp 0x99dde
leaq 0x18aff(%rip), %rsi     # 0xb2886
jmp 0x99d90
leaq 0x18b38(%rip), %rsi     # 0xb28c8
movq %r14, %rdi
callq 0x9214d
leaq 0x1(%r15), %rsi
movq %r14, %rdi
callq 0x92056
testq %rax, %rax
je 0x99dde
movq %rax, %r12
testq %r15, %r15
je 0x99dc3
movq 0x488(%r14), %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0xe370
movq 0x488(%r14), %rsi
movq %r14, %rdi
callq 0x92016
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 0x18ab9(%rip), %rsi     # 0xb28b0
movq %r14, %rdi
callq 0x9214d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x92016
jmp 0x99d98