// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_iTXt
void /* PRIVATE */
png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
    png_charp lang, png_charp lang_key, png_charp text)
{
   PNG_iTXt;
   png_size_t lang_len, key_len, lang_key_len, text_len;
   png_charp new_lang;
   png_charp new_key = NULL;
   png_byte cbuf[2];
   compression_state comp;

   png_debug(1, "in png_write_iTXt");

   comp.num_output_ptr = 0;
   comp.max_output_ptr = 0;
   comp.output_ptr = NULL;
   comp.input = NULL;

   if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0)
      return;

   if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
   {
      png_warning(png_ptr, "Empty language field in iTXt chunk");
      new_lang = NULL;
      lang_len = 0;
   }

   if (lang_key == NULL)
      lang_key_len = 0;
   else
      lang_key_len = png_strlen(lang_key);

   if (text == NULL)
      text_len = 0;
   else
      text_len = png_strlen(text);

   /* Compute the compressed data; do it now for the length */
   text_len = png_text_compress(png_ptr, text, text_len, compression-2,
      &comp);


   /* Make sure we include the compression flag, the compression byte,
    * and the NULs after the key, lang, and lang_key parts */

   png_write_chunk_start(png_ptr, (png_bytep)png_iTXt,
          (png_uint_32)(
        5 /* comp byte, comp flag, terminators for key, lang and lang_key */
        + key_len
        + lang_len
        + lang_key_len
        + text_len));

   /* We leave it to the application to meet PNG-1.0 requirements on the
    * contents of the text.  PNG-1.0 through PNG-1.2 discourage the use of
    * any non-Latin-1 characters except for NEWLINE.  ISO PNG will forbid them.
    * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
    */
   png_write_chunk_data(png_ptr, (png_bytep)new_key,
     (png_size_t)(key_len + 1));

   /* Set the compression flag */
   if (compression == PNG_ITXT_COMPRESSION_NONE || \
       compression == PNG_TEXT_COMPRESSION_NONE)
       cbuf[0] = 0;
   else /* compression == PNG_ITXT_COMPRESSION_zTXt */
       cbuf[0] = 1;
   /* Set the compression method */
   cbuf[1] = 0;
   png_write_chunk_data(png_ptr, cbuf, (png_size_t)2);

   cbuf[0] = 0;
   png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf),
     (png_size_t)(lang_len + 1));
   png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf),
     (png_size_t)(lang_key_len + 1));
   png_write_compressed_data_out(png_ptr, &comp);

   png_write_chunk_end(png_ptr);
   png_free(png_ptr, new_key);
   png_free(png_ptr, new_lang);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r13
movq %r8, %r14
movq %rcx, %r12
movl %esi, %r15d
movq %rdi, %rbx
movb $0x0, 0x4(%rsp)
movl $0x74585469, (%rsp)     # imm = 0x74585469
xorl %ecx, %ecx
leaq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq %rcx, 0x34(%rsp)
movq %rcx, 0x40(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, %rsi
movq %rax, %rdx
callq 0x9e27b
testq %rax, %rax
je 0x9f3d2
movq %rax, %rbp
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9e27b
movq %rax, %r12
testq %rax, %rax
jne 0x9f2ba
leaq 0x14f00(%rip), %rsi     # 0xb41a9
movq %rbx, %rdi
callq 0x9214d
movq $0x0, 0x10(%rsp)
testq %r14, %r14
je 0x9f2ce
movq %r14, %rdi
callq 0xe1e0
movq %rax, 0x8(%rsp)
jmp 0x9f2d7
movq $0x0, 0x8(%rsp)
testq %r13, %r13
je 0x9f2f8
movq %r13, %rdi
callq 0xe1e0
leal -0x2(%r15), %ecx
leaq 0x28(%rsp), %r8
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
jmp 0x9f308
leal -0x2(%r15), %ecx
leaq 0x28(%rsp), %r8
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x9e4ac
leal (%r12,%rbp), %ecx
movq 0x8(%rsp), %r13
addl %r13d, %ecx
leal (%rax,%rcx), %edx
addl $0x5, %edx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x9d91a
movq 0x20(%rsp), %rsi
movq %rsi, 0x18(%rsp)
incq %rbp
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x9d98f
incl %r15d
testl $0xfffffffd, %r15d      # imm = 0xFFFFFFFD
leaq 0x6(%rsp), %rbp
setne (%rbp)
xorl %r15d, %r15d
movb %r15b, 0x1(%rbp)
movl $0x2, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x9d98f
movb %r15b, (%rbp)
movq 0x10(%rsp), %r15
testq %r15, %r15
movq %r15, %rsi
cmoveq %rbp, %rsi
incq %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x9d98f
testq %r14, %r14
cmoveq %rbp, %r14
incq %r13
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x9d98f
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x9e752
movq %rbx, %rdi
callq 0x9d9ce
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x92016
movq %rbx, %rdi
movq %r15, %rsi
callq 0x92016
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq