// File: lvandeve[P]lodepng/lodepng.cpp
// Function: readChunk_iCCP(LodePNGInfo*, LodePNGDecoderSettings const*, unsigned char const*, unsigned long)
static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,
                               const unsigned char* data, size_t chunkLength) {
  unsigned error = 0;
  unsigned i;
  size_t size = 0;
  /*copy the object to change parameters in it*/
  LodePNGDecompressSettings zlibsettings = decoder->zlibsettings;

  unsigned length, string2_begin;

  if(info->iccp_defined) lodepng_clear_icc(info);
  info->iccp_defined = 1;

  for(length = 0; length < chunkLength && data[length] != 0; ++length) ;
  if(length + 2 >= chunkLength) return 75; /*no null termination, corrupt?*/
  if(length < 1 || length > 79) return 89; /*keyword too short or long*/

  info->iccp_name = (char*)lodepng_malloc(length + 1);
  if(!info->iccp_name) return 83; /*alloc fail*/

  info->iccp_name[length] = 0;
  for(i = 0; i != length; ++i) info->iccp_name[i] = (char)data[i];

  if(data[length + 1] != 0) return 72; /*the 0 byte indicating compression must be 0*/

  string2_begin = length + 2;
  if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/

  length = (unsigned)chunkLength - string2_begin;
  zlibsettings.max_output_size = decoder->max_icc_size;
  error = zlib_decompress(&info->iccp_profile, &size, 0,
                          &data[string2_begin],
                          length, &zlibsettings);
  /*error: ICC profile larger than decoder->max_icc_size*/
  if(error && size > zlibsettings.max_output_size) error = 113;
  info->iccp_profile_size = (unsigned)size;
  if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/
  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x60(%rbp), %rdi
movl $0x28, %edx
callq 0x31e0
movq -0x10(%rbp), %rax
cmpl $0x0, 0xfc(%rax)
je 0xbacf
movq -0x10(%rbp), %rdi
callq 0x6380
movq -0x10(%rbp), %rax
movl $0x1, 0xfc(%rax)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x69(%rbp)
jae 0xbb08
movq -0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0xbb11
jmp 0xbb1e
jmp 0xbb13
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xbae4
movl -0x64(%rbp), %eax
addl $0x2, %eax
movl %eax, %eax
cmpq -0x28(%rbp), %rax
jb 0xbb38
movl $0x4b, -0x4(%rbp)
jmp 0xbc99
cmpl $0x1, -0x64(%rbp)
jb 0xbb44
cmpl $0x4f, -0x64(%rbp)
jbe 0xbb50
movl $0x59, -0x4(%rbp)
jmp 0xbc99
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3bc0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x100(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x100(%rax)
jne 0xbb87
movl $0x53, -0x4(%rbp)
jmp 0xbc99
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rax
movl -0x64(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x64(%rbp), %eax
je 0xbbce
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rax
movl -0x30(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xbba0
movq -0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xbbef
movl $0x48, -0x4(%rbp)
jmp 0xbc99
movl -0x64(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpq -0x28(%rbp), %rax
jbe 0xbc0d
movl $0x4b, -0x4(%rbp)
jmp 0xbc99
movq -0x28(%rbp), %rax
subl -0x68(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
movq -0x20(%rbp), %rcx
movl -0x68(%rbp), %eax
addq %rax, %rcx
movl -0x64(%rbp), %eax
movl %eax, %r8d
leaq -0x38(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x60(%rbp), %r9
callq 0x117d0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0xbc69
movq -0x38(%rbp), %rax
cmpq -0x58(%rbp), %rax
jbe 0xbc69
movl $0x71, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x110(%rax)
cmpl $0x0, -0x2c(%rbp)
jne 0xbc93
movq -0x10(%rbp), %rax
cmpl $0x0, 0x110(%rax)
jne 0xbc93
movl $0x64, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)