// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_iCCP
void /* PRIVATE */
png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Note: this does not properly handle chunks that are > 64K under DOS */
{
   png_byte compression_type;
   png_bytep pC;
   png_charp profile;
   png_uint_32 skip = 0;
   png_uint_32 profile_size, profile_length;
   png_size_t slength, prefix_length, data_length;

   png_debug(1, "in png_handle_iCCP");

   if (!(png_ptr->mode & PNG_HAVE_IHDR))
      png_error(png_ptr, "Missing IHDR before iCCP");
   else if (png_ptr->mode & PNG_HAVE_IDAT)
   {
      png_warning(png_ptr, "Invalid iCCP after IDAT");
      png_crc_finish(png_ptr, length);
      return;
   }
   else if (png_ptr->mode & PNG_HAVE_PLTE)
      /* Should be an error, but we can cope with it */
      png_warning(png_ptr, "Out of place iCCP chunk");

   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
   {
      png_warning(png_ptr, "Duplicate iCCP chunk");
      png_crc_finish(png_ptr, length);
      return;
   }

#ifdef PNG_MAX_MALLOC_64K
   if (length > (png_uint_32)65535L)
   {
      png_warning(png_ptr, "iCCP chunk too large to fit in memory");
      skip = length - (png_uint_32)65535L;
      length = (png_uint_32)65535L;
   }
#endif

   png_free(png_ptr, png_ptr->chunkdata);
   png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
   slength = (png_size_t)length;
   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);

   if (png_crc_finish(png_ptr, skip))
   {
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }

   png_ptr->chunkdata[slength] = 0x00;

   for (profile = png_ptr->chunkdata; *profile; profile++)
      /* Empty loop to find end of name */ ;

   ++profile;

   /* There should be at least one zero (the compression type byte)
    * following the separator, and we should be on it
    */
   if ( profile >= png_ptr->chunkdata + slength - 1)
   {
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      png_warning(png_ptr, "Malformed iCCP chunk");
      return;
   }

   /* Compression_type should always be zero */
   compression_type = *profile++;
   if (compression_type)
   {
      png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
      compression_type = 0x00;  /* Reset it to zero (libpng-1.0.6 through 1.0.8
                                 wrote nonzero) */
   }

   prefix_length = profile - png_ptr->chunkdata;
   png_decompress_chunk(png_ptr, compression_type,
     slength, prefix_length, &data_length);

   profile_length = data_length - prefix_length;

   if ( prefix_length > data_length || profile_length < 4)
   {
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      png_warning(png_ptr, "Profile size field missing from iCCP chunk");
      return;
   }

   /* Check the profile_size recorded in the first 32 bits of the ICC profile */
   pC = (png_bytep)(png_ptr->chunkdata + prefix_length);
   profile_size = ((*(pC    ))<<24) |
                  ((*(pC + 1))<<16) |
                  ((*(pC + 2))<< 8) |
                  ((*(pC + 3))    );

   if (profile_size < profile_length)
      profile_length = profile_size;

   if (profile_size > profile_length)
   {
#ifdef PNG_STDIO_SUPPORTED
         char umsg[50];
#endif
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      png_warning(png_ptr, "Ignoring truncated iCCP profile");
#ifdef PNG_STDIO_SUPPORTED

      png_snprintf(umsg, 50, "declared profile size = %lu",
          (unsigned long)profile_size);
      png_warning(png_ptr, umsg);
      png_snprintf(umsg, 50, "actual profile length = %lu",
          (unsigned long)profile_length);
      png_warning(png_ptr, umsg);
#endif
      return;
   }

   png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata,
     compression_type, png_ptr->chunkdata + prefix_length, profile_length);
   png_free(png_ptr, png_ptr->chunkdata);
   png_ptr->chunkdata = NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl 0x11c(%rdi), %eax
testb $0x1, %al
jne 0x9ab4f
leaq 0x1825f(%rip), %rsi     # 0xb2d2c
movq %rbx, %rdi
callq 0x920b4
testq %r14, %r14
je 0x9aae5
testb $0x10, 0x9(%r14)
jne 0x9ab78
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92016
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x91fa8
movq %rax, 0x488(%rbx)
movl %r15d, %r12d
movq %rbx, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x99b23
movq %rbx, %rdi
xorl %esi, %esi
callq 0x99b4f
movq 0x488(%rbx), %rsi
testl %eax, %eax
je 0x9aba0
movq %rbx, %rdi
callq 0x92016
movq $0x0, 0x488(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x4, %al
jne 0x9ab6f
testb $0x2, %al
je 0x9aad5
leaq 0x181fb(%rip), %rsi     # 0xb2d5d
movq %rbx, %rdi
callq 0x9214d
jmp 0x9aad5
leaq 0x181cf(%rip), %rsi     # 0xb2d45
jmp 0x9ab7f
leaq 0x181f6(%rip), %rsi     # 0xb2d75
movq %rbx, %rdi
callq 0x9214d
movq %rbx, %rdi
movl %r15d, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x99b4f
movb $0x0, (%rsi,%r12)
movq 0x488(%rbx), %r15
xorl %r13d, %r13d
cmpb $0x0, (%r15,%r13)
leaq 0x1(%r13), %r13
jne 0x9abaf
leaq (%r15,%r12), %rax
decq %rax
leaq (%r15,%r13), %rcx
cmpq %rax, %rcx
jae 0x9acd7
cmpb $0x0, (%r15,%r13)
movq %r15, %rcx
je 0x9abee
leaq 0x181c0(%rip), %rsi     # 0xb2d9f
movq %rbx, %rdi
callq 0x9214d
movq 0x488(%rbx), %rcx
movq %r15, %rax
subq %rcx, %rax
leaq (%rax,%r13), %rbp
incq %rbp
leaq 0x8(%rsp), %r8
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rcx, %r12
movq %rbp, %rcx
callq 0x99c5d
leaq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x488(%rbx), %rdx
cmpq %rax, %rbp
ja 0x9acf6
movq %r12, %rcx
movl %r15d, %ebp
notl %ebp
addl %ecx, %ebp
addl %eax, %ebp
subl %r13d, %ebp
cmpl $0x3, %ebp
jbe 0x9acf6
movq %rdx, %rax
subq %rcx, %rax
addq %r15, %rax
movl 0x1(%r13,%rax), %r15d
bswapl %r15d
cmpl %ebp, %r15d
cmovbl %r15d, %ebp
jbe 0x9ad29
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x92016
movq $0x0, 0x488(%rbx)
leaq 0x1817c(%rip), %rsi     # 0xb2dfa
movq %rbx, %rdi
callq 0x9214d
movl %r15d, %ecx
leaq 0x1818a(%rip), %rdx     # 0xb2e1a
leaq 0x10(%rsp), %r14
movl $0x32, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0xe750
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9214d
movl %ebp, %ecx
leaq 0x1817e(%rip), %rdx     # 0xb2e36
movl $0x32, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0xe750
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9214d
jmp 0x9ab40
movq %rbx, %rdi
movq %r15, %rsi
callq 0x92016
movq $0x0, 0x488(%rbx)
leaq 0x18096(%rip), %rsi     # 0xb2d8a
jmp 0x9ad13
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x92016
movq $0x0, 0x488(%rbx)
leaq 0x180bc(%rip), %rsi     # 0xb2dcf
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9214d
leaq (%rax,%r13), %r8
incq %r8
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
movl %ebp, %r9d
callq 0x8822a
movq 0x488(%rbx), %rsi
jmp 0x9ab2d