// File: /workspace/github_cpp_makefile_star2_O1/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 0x9c162
leaq 0x1709f(%rip), %rsi     # 0xb314e
movq %rbx, %rdi
callq 0x92dd0
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92d32
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x92d72
movq %rax, 0x488(%rbx)
testq %rax, %rax
je 0x9c183
movl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x9a4db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9a507
movq 0x488(%rbx), %rsi
testl %eax, %eax
jne 0x9c285
movb $0x0, (%rsi,%r15)
movq 0x488(%rbx), %r13
leaq 0x9(%r13), %rbp
cmpb $0x0, -0x9(%rbp)
leaq 0x1(%rbp), %rbp
jne 0x9c11c
addq %r15, %r13
leaq 0x2(%rbp), %rax
cmpq %rax, %r13
jbe 0x9c1c8
movzbl -0x9(%rbp), %eax
testb %al, %al
js 0x9c1d4
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 0x9c1ef
testb $0x4, %al
jne 0x9c1a0
testq %r14, %r14
je 0x9c0b7
testb $0x4, 0x9(%r14)
je 0x9c0b7
leaq 0x16ffe(%rip), %rsi     # 0xb317f
jmp 0x9c1a7
leaq 0x1700a(%rip), %rsi     # 0xb3194
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x92e6e
leaq 0x16fc0(%rip), %rsi     # 0xb3167
movq %rbx, %rdi
callq 0x92e6e
movq %rbx, %rdi
movl %r15d, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9a507
leaq 0x16fe0(%rip), %rsi     # 0xb31af
jmp 0x9c276
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 0x9c216
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 0x9c233
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 0x9c26f
leal -0x1(%r12), %ecx
cmpb $0x1, %cl
ja 0x9c258
cmpb $0x3, %al
jne 0x9c26f
movzbl %al, %edx
cmpl $0x3, %r12d
sete %al
cmpb $0x4, %dl
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x9c2a7
leaq 0x16f4b(%rip), %rsi     # 0xb31c1
movq %rbx, %rdi
callq 0x92e6e
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92d32
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 0x9c2ca
leaq 0x16f2e(%rip), %rsi     # 0xb31eb
movq %rbx, %rdi
callq 0x92e6e
movq 0x8(%rsp), %rdx
leaq 0x1(%rbp), %rax
movq %rax, 0x10(%rsp)
cmpb $0x0, 0x1(%rbp)
leaq 0x1(%rbp), %rbp
jne 0x9c2d3
leal (,%rdx,8), %esi
movq %rbx, %rdi
callq 0x92d72
testq %rax, %rax
je 0x9c37b
movq 0x8(%rsp), %r10
testq %r10, %r10
je 0x9c34b
movl %r10d, %edi
xorl %ecx, %ecx
leaq 0x1(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
cmpq %r13, %rdx
seta %sil
ja 0x9c3a1
cmpb $0x0, (%rdx)
je 0x9c33b
addq $0x2, %rbp
cmpq %r13, %rbp
seta %sil
ja 0x9c3a1
leaq 0x1(%rbp), %rdx
cmpb $0x0, (%rbp)
movq %rdx, %rbp
jne 0x9c322
decq %rdx
testb %sil, %sil
jne 0x9c3a1
incq %rcx
movq %rdx, %rbp
cmpq %rdi, %rcx
jne 0x9c304
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 0x88c5b
addq $0x20, %rsp
jmp 0x9c3b3
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92d32
movq $0x0, 0x488(%rbx)
leaq 0x16e79(%rip), %rsi     # 0xb3215
jmp 0x9c18a
leaq 0x16e07(%rip), %rsi     # 0xb31af
movq %rbx, %rdi
movq %rax, %r14
callq 0x92e6e
movq 0x488(%rbx), %rsi
movq %rbx, %rdi
callq 0x92d32
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 0x92d32