// File: tomfunkhouser[P]gaps/pkgs/png/pngwrite.c
// Function: png_write_flush
void PNGAPI
png_write_flush(png_structp png_ptr)
{
   int wrote_IDAT;

   png_debug(1, "in png_write_flush");

   if (png_ptr == NULL)
      return;
   /* We have already written out all of the data */
   if (png_ptr->row_number >= png_ptr->num_rows)
      return;

   do
   {
      int ret;

      /* Compress the data */
      ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
      wrote_IDAT = 0;

      /* Check for compression errors */
      if (ret != Z_OK)
      {
         if (png_ptr->zstream.msg != NULL)
            png_error(png_ptr, png_ptr->zstream.msg);
         else
            png_error(png_ptr, "zlib error");
      }

      if (!(png_ptr->zstream.avail_out))
      {
         /* Write the IDAT and reset the zlib output buffer */
         png_write_IDAT(png_ptr, png_ptr->zbuf,
                        png_ptr->zbuf_size);
         png_ptr->zstream.next_out = png_ptr->zbuf;
         png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
         wrote_IDAT = 1;
      }
   } while(wrote_IDAT == 1);

   /* If there is any data left to be output, write it into a new IDAT */
   if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
   {
      /* Write the IDAT and reset the zlib output buffer */
      png_write_IDAT(png_ptr, png_ptr->zbuf,
                     png_ptr->zbuf_size - png_ptr->zstream.avail_out);
      png_ptr->zstream.next_out = png_ptr->zbuf;
      png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
   }
   png_ptr->flush_rows = 0;
   png_flush(png_ptr);
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x105396
jmp 0x105524
movq 0x10(%rsp), %rax
movl 0x1e4(%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0x1c4(%rcx), %eax
jb 0x1053b3
jmp 0x105524
jmp 0x1053b5
movq 0x10(%rsp), %rdi
addq $0x128, %rdi            # imm = 0x128
movl $0x2, %esi
callq 0x115c80
movl %eax, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x0, 0x8(%rsp)
je 0x105418
movq 0x10(%rsp), %rax
cmpq $0x0, 0x158(%rax)
je 0x105405
movq 0x10(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x158(%rax), %rsi
callq 0x113860
jmp 0x105416
movq 0x10(%rsp), %rdi
leaq 0x33d61(%rip), %rsi     # 0x139172
callq 0x113860
jmp 0x105418
movq 0x10(%rsp), %rax
cmpl $0x0, 0x148(%rax)
jne 0x105481
movq 0x10(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x198(%rax), %rsi
movq 0x10(%rsp), %rax
movq 0x1a0(%rax), %rdx
callq 0x12b9a0
movq 0x10(%rsp), %rax
movq 0x198(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x140(%rax)
movq 0x10(%rsp), %rax
movq 0x1a0(%rax), %rax
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x148(%rax)
movl $0x1, 0xc(%rsp)
jmp 0x105483
cmpl $0x1, 0xc(%rsp)
je 0x1053b5
movq 0x10(%rsp), %rax
movq 0x1a0(%rax), %rax
movq 0x10(%rsp), %rcx
movl 0x148(%rcx), %ecx
cmpq %rcx, %rax
je 0x10550b
movq 0x10(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x198(%rax), %rsi
movq 0x10(%rsp), %rax
movq 0x1a0(%rax), %rdx
movq 0x10(%rsp), %rax
movl 0x148(%rax), %eax
subq %rax, %rdx
callq 0x12b9a0
movq 0x10(%rsp), %rax
movq 0x198(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x140(%rax)
movq 0x10(%rsp), %rax
movq 0x1a0(%rax), %rax
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x148(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x284(%rax)
movq 0x10(%rsp), %rdi
callq 0x1312b0
addq $0x18, %rsp
retq
nopl (%rax)