// File: /workspace/github_cpp_makefile_star2_O2/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 0x8c668
leaq 0x173f3(%rip), %rsi     # 0xa39dc
movq %rbx, %rdi
callq 0x849c0
testq %r14, %r14
je 0x8c601
testb $0x10, 0x9(%r14)
jne 0x8c68d
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x848bb
movq %rax, 0x488(%rbx)
movl %r15d, %r12d
movq %rbx, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x8b6d7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8b703
movq 0x488(%rbx), %rsi
testl %eax, %eax
je 0x8c6b5
movq %rbx, %rdi
callq 0x84923
andq $0x0, 0x488(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x4, %al
jne 0x8c684
testb $0x2, %al
je 0x8c5f1
leaq 0x17396(%rip), %rsi     # 0xa3a0d
movq %rbx, %rdi
callq 0x84a53
jmp 0x8c5f1
leaq 0x1736a(%rip), %rsi     # 0xa39f5
jmp 0x8c694
leaq 0x17391(%rip), %rsi     # 0xa3a25
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
movl %r15d, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b703
movb $0x0, (%rsi,%r12)
movq 0x488(%rbx), %r15
xorl %r13d, %r13d
cmpb $0x0, (%r15,%r13)
leaq 0x1(%r13), %r13
jne 0x8c6c4
leaq (%r15,%r12), %rax
decq %rax
leaq (%r15,%r13), %rcx
cmpq %rax, %rcx
jae 0x8c7e9
cmpb $0x0, (%r15,%r13)
movq %r15, %rcx
je 0x8c703
leaq 0x1735b(%rip), %rsi     # 0xa3a4f
movq %rbx, %rdi
callq 0x84a53
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 0x8b807
leaq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x488(%rbx), %rdx
cmpq %rax, %rbp
ja 0x8c805
movq %r12, %rcx
movl %r15d, %ebp
notl %ebp
addl %ecx, %ebp
addl %eax, %ebp
subl %r13d, %ebp
cmpl $0x3, %ebp
jbe 0x8c805
movq %rdx, %rax
subq %rcx, %rax
addq %r15, %rax
movl 0x1(%r13,%rax), %r15d
bswapl %r15d
cmpl %ebp, %r15d
cmovbl %r15d, %ebp
jbe 0x8c835
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x84923
andq $0x0, 0x488(%rbx)
leaq 0x1731a(%rip), %rsi     # 0xa3aaa
movq %rbx, %rdi
callq 0x84a53
movl %r15d, %ecx
leaq 0x17328(%rip), %rdx     # 0xa3aca
leaq 0x10(%rsp), %r14
pushq $0x32
popq %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0xe780
movq %rbx, %rdi
movq %r14, %rsi
callq 0x84a53
movl %ebp, %ecx
leaq 0x1731a(%rip), %rdx     # 0xa3ae6
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0xe780
movq %rbx, %rdi
movq %r14, %rsi
callq 0x84a53
jmp 0x8c659
movq %rbx, %rdi
movq %r15, %rsi
callq 0x84923
andq $0x0, 0x488(%rbx)
leaq 0x17237(%rip), %rsi     # 0xa3a3a
jmp 0x8c81f
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x84923
andq $0x0, 0x488(%rbx)
leaq 0x17260(%rip), %rsi     # 0xa3a7f
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x84a53
leaq (%rax,%r13), %r8
incq %r8
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
movl %ebp, %r9d
callq 0x7b594
movq 0x488(%rbx), %rsi
jmp 0x8c649