// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_pCAL
void /* PRIVATE */
png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
   png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
{
   PNG_pCAL;
   png_size_t purpose_len, units_len, total_len;
   png_uint_32p params_len;
   png_byte buf[10];
   png_charp new_purpose;
   int i;

   png_debug1(1, "in png_write_pCAL (%d parameters)", nparams);

   if (type >= PNG_EQUATION_LAST)
      png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");

   purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
   png_debug1(3, "pCAL purpose length = %d", (int)purpose_len);
   units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
   png_debug1(3, "pCAL units length = %d", (int)units_len);
   total_len = purpose_len + units_len + 10;

   params_len = (png_uint_32p)png_malloc(png_ptr,
      (png_alloc_size_t)(nparams * png_sizeof(png_uint_32)));

   /* Find the length of each parameter, making sure we don't count the
      null terminator for the last parameter. */
   for (i = 0; i < nparams; i++)
   {
      params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
      png_debug2(3, "pCAL parameter %d length = %lu", i,
        (unsigned long) params_len[i]);
      total_len += (png_size_t)params_len[i];
   }

   png_debug1(3, "pCAL total length = %d", (int)total_len);
   png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
   png_write_chunk_data(png_ptr, (png_bytep)new_purpose,
     (png_size_t)purpose_len);
   png_save_int_32(buf, X0);
   png_save_int_32(buf + 4, X1);
   buf[8] = (png_byte)type;
   buf[9] = (png_byte)nparams;
   png_write_chunk_data(png_ptr, buf, (png_size_t)10);
   png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);

   png_free(png_ptr, new_purpose);

   for (i = 0; i < nparams; i++)
   {
      png_write_chunk_data(png_ptr, (png_bytep)params[i],
         (png_size_t)params_len[i]);
   }

   png_free(png_ptr, params_len);
   png_write_chunk_end(png_ptr);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0xc(%rsp)
movl %ecx, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movq 0x80(%rsp), %r15
movb $0x0, 0x14(%rsp)
movl $0x4c414370, 0x10(%rsp) # imm = 0x4C414370
movl %r8d, 0x20(%rsp)
cmpl $0x4, %r8d
jl 0x90ce5
leaq 0x13212(%rip), %rsi     # 0xa3eef
movq %rbx, %rdi
callq 0x84a53
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8fb3e
movq %rax, %r12
movq %r15, %rdi
callq 0xe1e0
movq %rax, %r13
movl 0xc(%rsp), %ecx
movl %ecx, %eax
addl $-0x1, %eax
movq %r13, %rax
adcq $0x0, %rax
movq %rax, 0x38(%rsp)
movl %ecx, %r14d
addl $-0x1, %r14d
movq %r12, 0x30(%rsp)
adcq %r12, %r13
addq $0xb, %r13
movslq %ecx, %rbp
leaq (,%rbp,4), %rsi
movq %rbx, %rdi
callq 0x848bb
movq %rax, %r12
xorl %r15d, %r15d
testl %ebp, %ebp
movl $0x0, %ebp
cmovgl 0xc(%rsp), %ebp
cmpq %r15, %rbp
je 0x90d7d
movq 0x88(%rsp), %rax
movq (%rax,%r15,8), %rdi
callq 0xe1e0
xorl %ecx, %ecx
cmpq %r15, %r14
setne %cl
addq %rax, %rcx
movl %ecx, (%r12,%r15,4)
addq %rcx, %r13
incq %r15
jmp 0x90d50
movq 0x30(%rsp), %r14
incq %r14
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x8f233
movq 0x40(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x8f2a4
movl 0x18(%rsp), %ecx
movl %ecx, %eax
shrl $0x18, %eax
leaq 0x26(%rsp), %rsi
movb %al, (%rsi)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x1(%rsi)
movb %ch, 0x28(%rsp)
movb %cl, 0x3(%rsi)
movl 0x1c(%rsp), %ecx
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x4(%rsi)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x5(%rsi)
movb %ch, 0x2c(%rsp)
movb %cl, 0x7(%rsi)
movl 0x20(%rsp), %eax
movb %al, 0x8(%rsi)
movl 0xc(%rsp), %eax
movb %al, 0x9(%rsi)
pushq $0xa
popq %rdx
movq %rbx, %rdi
callq 0x8f2a4
movq %rbx, %rdi
movq 0x80(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x8f2a4
movq %rbx, %rdi
movq %r13, %rsi
callq 0x84923
xorl %r14d, %r14d
cmpq %r14, %rbp
je 0x90e40
movq 0x88(%rsp), %rax
movq (%rax,%r14,8), %rsi
movl (%r12,%r14,4), %edx
movq %rbx, %rdi
callq 0x8f2a4
incq %r14
jmp 0x90e1e
movq %rbx, %rdi
movq %r12, %rsi
callq 0x84923
movq %rbx, %rdi
callq 0x8f2e3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq