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

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

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

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

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

   int max_pixel_depth;
   png_size_t row_bytes;

   png_debug(1, "in png_read_start_row");
   png_ptr->zstream.avail_in = 0;
   png_init_read_transformations(png_ptr);
#ifdef PNG_READ_INTERLACING_SUPPORTED
   if (png_ptr->interlaced)
   {
      if (!(png_ptr->transformations & PNG_INTERLACE))
         png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
            png_pass_ystart[0]) / png_pass_yinc[0];
      else
         png_ptr->num_rows = png_ptr->height;

      png_ptr->iwidth = (png_ptr->width +
         png_pass_inc[png_ptr->pass] - 1 -
         png_pass_start[png_ptr->pass]) /
         png_pass_inc[png_ptr->pass];
   }
   else
#endif /* PNG_READ_INTERLACING_SUPPORTED */
   {
      png_ptr->num_rows = png_ptr->height;
      png_ptr->iwidth = png_ptr->width;
   }
   max_pixel_depth = png_ptr->pixel_depth;

#ifdef PNG_READ_PACK_SUPPORTED
   if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
      max_pixel_depth = 8;
#endif

#ifdef PNG_READ_EXPAND_SUPPORTED
   if (png_ptr->transformations & PNG_EXPAND)
   {
      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
      {
         if (png_ptr->num_trans)
            max_pixel_depth = 32;
         else
            max_pixel_depth = 24;
      }
      else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
      {
         if (max_pixel_depth < 8)
            max_pixel_depth = 8;
         if (png_ptr->num_trans)
            max_pixel_depth *= 2;
      }
      else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
      {
         if (png_ptr->num_trans)
         {
            max_pixel_depth *= 4;
            max_pixel_depth /= 3;
         }
      }
   }
#endif

#ifdef PNG_READ_FILLER_SUPPORTED
   if (png_ptr->transformations & (PNG_FILLER))
   {
      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
         max_pixel_depth = 32;
      else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
      {
         if (max_pixel_depth <= 8)
            max_pixel_depth = 16;
         else
            max_pixel_depth = 32;
      }
      else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
      {
         if (max_pixel_depth <= 32)
            max_pixel_depth = 32;
         else
            max_pixel_depth = 64;
      }
   }
#endif

#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
   if (png_ptr->transformations & PNG_GRAY_TO_RGB)
   {
      if (
#ifdef PNG_READ_EXPAND_SUPPORTED
        (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
#endif
#ifdef PNG_READ_FILLER_SUPPORTED
        (png_ptr->transformations & (PNG_FILLER)) ||
#endif
        png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
      {
         if (max_pixel_depth <= 16)
            max_pixel_depth = 32;
         else
            max_pixel_depth = 64;
      }
      else
      {
         if (max_pixel_depth <= 8)
           {
             if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
               max_pixel_depth = 32;
             else
               max_pixel_depth = 24;
           }
         else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
            max_pixel_depth = 64;
         else
            max_pixel_depth = 48;
      }
   }
#endif

#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
   if (png_ptr->transformations & PNG_USER_TRANSFORM)
     {
       int user_pixel_depth = png_ptr->user_transform_depth*
         png_ptr->user_transform_channels;
       if (user_pixel_depth > max_pixel_depth)
         max_pixel_depth=user_pixel_depth;
     }
#endif

   /* Align the width on the next larger 8 pixels.  Mainly used
    * for interlacing
    */
   row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
   /* Calculate the maximum bytes needed, adding a byte and a pixel
    * for safety's sake
    */
   row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
      1 + ((max_pixel_depth + 7) >> 3);
#ifdef PNG_MAX_MALLOC_64K
   if (row_bytes > (png_uint_32)65536L)
      png_error(png_ptr, "This image requires a row greater than 64KB");
#endif

   if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
   {
     png_free(png_ptr, png_ptr->big_row_buf);
     if (png_ptr->interlaced)
        png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
            row_bytes + 48);
     else
        png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr,
            row_bytes + 48);
     png_ptr->old_big_row_buf_size = row_bytes + 48;

#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
     /* Use 16-byte aligned memory for row_buf with at least 16 bytes
      * of padding before and after row_buf.
      */
     png_ptr->row_buf = png_ptr->big_row_buf + 32
         - (((png_alloc_size_t)&(png_ptr->big_row_buf[0]) + 15) % 16);
     png_ptr->old_big_row_buf_size = row_bytes + 48;
#else
     /* Use 32 bytes of padding before and 16 bytes after row_buf. */
     png_ptr->row_buf = png_ptr->big_row_buf + 32;
#endif
     png_ptr->old_big_row_buf_size = row_bytes + 48;
   }

