// File: tomfunkhouser[P]gaps/pkgs/png/pngwrite.c
// Function: png_write_end
void PNGAPI
png_write_end(png_structp png_ptr, png_infop info_ptr)
{
   png_debug(1, "in png_write_end");

   if (png_ptr == NULL)
      return;
   if (!(png_ptr->mode & PNG_HAVE_IDAT))
      png_error(png_ptr, "No IDATs written into file");

   /* See if user wants us to write information chunks */
   if (info_ptr != NULL)
   {
#ifdef PNG_WRITE_TEXT_SUPPORTED
      int i; /* local index variable */
#endif
#ifdef PNG_WRITE_tIME_SUPPORTED
      /* Check to see if user has supplied a time chunk */
      if ((info_ptr->valid & PNG_INFO_tIME) &&
         !(png_ptr->mode & PNG_WROTE_tIME))
         png_write_tIME(png_ptr, &(info_ptr->mod_time));
#endif
#ifdef PNG_WRITE_TEXT_SUPPORTED
      /* Loop through comment chunks */
      for (i = 0; i < info_ptr->num_text; i++)
      {
         png_debug2(2, "Writing trailer text chunk %d, type %d", i,
            info_ptr->text[i].compression);
         /* An internationalized chunk? */
         if (info_ptr->text[i].compression > 0)
         {
#ifdef PNG_WRITE_iTXt_SUPPORTED
            /* Write international chunk */
            png_write_iTXt(png_ptr,
                        info_ptr->text[i].compression,
                        info_ptr->text[i].key,
                        info_ptr->text[i].lang,
                        info_ptr->text[i].lang_key,
                        info_ptr->text[i].text);
#else
            png_warning(png_ptr, "Unable to write international text");
#endif
            /* Mark this chunk as written */
            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
         }
         else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
         {
#ifdef PNG_WRITE_zTXt_SUPPORTED
            /* Write compressed chunk */
            png_write_zTXt(png_ptr, info_ptr->text[i].key,
               info_ptr->text[i].text, 0,
               info_ptr->text[i].compression);
#else
            png_warning(png_ptr, "Unable to write compressed text");
#endif
            /* Mark this chunk as written */
            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
         }
         else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
         {
#ifdef PNG_WRITE_tEXt_SUPPORTED
            /* Write uncompressed chunk */
            png_write_tEXt(png_ptr, info_ptr->text[i].key,
               info_ptr->text[i].text, 0);
#else
            png_warning(png_ptr, "Unable to write uncompressed text");
#endif

            /* Mark this chunk as written */
            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
         }
      }
#endif
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
   if (info_ptr->unknown_chunks_num)
   {
      png_unknown_chunk *up;

      png_debug(5, "writing extra chunks");

      for (up = info_ptr->unknown_chunks;
           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
           up++)
      {
         int keep = png_handle_as_unknown(png_ptr, up->name);
         if (keep != PNG_HANDLE_CHUNK_NEVER &&
            up->location && (up->location & PNG_AFTER_IDAT) &&
            ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
            (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
         {
            png_write_chunk(png_ptr, up->name, up->data, up->size);
         }
      }
   }
#endif
   }

   png_ptr->mode |= PNG_AFTER_IDAT;

   /* Write end of PNG file */
   png_write_IEND(png_ptr);
   /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
    * and restored again in libpng-1.2.30, may cause some applications that
    * do not set png_ptr->output_flush_fn to crash.  If your application
    * experiences a problem, please try building libpng with
    * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
    * png-mng-implement at lists.sf.net .
    */
#ifdef PNG_WRITE_FLUSH_SUPPORTED
#  ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
   png_flush(png_ptr);
#  endif
#endif
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x10410b
jmp 0x10447d
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x10412f
movq 0x20(%rsp), %rdi
leaq 0x352df(%rip), %rsi     # 0x139409
callq 0x113860
cmpq $0x0, 0x18(%rsp)
je 0x10445f
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x104175
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x104175
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
addq $0x50, %rsi
callq 0x12deb0
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x18(%rsp), %rcx
cmpl 0x3c(%rcx), %eax
jge 0x10436c
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jle 0x104252
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rcx
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %r8
imulq $0x38, %r8, %r8
addq %r8, %rax
movq 0x30(%rax), %r8
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %r9
imulq $0x38, %r9, %r9
addq %r9, %rax
movq 0x10(%rax), %r9
callq 0x12d7a0
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0xfffffffd, (%rax)     # imm = 0xFFFFFFFD
jmp 0x10435a
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jl 0x1042e1
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdx
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %r8d
xorl %eax, %eax
movl %eax, %ecx
callq 0x12d610
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
jmp 0x104358
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
jne 0x104356
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x12d520
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0xfffffffd, (%rax)     # imm = 0xFFFFFFFD
jmp 0x104358
jmp 0x10435a
jmp 0x10435c
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x10417d
movq 0x18(%rsp), %rax
cmpq $0x0, 0xf0(%rax)
je 0x10445d
movq 0x18(%rsp), %rax
movq 0xe8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq 0xe8(%rcx), %rcx
movq 0x18(%rsp), %rdx
movq 0xf0(%rdx), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x10445b
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0xfc3e0
movl %eax, 0x4(%rsp)
cmpl $0x1, 0x4(%rsp)
je 0x104446
movq 0x8(%rsp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
je 0x104446
movq 0x8(%rsp), %rax
movzbl 0x18(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x104446
movq 0x8(%rsp), %rax
movzbl 0x3(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x104425
cmpl $0x3, 0x4(%rsp)
je 0x104425
movq 0x20(%rsp), %rax
movl 0x120(%rax), %eax
andq $0x10000, %rax          # imm = 0x10000
cmpq $0x0, %rax
je 0x104446
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
callq 0x12b040
jmp 0x104448
movq 0x8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x8(%rsp)
jmp 0x104390
jmp 0x10445d
jmp 0x10445f
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x11c(%rax)
movq 0x20(%rsp), %rdi
callq 0x12bbc0
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)