// File: /workspace/github_cpp_makefile_star2_O1/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, %r13d
movl %ecx, 0xc(%rsp)
movl %edx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %r12
movq 0x80(%rsp), %r14
movb $0x0, 0x4(%rsp)
movl $0x4c414370, (%rsp)     # imm = 0x4C414370
movl %r8d, 0x10(%rsp)
cmpl $0x4, %r8d
jl 0x9fe46
leaq 0x133ad(%rip), %rsi     # 0xb31eb
movq %r12, %rdi
callq 0x92e6e
movq 0x88(%rsp), %rbx
leaq 0x40(%rsp), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x9ec1f
movq %rax, %rbp
incq %rax
movq %rax, 0x20(%rsp)
movq %r14, %rdi
callq 0xe1e0
xorl %r15d, %r15d
testl %r13d, %r13d
setne %r15b
addq %rax, %r15
movslq %r13d, %r14
leaq (,%r14,4), %rsi
movq %r12, 0x38(%rsp)
movq %r12, %rdi
callq 0x92cb5
movq %rax, %r12
movq %r15, 0x28(%rsp)
addq %r15, %rbp
addq $0xb, %rbp
movl %r13d, %r15d
testl %r14d, %r14d
movq %r13, 0x30(%rsp)
jle 0x9fedb
decl %r13d
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
callq 0xe1e0
xorl %ecx, %ecx
cmpq %r14, %r13
setne %cl
addq %rax, %rcx
movl %ecx, (%r12,%r14,4)
addq %rcx, %rbp
incq %r14
cmpq %r14, %r15
jne 0x9feb8
movq %rsp, %rsi
movq 0x38(%rsp), %r13
movq %r13, %rdi
movl %ebp, %edx
callq 0x9e30e
movq 0x40(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
movq 0x20(%rsp), %rdx
callq 0x9e383
movl 0x8(%rsp), %ecx
movl %ecx, %eax
shrl $0x18, %eax
leaq 0x16(%rsp), %rsi
movb %al, (%rsi)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x1(%rsi)
movb %ch, 0x18(%rsp)
movb %cl, 0x3(%rsi)
movl 0xc(%rsp), %ecx
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x4(%rsi)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x5(%rsi)
movb %ch, 0x1c(%rsp)
movb %cl, 0x7(%rsi)
movl 0x10(%rsp), %eax
movb %al, 0x8(%rsi)
movq 0x30(%rsp), %r14
movb %r14b, 0x9(%rsi)
movl $0xa, %edx
movq %r13, %rdi
callq 0x9e383
movq %r13, %rdi
movq 0x80(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x9e383
movq %r13, %rdi
movq %rbp, %rsi
callq 0x92d32
testl %r14d, %r14d
jle 0x9ff99
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rsi
movl (%r12,%r14,4), %edx
movq %r13, %rdi
callq 0x9e383
incq %r14
cmpq %r14, %r15
jne 0x9ff81
movq %r13, %rdi
movq %r12, %rsi
callq 0x92d32
movq %r13, %rdi
callq 0x9e3c2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq