// File: tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_finish_row
void /* PRIVATE */
png_write_finish_row(png_structp png_ptr)
{
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */

   /* Start of interlace block */
   int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};

   /* Offset to next interlace block */
   int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};

   /* Start of interlace block in the y direction */
   int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};

   /* Offset to next interlace block in the y direction */
   int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif

   int ret;

   png_debug(1, "in png_write_finish_row");

   /* Next row */
   png_ptr->row_number++;

   /* See if we are done */
   if (png_ptr->row_number < png_ptr->num_rows)
      return;

#ifdef PNG_WRITE_INTERLACING_SUPPORTED
   /* If interlaced, go to next pass */
   if (png_ptr->interlaced)
   {
      png_ptr->row_number = 0;
      if (png_ptr->transformations & PNG_INTERLACE)
      {
         png_ptr->pass++;
      }
      else
      {
         /* Loop until we find a non-zero width or height pass */
         do
         {
            png_ptr->pass++;
            if (png_ptr->pass >= 7)
               break;
            png_ptr->usr_width = (png_ptr->width +
               png_pass_inc[png_ptr->pass] - 1 -
               png_pass_start[png_ptr->pass]) /
               png_pass_inc[png_ptr->pass];
            png_ptr->num_rows = (png_ptr->height +
               png_pass_yinc[png_ptr->pass] - 1 -
               png_pass_ystart[png_ptr->pass]) /
               png_pass_yinc[png_ptr->pass];
            if (png_ptr->transformations & PNG_INTERLACE)
               break;
         } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);

      }

      /* Reset the row above the image for the next pass */
      if (png_ptr->pass < 7)
      {
         if (png_ptr->prev_row != NULL)
            png_memset(png_ptr->prev_row, 0,
               (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
               png_ptr->usr_bit_depth, png_ptr->width)) + 1);
         return;
      }
   }
#endif

   /* If we get here, we've just written the last row, so we need
      to flush the compressor */
   do
   {
      /* Tell the compressor we are done */
      ret = deflate(&png_ptr->zstream, Z_FINISH);
      /* Check for an error */
      if (ret == Z_OK)
      {
         /* Check to see if we need more room */
         if (!(png_ptr->zstream.avail_out))
         {
            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;
         }
      }
      else if (ret != Z_STREAM_END)
      {
         if (png_ptr->zstream.msg != NULL)
            png_error(png_ptr, png_ptr->zstream.msg);
         else
            png_error(png_ptr, "zlib error");
      }
   } while (ret != Z_STREAM_END);

   /* Write any extra space */
   if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
   {
      png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
         png_ptr->zstream.avail_out);
   }

   deflateReset(&png_ptr->zstream);
   png_ptr->zstream.data_type = Z_BINARY;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq 0x11fca(%rip), %rax     # 0x140440
movq %rax, 0x80(%rsp)
movq 0x11fc3(%rip), %rax     # 0x140448
movq %rax, 0x88(%rsp)
movq 0x11fbc(%rip), %rax     # 0x140450
movq %rax, 0x90(%rsp)
movl 0x11fb6(%rip), %eax     # 0x140458
movl %eax, 0x98(%rsp)
movq 0x11fb0(%rip), %rax     # 0x140460
movq %rax, 0x60(%rsp)
movq 0x11fac(%rip), %rax     # 0x140468
movq %rax, 0x68(%rsp)
movq 0x11fa8(%rip), %rax     # 0x140470
movq %rax, 0x70(%rsp)
movl 0x11fa5(%rip), %eax     # 0x140478
movl %eax, 0x78(%rsp)
movq 0x11fa2(%rip), %rax     # 0x140480
movq %rax, 0x40(%rsp)
movq 0x11f9e(%rip), %rax     # 0x140488
movq %rax, 0x48(%rsp)
movq 0x11f9a(%rip), %rax     # 0x140490
movq %rax, 0x50(%rsp)
movl 0x11f97(%rip), %eax     # 0x140498
movl %eax, 0x58(%rsp)
movq 0x11f94(%rip), %rax     # 0x1404a0
movq %rax, 0x20(%rsp)
movq 0x11f90(%rip), %rax     # 0x1404a8
movq %rax, 0x28(%rsp)
movq 0x11f8c(%rip), %rax     # 0x1404b0
movq %rax, 0x30(%rsp)
movl 0x11f89(%rip), %eax     # 0x1404b8
movl %eax, 0x38(%rsp)
movq 0xa0(%rsp), %rax
movl 0x1e4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1e4(%rax)
movq 0xa0(%rsp), %rax
movl 0x1e4(%rax), %eax
movq 0xa0(%rsp), %rcx
cmpl 0x1c4(%rcx), %eax
jae 0x12e56d
jmp 0x12e98e
movq 0xa0(%rsp), %rax
cmpb $0x0, 0x24b(%rax)
je 0x12e810
movq 0xa0(%rsp), %rax
movl $0x0, 0x1e4(%rax)
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x12e5c6
movq 0xa0(%rsp), %rax
movb 0x24c(%rax), %cl
addb $0x1, %cl
movb %cl, 0x24c(%rax)
jmp 0x12e708
jmp 0x12e5c8
movq 0xa0(%rsp), %rax
movb 0x24c(%rax), %cl
addb $0x1, %cl
movb %cl, 0x24c(%rax)
movq 0xa0(%rsp), %rax
movzbl 0x24c(%rax), %eax
cmpl $0x7, %eax
jl 0x12e5f8
jmp 0x12e706
movq 0xa0(%rsp), %rax
movl 0x1bc(%rax), %eax
movq 0xa0(%rsp), %rcx
movzbl 0x24c(%rcx), %ecx
addl 0x60(%rsp,%rcx,4), %eax
subl $0x1, %eax
movq 0xa0(%rsp), %rcx
movzbl 0x24c(%rcx), %ecx
subl 0x80(%rsp,%rcx,4), %eax
movq 0xa0(%rsp), %rcx
movzbl 0x24c(%rcx), %ecx
xorl %edx, %edx
divl 0x60(%rsp,%rcx,4)
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x1c8(%rax)
movq 0xa0(%rsp), %rax
movl 0x1c0(%rax), %eax
movq 0xa0(%rsp), %rcx
movzbl 0x24c(%rcx), %ecx
addl 0x20(%rsp,%rcx,4), %eax
subl $0x1, %eax
movq 0xa0(%rsp), %rcx
movzbl 0x24c(%rcx), %ecx
subl 0x40(%rsp,%rcx,4), %eax
movq 0xa0(%rsp), %rcx
movzbl 0x24c(%rcx), %ecx
xorl %edx, %edx
divl 0x20(%rsp,%rcx,4)
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x1c4(%rax)
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x12e6cb
jmp 0x12e706
jmp 0x12e6cd
movq 0xa0(%rsp), %rcx
movb $0x1, %al
cmpl $0x0, 0x1c8(%rcx)
movb %al, 0x1b(%rsp)
je 0x12e6fa
movq 0xa0(%rsp), %rax
cmpl $0x0, 0x1c4(%rax)
sete %al
movb %al, 0x1b(%rsp)
movb 0x1b(%rsp), %al
testb $0x1, %al
jne 0x12e5c8
jmp 0x12e708
movq 0xa0(%rsp), %rax
movzbl 0x24c(%rax), %eax
cmpl $0x7, %eax
jge 0x12e80e
movq 0xa0(%rsp), %rax
cmpq $0x0, 0x1e8(%rax)
je 0x12e809
movq 0xa0(%rsp), %rax
movq 0x1e8(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0xa0(%rsp), %rax
movzbl 0x253(%rax), %eax
movq 0xa0(%rsp), %rcx
movzbl 0x250(%rcx), %ecx
imull %ecx, %eax
cmpl $0x8, %eax
jl 0x12e7b1
movq 0xa0(%rsp), %rax
movl 0x1bc(%rax), %eax
movq 0xa0(%rsp), %rcx
movzbl 0x253(%rcx), %ecx
movq 0xa0(%rsp), %rdx
movzbl 0x250(%rdx), %edx
imull %edx, %ecx
movslq %ecx, %rcx
shrq $0x3, %rcx
imulq %rcx, %rax
movq %rax, 0x8(%rsp)
jmp 0x12e7f4
movq 0xa0(%rsp), %rax
movl 0x1bc(%rax), %eax
movq 0xa0(%rsp), %rcx
movzbl 0x253(%rcx), %ecx
movq 0xa0(%rsp), %rdx
movzbl 0x250(%rdx), %edx
imull %edx, %ecx
movslq %ecx, %rcx
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rdx
addq $0x1, %rdx
xorl %esi, %esi
callq 0xf280
jmp 0x12e98e
jmp 0x12e810
jmp 0x12e812
movq 0xa0(%rsp), %rdi
addq $0x128, %rdi            # imm = 0x128
movl $0x4, %esi
callq 0x115c80
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jne 0x12e8b1
movq 0xa0(%rsp), %rax
cmpl $0x0, 0x148(%rax)
jne 0x12e8af
movq 0xa0(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq 0x198(%rax), %rsi
movq 0xa0(%rsp), %rax
movq 0x1a0(%rax), %rdx
callq 0x12b9a0
movq 0xa0(%rsp), %rax
movq 0x198(%rax), %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0x140(%rax)
movq 0xa0(%rsp), %rax
movq 0x1a0(%rax), %rax
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x148(%rax)
jmp 0x12e900
cmpl $0x1, 0x1c(%rsp)
je 0x12e8fe
movq 0xa0(%rsp), %rax
cmpq $0x0, 0x158(%rax)
je 0x12e8e8
movq 0xa0(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq 0x158(%rax), %rsi
callq 0x113860
jmp 0x12e8fc
movq 0xa0(%rsp), %rdi
leaq 0xa87b(%rip), %rsi      # 0x139172
callq 0x113860
jmp 0x12e8fe
jmp 0x12e900
jmp 0x12e902
cmpl $0x1, 0x1c(%rsp)
jne 0x12e812
movq 0xa0(%rsp), %rax
movl 0x148(%rax), %eax
movq 0xa0(%rsp), %rcx
cmpq 0x1a0(%rcx), %rax
jae 0x12e968
movq 0xa0(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq 0x198(%rax), %rsi
movq 0xa0(%rsp), %rax
movq 0x1a0(%rax), %rdx
movq 0xa0(%rsp), %rax
movl 0x148(%rax), %eax
subq %rax, %rdx
callq 0x12b9a0
movq 0xa0(%rsp), %rdi
addq $0x128, %rdi            # imm = 0x128
callq 0x1154e0
movq 0xa0(%rsp), %rax
movl $0x0, 0x180(%rax)
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)