// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movq %r8, %r14
movq %rcx, %r12
movl %esi, %r15d
movq %rdi, %rbx
movb $0x0, 0x14(%rsp)
movl $0x74585469, 0x10(%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 0x9ec1f
testq %rax, %rax
je 0x9fd5d
movq %rax, %rbp
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9ec1f
movq %rax, %r12
testq %rax, %rax
jne 0x9fc57
leaq 0x14516(%rip), %rsi     # 0xb4159
movq %rbx, %rdi
callq 0x92e6e
movq $0x0, 0x18(%rsp)
xorl %r12d, %r12d
testq %r14, %r14
je 0x9fc69
movq %r14, %rdi
callq 0xe1e0
movq %rax, %r13
jmp 0x9fc6c
xorl %r13d, %r13d
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x9fc88
movq %rsi, %rdi
callq 0xe1e0
movq 0x8(%rsp), %rsi
movq %rax, %rdx
jmp 0x9fc8a
xorl %edx, %edx
leal -0x2(%r15), %ecx
leaq 0x28(%rsp), %r8
movq %rbx, %rdi
callq 0x9ee4b
leal (%r12,%rbp), %ecx
addl %r13d, %ecx
leal (%rax,%rcx), %edx
addl $0x5, %edx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x9e30e
movq 0x20(%rsp), %rsi
movq %rsi, 0x8(%rsp)
incq %rbp
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x9e383
incl %r15d
testl $0xfffffffd, %r15d      # imm = 0xFFFFFFFD
leaq 0x16(%rsp), %rbp
setne (%rbp)
xorl %r15d, %r15d
movb %r15b, 0x1(%rbp)
movl $0x2, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x9e383
movb %r15b, (%rbp)
movq 0x18(%rsp), %r15
testq %r15, %r15
movq %r15, %rsi
cmoveq %rbp, %rsi
incq %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x9e383
testq %r14, %r14
cmoveq %rbp, %r14
incq %r13
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x9e383
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq 0x9f0fb
movq %rbx, %rdi
callq 0x9e3c2
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x92d32
movq %rbx, %rdi
movq %r15, %rsi
callq 0x92d32
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq