// File: tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_filtered_row
void /* PRIVATE */
png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
{
   png_debug(1, "in png_write_filtered_row");

   png_debug1(2, "filter = %d", filtered_row[0]);
   /* Set up the zlib input buffer */

   png_ptr->zstream.next_in = filtered_row;
   png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
   /* Repeat until we have compressed all the data */
   do
   {
      int ret; /* Return of zlib */

      /* Compress the data */
      ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
      /* 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");
      }

      /* See if it is time to write another IDAT */
      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;
      }
   /* Repeat until all data has been compressed */
   } while (png_ptr->zstream.avail_in);

   /* Swap the current and previous rows */
   if (png_ptr->prev_row != NULL)
   {
      png_bytep tptr;

      tptr = png_ptr->prev_row;
      png_ptr->prev_row = png_ptr->row_buf;
      png_ptr->row_buf = tptr;
   }

   /* Finish row - updates counters and flushes zlib if last row */
   png_write_finish_row(png_ptr);

#ifdef PNG_WRITE_FLUSH_SUPPORTED
   png_ptr->flush_rows++;

   if (png_ptr->flush_dist > 0 &&
       png_ptr->flush_rows >= png_ptr->flush_dist)
   {
      png_write_flush(png_ptr);
   }
#endif
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x128(%rax)
movq 0x20(%rsp), %rax
movq 0x220(%rax), %rax
movl %eax, %ecx
addl $0x1, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x130(%rax)
movq 0x20(%rsp), %rdi
addq $0x128, %rdi            # imm = 0x128
xorl %esi, %esi
callq 0x115c80
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x1310c3
movq 0x20(%rsp), %rax
cmpq $0x0, 0x158(%rax)
je 0x1310b0
movq 0x20(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x158(%rax), %rsi
callq 0x113860
jmp 0x1310c1
movq 0x20(%rsp), %rdi
leaq 0x80b6(%rip), %rsi      # 0x139172
callq 0x113860
jmp 0x1310c3
movq 0x20(%rsp), %rax
cmpl $0x0, 0x148(%rax)
jne 0x131124
movq 0x20(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x198(%rax), %rsi
movq 0x20(%rsp), %rax
movq 0x1a0(%rax), %rdx
callq 0x12b9a0
movq 0x20(%rsp), %rax
movq 0x198(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x140(%rax)
movq 0x20(%rsp), %rax
movq 0x1a0(%rax), %rax
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x148(%rax)
jmp 0x131126
movq 0x20(%rsp), %rax
cmpl $0x0, 0x130(%rax)
jne 0x13106b
movq 0x20(%rsp), %rax
cmpq $0x0, 0x1e8(%rax)
je 0x131181
movq 0x20(%rsp), %rax
movq 0x1e8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq 0x1f0(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x1e8(%rax)
movq 0x8(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x1f0(%rax)
movq 0x20(%rsp), %rdi
callq 0x12e460
movq 0x20(%rsp), %rax
movl 0x284(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x284(%rax)
movq 0x20(%rsp), %rax
cmpl $0x0, 0x280(%rax)
jbe 0x1311cf
movq 0x20(%rsp), %rax
movl 0x284(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x280(%rcx), %eax
jb 0x1311cf
movq 0x20(%rsp), %rdi
callq 0x105380
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)
nop