#ifdef PNG_MAX_MALLOC_64K
   if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
      png_error(png_ptr, "This image requires a row greater than 64KB");
#endif
   if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
      png_error(png_ptr, "Row has too many bytes to allocate in memory");

   if (png_ptr->rowbytes + 1 > png_ptr->old_prev_row_size)
   {
      png_free(png_ptr, png_ptr->prev_row);
      png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
        png_ptr->rowbytes + 1));
      png_ptr->old_prev_row_size = png_ptr->rowbytes + 1;
   }

   png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);

   png_debug1(3, "width = %lu,", png_ptr->width);
   png_debug1(3, "height = %lu,", png_ptr->height);
   png_debug1(3, "iwidth = %lu,", png_ptr->iwidth);
   png_debug1(3, "num_rows = %lu,", png_ptr->num_rows);
   png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes);
   png_debug1(3, "irowbytes = %lu",
       PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);

   png_ptr->flags |= PNG_FLAG_ROW_INIT;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq 0x15a4a(%rip), %rax     # 0x13f0e0
movq %rax, 0x80(%rsp)
movq 0x15a43(%rip), %rax     # 0x13f0e8
movq %rax, 0x88(%rsp)
movq 0x15a3c(%rip), %rax     # 0x13f0f0
movq %rax, 0x90(%rsp)
movl 0x15a36(%rip), %eax     # 0x13f0f8
movl %eax, 0x98(%rsp)
movq 0x15a30(%rip), %rax     # 0x13f100
movq %rax, 0x60(%rsp)
movq 0x15a2c(%rip), %rax     # 0x13f108
movq %rax, 0x68(%rsp)
movq 0x15a28(%rip), %rax     # 0x13f110
movq %rax, 0x70(%rsp)
movl 0x15a25(%rip), %eax     # 0x13f118
movl %eax, 0x78(%rsp)
movq 0x15a22(%rip), %rax     # 0x13f120
movq %rax, 0x40(%rsp)
movq 0x15a1e(%rip), %rax     # 0x13f128
movq %rax, 0x48(%rsp)
movq 0x15a1a(%rip), %rax     # 0x13f130
movq %rax, 0x50(%rsp)
movl 0x15a17(%rip), %eax     # 0x13f138
movl %eax, 0x58(%rsp)
movq 0x15a14(%rip), %rax     # 0x13f140
movq %rax, 0x20(%rsp)
movq 0x15a10(%rip), %rax     # 0x13f148
movq %rax, 0x28(%rsp)
movq 0x15a0c(%rip), %rax     # 0x13f150
movq %rax, 0x30(%rsp)
movl 0x15a09(%rip), %eax     # 0x13f158
movl %eax, 0x38(%rsp)
movq 0xa0(%rsp), %rax
movl $0x0, 0x130(%rax)
movq 0xa0(%rsp), %rdi
callq 0x107b30
movq 0xa0(%rsp), %rax
cmpb $0x0, 0x24b(%rax)
je 0x12984b
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x1297ce
movq 0xa0(%rsp), %rax
movl 0x1c0(%rax), %eax
addl 0x20(%rsp), %eax
subl $0x1, %eax
subl 0x40(%rsp), %eax
xorl %edx, %edx
divl 0x20(%rsp)
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x1c4(%rax)
jmp 0x1297ea
movq 0xa0(%rsp), %rax
movl 0x1c0(%rax), %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x1c4(%rax)
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, 0x1e0(%rax)
jmp 0x129883
movq 0xa0(%rsp), %rax
movl 0x1c0(%rax), %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x1c4(%rax)
movq 0xa0(%rsp), %rax
movl 0x1bc(%rax), %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x1e0(%rax)
movq 0xa0(%rsp), %rax
movzbl 0x251(%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1298c8
movq 0xa0(%rsp), %rax
movzbl 0x24f(%rax), %eax
cmpl $0x8, %eax
jge 0x1298c8
movl $0x8, 0x1c(%rsp)
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x1299ab
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x3, %eax
jne 0x129921
movq 0xa0(%rsp), %rax
cmpw $0x0, 0x242(%rax)
je 0x129914
movl $0x20, 0x1c(%rsp)
jmp 0x12991c
movl $0x18, 0x1c(%rsp)
jmp 0x1299a9
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x0, %eax
jne 0x129962
cmpl $0x8, 0x1c(%rsp)
jge 0x129944
movl $0x8, 0x1c(%rsp)
movq 0xa0(%rsp), %rax
cmpw $0x0, 0x242(%rax)
je 0x129960
movl 0x1c(%rsp), %eax
shll %eax
movl %eax, 0x1c(%rsp)
jmp 0x1299a7
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x2, %eax
jne 0x1299a5
movq 0xa0(%rsp), %rax
cmpw $0x0, 0x242(%rax)
je 0x1299a3
movl 0x1c(%rsp), %eax
shll $0x2, %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, 0x1c(%rsp)
jmp 0x1299a5
jmp 0x1299a7
jmp 0x1299a9
jmp 0x1299ab
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andq $0x8000, %rax           # imm = 0x8000
cmpq $0x0, %rax
je 0x129a4b
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x3, %eax
jne 0x1299e7
movl $0x20, 0x1c(%rsp)
jmp 0x129a49
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x0, %eax
jne 0x129a16
cmpl $0x8, 0x1c(%rsp)
jg 0x129a0c
movl $0x10, 0x1c(%rsp)
jmp 0x129a14
movl $0x20, 0x1c(%rsp)
jmp 0x129a47
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x2, %eax
jne 0x129a45
cmpl $0x20, 0x1c(%rsp)
jg 0x129a3b
movl $0x20, 0x1c(%rsp)
jmp 0x129a43
movl $0x40, 0x1c(%rsp)
jmp 0x129a45
jmp 0x129a47
jmp 0x129a49
jmp 0x129a4b
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x129b37
movq 0xa0(%rsp), %rax
movzwl 0x242(%rax), %eax
cmpl $0x0, %eax
je 0x129a93
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
jne 0x129ac1
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andq $0x8000, %rax           # imm = 0x8000
cmpq $0x0, %rax
jne 0x129ac1
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x4, %eax
jne 0x129adc
cmpl $0x10, 0x1c(%rsp)
jg 0x129ad2
movl $0x20, 0x1c(%rsp)
jmp 0x129ada
movl $0x40, 0x1c(%rsp)
jmp 0x129b35
cmpl $0x8, 0x1c(%rsp)
jg 0x129b0b
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x6, %eax
jne 0x129b01
movl $0x20, 0x1c(%rsp)
jmp 0x129b09
movl $0x18, 0x1c(%rsp)
jmp 0x129b33
movq 0xa0(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x6, %eax
jne 0x129b29
movl $0x40, 0x1c(%rsp)
jmp 0x129b31
movl $0x30, 0x1c(%rsp)
jmp 0x129b33
jmp 0x129b35
jmp 0x129b37
movq 0xa0(%rsp), %rax
movl 0x124(%rax), %eax
andq $0x100000, %rax         # imm = 0x100000
cmpq $0x0, %rax
je 0x129b8a
movq 0xa0(%rsp), %rax
movzbl 0x118(%rax), %eax
movq 0xa0(%rsp), %rcx
movzbl 0x119(%rcx), %ecx
imull %ecx, %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jle 0x129b88
movl 0xc(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x129b8a
movq 0xa0(%rsp), %rax
movl 0x1bc(%rax), %eax
addl $0x7, %eax
andl $-0x8, %eax
movl %eax, %eax
movq %rax, 0x10(%rsp)
cmpl $0x8, 0x1c(%rsp)
jl 0x129bc4
movq 0x10(%rsp), %rax
movslq 0x1c(%rsp), %rcx
shrq $0x3, %rcx
imulq %rcx, %rax
movq %rax, (%rsp)
jmp 0x129bde
movq 0x10(%rsp), %rax
movslq 0x1c(%rsp), %rcx
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, (%rsp)
movq (%rsp), %rax
addq $0x1, %rax
movl 0x1c(%rsp), %ecx
addl $0x7, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x30, %rax
movq 0xa0(%rsp), %rcx
movl 0x480(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x129d26
movq 0xa0(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq 0x430(%rax), %rsi
callq 0x1136d0
movq 0xa0(%rsp), %rax
cmpb $0x0, 0x24b(%rax)
je 0x129c72
movq 0xa0(%rsp), %rdi
movq 0x10(%rsp), %rsi
addq $0x30, %rsi
callq 0x113560
movq %rax, %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0x430(%rax)
jmp 0x129c9a
movq 0xa0(%rsp), %rdi
movq 0x10(%rsp), %rsi
addq $0x30, %rsi
callq 0x1135b0
movq %rax, %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0x430(%rax)
movq 0x10(%rsp), %rax
addq $0x30, %rax
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x480(%rax)
movq 0xa0(%rsp), %rax
movq 0x430(%rax), %rcx
addq $0x20, %rcx
movq 0xa0(%rsp), %rax
movq 0x430(%rax), %rdx
addq $0xf, %rdx
andq $0xf, %rdx
xorl %eax, %eax
subq %rdx, %rax
addq %rax, %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0x1f0(%rax)
movq 0x10(%rsp), %rax
addq $0x30, %rax
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x480(%rax)
movq 0x10(%rsp), %rax
addq $0x30, %rax
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x480(%rax)
movq 0xa0(%rsp), %rax
movq 0x1d0(%rax), %rax
cmpl $-0x2, %eax
jbe 0x129d4e
movq 0xa0(%rsp), %rdi
leaq 0x16294(%rip), %rsi     # 0x13ffdd
callq 0x113860
movq 0xa0(%rsp), %rax
movq 0x1d0(%rax), %rax
addq $0x1, %rax
movq 0xa0(%rsp), %rcx
movl 0x484(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x129de9
movq 0xa0(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq 0x1e8(%rax), %rsi
callq 0x1136d0
movq 0xa0(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq 0x1d0(%rax), %rax
addq $0x1, %rax
movl %eax, %eax
movl %eax, %esi
callq 0x1135b0
movq %rax, %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0x1e8(%rax)
movq 0xa0(%rsp), %rax
movq 0x1d0(%rax), %rax
addq $0x1, %rax
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x484(%rax)
movq 0xa0(%rsp), %rax
movq 0x1e8(%rax), %rdi
movq 0xa0(%rsp), %rax
movq 0x1d0(%rax), %rdx
addq $0x1, %rdx
xorl %esi, %esi
callq 0xf280
movq 0xa0(%rsp), %rax
movl 0x120(%rax), %ecx
orl $0x40, %ecx
movl %ecx, 0x120(%rax)
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)