// File: /workspace/github_cpp_makefile_star2_O2/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 0x8d28e
leaq 0x16c77(%rip), %rsi     # 0xa3e52
movq %rbx, %rdi
callq 0x849c0
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x84960
movq %rax, 0x488(%rbx)
testq %rax, %rax
je 0x8d2af
movl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x8b6d7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8b703
movq 0x488(%rbx), %rsi
testl %eax, %eax
jne 0x8d3b1
movb $0x0, (%rsi,%r15)
movq 0x488(%rbx), %r13
leaq 0x9(%r13), %rbp
cmpb $0x0, -0x9(%rbp)
leaq 0x1(%rbp), %rbp
jne 0x8d248
addq %r15, %r13
leaq 0x2(%rbp), %rax
cmpq %rax, %r13
jbe 0x8d2f4
movzbl -0x9(%rbp), %eax
testb %al, %al
js 0x8d300
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 0x8d31b
testb $0x4, %al
jne 0x8d2cc
testq %r14, %r14
je 0x8d1e3
testb $0x4, 0x9(%r14)
je 0x8d1e3
leaq 0x16bd6(%rip), %rsi     # 0xa3e83
jmp 0x8d2d3
leaq 0x16be2(%rip), %rsi     # 0xa3e98
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x84a53
leaq 0x16b98(%rip), %rsi     # 0xa3e6b
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
movl %r15d, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b703
leaq 0x16bb8(%rip), %rsi     # 0xa3eb3
jmp 0x8d3a2
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 0x8d342
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 0x8d35f
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 0x8d39b
movzbl %al, %edx
leal -0x1(%r12), %eax
cmpb $0x1, %al
ja 0x8d387
cmpb $0x3, %dl
jne 0x8d39b
cmpl $0x3, %r12d
sete %al
cmpb $0x4, %dl
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x8d3d0
leaq 0x16b23(%rip), %rsi     # 0xa3ec5
movq %rbx, %rdi
callq 0x84a53
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
andq $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 0x8d3f3
leaq 0x16b09(%rip), %rsi     # 0xa3eef
movq %rbx, %rdi
callq 0x84a53
movq 0x8(%rsp), %rdx
leaq 0x1(%rbp), %rax
movq %rax, 0x10(%rsp)
cmpb $0x0, 0x1(%rbp)
leaq 0x1(%rbp), %rbp
jne 0x8d3fc
leal (,%rdx,8), %esi
movq %rbx, %rdi
callq 0x84960
testq %rax, %rax
je 0x8d48b
movq 0x8(%rsp), %r10
movl %r10d, %edx
xorl %ecx, %ecx
cmpq %rdx, %rcx
je 0x8d4ae
incq %rbp
movq %rbp, (%rax,%rcx,8)
cmpq %r13, %rbp
ja 0x8d449
cmpb $0x0, (%rbp)
je 0x8d444
incq %rbp
jmp 0x8d434
incq %rcx
jmp 0x8d424
leaq 0x16a63(%rip), %rsi     # 0xa3eb3
movq %rbx, %rdi
movq %rax, %r14
callq 0x84a53
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
andq $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 0x84923
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x84923
andq $0x0, 0x488(%rbx)
leaq 0x16a70(%rip), %rsi     # 0xa3f19
jmp 0x8d2b6
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 0x7b1cb
addq $0x20, %rsp
jmp 0x8d45b