// File: /workspace/github_cpp_makefile_star2_O1/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 0x9b4e1
leaq 0x17879(%rip), %rsi     # 0xb2cd8
movq %rbx, %rdi
callq 0x92dd0
testq %r14, %r14
je 0x9b477
testb $0x10, 0x9(%r14)
jne 0x9b50a
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92d32
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x92cb5
movq %rax, 0x488(%rbx)
movl %r15d, %r12d
movq %rbx, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x9a4db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9a507
movq 0x488(%rbx), %rsi
testl %eax, %eax
je 0x9b532
movq %rbx, %rdi
callq 0x92d32
movq $0x0, 0x488(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x4, %al
jne 0x9b501
testb $0x2, %al
je 0x9b467
leaq 0x17815(%rip), %rsi     # 0xb2d09
movq %rbx, %rdi
callq 0x92e6e
jmp 0x9b467
leaq 0x177e9(%rip), %rsi     # 0xb2cf1
jmp 0x9b511
leaq 0x17810(%rip), %rsi     # 0xb2d21
movq %rbx, %rdi
callq 0x92e6e
movq %rbx, %rdi
movl %r15d, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9a507
movb $0x0, (%rsi,%r12)
movq 0x488(%rbx), %r15
xorl %r13d, %r13d
cmpb $0x0, (%r15,%r13)
leaq 0x1(%r13), %r13
jne 0x9b541
leaq (%r15,%r13), %rax
leaq (%r15,%r12), %rcx
decq %rcx
cmpq %rcx, %rax
jae 0x9b663
cmpb $0x0, (%r15,%r13)
je 0x9b576
leaq 0x177dd(%rip), %rsi     # 0xb2d4b
movq %rbx, %rdi
callq 0x92e6e
movq 0x488(%rbx), %rbp
movq %r15, %rax
subq %rbp, %rax
leaq (%rax,%r13), %rcx
incq %rcx
leaq 0x8(%rsp), %r8
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rcx, %r12
callq 0x9a61b
leaq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x488(%rbx), %rdx
cmpq %rax, %r12
ja 0x9b682
movq %rbp, %rcx
addl %ecx, %eax
movl %r15d, %ebp
notl %ebp
addl %eax, %ebp
subl %r13d, %ebp
cmpl $0x3, %ebp
jbe 0x9b682
movq %rdx, %rax
subq %rcx, %rax
addq %r15, %rax
movl 0x1(%r13,%rax), %r15d
bswapl %r15d
cmpl %ebp, %r15d
cmovbl %r15d, %ebp
jbe 0x9b6b5
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x92d32
movq $0x0, 0x488(%rbx)
leaq 0x1779c(%rip), %rsi     # 0xb2da6
movq %rbx, %rdi
callq 0x92e6e
movl %r15d, %ecx
leaq 0x177aa(%rip), %rdx     # 0xb2dc6
leaq 0x10(%rsp), %r14
movl $0x32, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0xe750
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92e6e
movl %ebp, %ecx
leaq 0x1779e(%rip), %rdx     # 0xb2de2
movl $0x32, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0xe750
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92e6e
jmp 0x9b4d2
movq %rbx, %rdi
movq %r15, %rsi
callq 0x92d32
movq $0x0, 0x488(%rbx)
leaq 0x176b6(%rip), %rsi     # 0xb2d36
jmp 0x9b69f
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x92d32
movq $0x0, 0x488(%rbx)
leaq 0x176dc(%rip), %rsi     # 0xb2d7b
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x92e6e
leaq (%rax,%r13), %r8
incq %r8
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
movl %ebp, %r9d
callq 0x89011
movq 0x488(%rbx), %rsi
jmp 0x9b4bf