// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_pCAL
void /* PRIVATE */
png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   png_int_32 X0, X1;
   png_byte type, nparams;
   png_charp buf, units, endptr;
   png_charpp params;
   png_size_t slength;
   int i;

   png_debug(1, "in png_handle_pCAL");

   if (!(png_ptr->mode & PNG_HAVE_IHDR))
      png_error(png_ptr, "Missing IHDR before pCAL");
   else if (png_ptr->mode & PNG_HAVE_IDAT)
   {
      png_warning(png_ptr, "Invalid pCAL after IDAT");
      png_crc_finish(png_ptr, length);
      return;
   }
   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
   {
      png_warning(png_ptr, "Duplicate pCAL chunk");
      png_crc_finish(png_ptr, length);
      return;
   }

   png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)",
      length + 1);
   png_free(png_ptr, png_ptr->chunkdata);
   png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
   if (png_ptr->chunkdata == NULL)
     {
       png_warning(png_ptr, "No memory for pCAL purpose");
       return;
     }
   slength = (png_size_t)length;
   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);

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

   png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */

   png_debug(3, "Finding end of pCAL purpose string");
   for (buf = png_ptr->chunkdata; *buf; buf++)
      /* Empty loop */ ;

   endptr = png_ptr->chunkdata + slength;

   /* We need to have at least 12 bytes after the purpose string
      in order to get the parameter information. */
   if (endptr <= buf + 12)
   {
      png_warning(png_ptr, "Invalid pCAL data");
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }

   png_debug(3, "Reading pCAL X0, X1, type, nparams, and units");
   X0 = png_get_int_32((png_bytep)buf+1);
   X1 = png_get_int_32((png_bytep)buf+5);
   type = buf[9];
   nparams = buf[10];
   units = buf + 11;

   png_debug(3, "Checking pCAL equation type and number of parameters");
   /* Check that we have the right number of parameters for known
      equation types. */
   if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
       (type == PNG_EQUATION_BASE_E && nparams != 3) ||
       (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
       (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
   {
      png_warning(png_ptr, "Invalid pCAL parameters for equation type");
      png_free(png_ptr, png_ptr->chunkdata);
      png_ptr->chunkdata = NULL;
      return;
   }
   else if (type >= PNG_EQUATION_LAST)
   {
      png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
   }

   for (buf = units; *buf; buf++)
      /* Empty loop to move past the units string. */ ;

   png_debug(3, "Allocating pCAL parameters array");
   params = (png_charpp)png_malloc_warn(png_ptr,
      (png_size_t)(nparams * png_sizeof(png_charp)));
   if (params == NULL)
     {
       png_free(png_ptr, png_ptr->chunkdata);
       png_ptr->chunkdata = NULL;
       png_warning(png_ptr, "No memory for pCAL params");
       return;
     }

   /* Get pointers to the start of each parameter string. */
   for (i = 0; i < (int)nparams; i++)
   {
      buf++; /* Skip the null string terminator from previous parameter. */

      png_debug1(3, "Reading pCAL parameter %d", i);
      for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
         /* Empty loop to move past each parameter string */ ;

      /* Make sure we haven't run out of data yet */
      if (buf > endptr)
      {
         png_warning(png_ptr, "Invalid pCAL data");
         png_free(png_ptr, png_ptr->chunkdata);
         png_ptr->chunkdata = NULL;
         png_free(png_ptr, params);
         return;
      }
   }

   png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams,
      units, params);

   png_free(png_ptr, png_ptr->chunkdata);
   png_ptr->chunkdata = NULL;
   png_free(png_ptr, params);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl 0x11c(%rdi), %eax
testb $0x1, %al
jne 0x9b7af
leaq 0x17aa6(%rip), %rsi     # 0xb31a2
movq %rbx, %rdi
callq 0x920b4
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92016
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x92056
movq %rax, 0x488(%rbx)
testq %rax, %rax
je 0x9b7d0
movl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x99b23
movq %rbx, %rdi
xorl %esi, %esi
callq 0x99b4f
movq 0x488(%rbx), %rsi
testl %eax, %eax
jne 0x9b8d2
movb $0x0, (%rsi,%r15)
movq 0x488(%rbx), %r13
leaq 0x9(%r13), %rbp
cmpb $0x0, -0x9(%rbp)
leaq 0x1(%rbp), %rbp
jne 0x9b769
addq %r15, %r13
leaq 0x2(%rbp), %rax
cmpq %rax, %r13
jbe 0x9b815
movzbl -0x9(%rbp), %eax
testb %al, %al
js 0x9b821
shll $0x18, %eax
movzbl -0x8(%rbp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl -0x7(%rbp), %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl -0x6(%rbp), %esi
orl %eax, %esi
jmp 0x9b83c
testb $0x4, %al
jne 0x9b7ed
testq %r14, %r14
je 0x9b704
testb $0x4, 0x9(%r14)
je 0x9b704
leaq 0x17a05(%rip), %rsi     # 0xb31d3
jmp 0x9b7f4
leaq 0x17a11(%rip), %rsi     # 0xb31e8
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9214d
leaq 0x179c7(%rip), %rsi     # 0xb31bb
movq %rbx, %rdi
callq 0x9214d
movq %rbx, %rdi
movl %r15d, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x99b4f
leaq 0x179e7(%rip), %rsi     # 0xb3203
jmp 0x9b8c3
movzbl -0x8(%rbp), %ecx
shll $0x10, %ecx
shll $0x18, %eax
orl %ecx, %eax
movzbl -0x7(%rbp), %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl -0x6(%rbp), %esi
orl %ecx, %esi
movzbl -0x5(%rbp), %eax
testb %al, %al
js 0x9b863
shll $0x18, %eax
movzbl -0x4(%rbp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl -0x3(%rbp), %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl -0x2(%rbp), %r15d
orl %eax, %r15d
jmp 0x9b880
movzbl -0x4(%rbp), %ecx
shll $0x10, %ecx
shll $0x18, %eax
orl %ecx, %eax
movzbl -0x3(%rbp), %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl -0x2(%rbp), %r15d
orl %ecx, %r15d
movzbl -0x1(%rbp), %r12d
testl %r12d, %r12d
sete %cl
movb (%rbp), %al
cmpb $0x2, %al
setne %dl
testb %dl, %cl
jne 0x9b8bc
leal -0x1(%r12), %ecx
cmpb $0x1, %cl
ja 0x9b8a5
cmpb $0x3, %al
jne 0x9b8bc
movzbl %al, %edx
cmpl $0x3, %r12d
sete %al
cmpb $0x4, %dl
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x9b8f4
leaq 0x17952(%rip), %rsi     # 0xb3215
movq %rbx, %rdi
callq 0x9214d
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92016
movq $0x0, 0x488(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, 0x4(%rsp)
cmpb $0x4, %r12b
movq %rdx, 0x8(%rsp)
jb 0x9b917
leaq 0x17935(%rip), %rsi     # 0xb323f
movq %rbx, %rdi
callq 0x9214d
movq 0x8(%rsp), %rdx
leaq 0x1(%rbp), %rax
movq %rax, 0x10(%rsp)
cmpb $0x0, 0x1(%rbp)
leaq 0x1(%rbp), %rbp
jne 0x9b920
leal (,%rdx,8), %esi
movq %rbx, %rdi
callq 0x92056
testq %rax, %rax
je 0x9b9e5
movq 0x8(%rsp), %r10
testq %r10, %r10
je 0x9b970
movl %r10d, %edx
xorl %ecx, %ecx
incq %rbp
movq %rbp, (%rax,%rcx,8)
cmpq %r13, %rbp
ja 0x9b9a0
cmpb $0x0, (%rbp)
je 0x9b968
incq %rbp
jmp 0x9b958
incq %rcx
cmpq %rdx, %rcx
jne 0x9b951
movq 0x488(%rbx), %rdx
subq $0x8, %rsp
movq %rbx, %rdi
movq %r14, %rsi
movl 0xc(%rsp), %ecx
movl %r15d, %r8d
movl %r12d, %r9d
pushq %rax
pushq 0x20(%rsp)
pushq %r10
movq %rax, %r14
callq 0x87e74
addq $0x20, %rsp
jmp 0x9b9b2
leaq 0x1785c(%rip), %rsi     # 0xb3203
movq %rbx, %rdi
movq %rax, %r14
callq 0x9214d
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92016
movq $0x0, 0x488(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x92016
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92016
movq $0x0, 0x488(%rbx)
leaq 0x17863(%rip), %rsi     # 0xb3269
jmp 0x9b7d7