// File: tomfunkhouser[P]gaps/pkgs/png/pngset.c
// Function: png_set_pCAL
void PNGAPI
png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
   png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
   png_charp units, png_charpp params)
{
   png_size_t length;
   int i;

   png_debug1(1, "in %s storage function", "pCAL");

   if (png_ptr == NULL || info_ptr == NULL)
      return;

   length = png_strlen(purpose) + 1;
   png_debug1(3, "allocating purpose for info (%lu bytes)",
     (unsigned long)length);
   info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
   if (info_ptr->pcal_purpose == NULL)
   {
      png_warning(png_ptr, "Insufficient memory for pCAL purpose");
      return;
   }
   png_memcpy(info_ptr->pcal_purpose, purpose, length);

   png_debug(3, "storing X0, X1, type, and nparams in info");
   info_ptr->pcal_X0 = X0;
   info_ptr->pcal_X1 = X1;
   info_ptr->pcal_type = (png_byte)type;
   info_ptr->pcal_nparams = (png_byte)nparams;

   length = png_strlen(units) + 1;
   png_debug1(3, "allocating units for info (%lu bytes)",
     (unsigned long)length);
   info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
   if (info_ptr->pcal_units == NULL)
   {
      png_warning(png_ptr, "Insufficient memory for pCAL units");
      return;
   }
   png_memcpy(info_ptr->pcal_units, units, length);

   info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
      (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
   if (info_ptr->pcal_params == NULL)
   {
      png_warning(png_ptr, "Insufficient memory for pCAL params");
      return;
   }

   png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));

   for (i = 0; i < nparams; i++)
   {
      length = png_strlen(params[i]) + 1;
      png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
        (unsigned long)length);
      info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
      if (info_ptr->pcal_params[i] == NULL)
      {
         png_warning(png_ptr, "Insufficient memory for pCAL parameter");
         return;
      }
      png_memcpy(info_ptr->pcal_params[i], params[i], length);
   }

   info_ptr->valid |= PNG_INFO_pCAL;
   info_ptr->free_me |= PNG_FREE_PCAL;
}

// Assembly:
subq $0x38, %rsp
movq 0x50(%rsp), %rax
movq 0x48(%rsp), %rax
movl 0x40(%rsp), %eax
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
movl %r8d, 0x18(%rsp)
movl %r9d, 0x14(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0xfd60f
cmpq $0x0, 0x28(%rsp)
jne 0xfd614
jmp 0xfd88c
movq 0x20(%rsp), %rdi
callq 0xf200
addq $0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x113760
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0xc0(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0xc0(%rax)
jne 0xfd66a
movq 0x30(%rsp), %rdi
leaq 0x3b7f4(%rip), %rsi     # 0x138e54
callq 0x113940
jmp 0xfd88c
movq 0x28(%rsp), %rax
movq 0xc0(%rax), %rdi
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0xf3d0
movl 0x1c(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0xc8(%rax)
movl 0x18(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0xcc(%rax)
movl 0x14(%rsp), %eax
movb %al, %cl
movq 0x28(%rsp), %rax
movb %cl, 0xe0(%rax)
movl 0x40(%rsp), %eax
movb %al, %cl
movq 0x28(%rsp), %rax
movb %cl, 0xe1(%rax)
movq 0x48(%rsp), %rdi
callq 0xf200
addq $0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x113760
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0xd0(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0xd0(%rax)
jne 0xfd71b
movq 0x30(%rsp), %rdi
leaq 0x3b768(%rip), %rsi     # 0x138e79
callq 0x113940
jmp 0xfd88c
movq 0x28(%rsp), %rax
movq 0xd0(%rax), %rdi
movq 0x48(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0xf3d0
movq 0x30(%rsp), %rdi
movl 0x40(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x113760
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0xd8(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0xd8(%rax)
jne 0xfd782
movq 0x30(%rsp), %rdi
leaq 0x3b724(%rip), %rsi     # 0x138e9c
callq 0x113940
jmp 0xfd88c
movq 0x28(%rsp), %rax
movq 0xd8(%rax), %rdi
movl 0x40(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0xf280
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
cmpl 0x40(%rsp), %eax
jge 0xfd864
movq 0x50(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xf200
addq $0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x113760
movq %rax, %rdx
movq 0x28(%rsp), %rax
movq 0xd8(%rax), %rax
movslq 0x4(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x28(%rsp), %rax
movq 0xd8(%rax), %rax
movslq 0x4(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0xfd827
movq 0x30(%rsp), %rdi
leaq 0x3b6a0(%rip), %rsi     # 0x138ec0
callq 0x113940
jmp 0xfd88c
movq 0x28(%rsp), %rax
movq 0xd8(%rax), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x50(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x8(%rsp), %rdx
callq 0xf3d0
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0xfd7ab
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movl %ecx, 0x8(%rax)
movq 0x28(%rsp), %rax
movl 0xe4(%rax), %ecx
orl $0x80, %ecx
movl %ecx, 0xe4(%rax)
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)