// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_do_read_interlace
void /* PRIVATE */
png_do_read_interlace(png_structp png_ptr)
{
   png_row_infop row_info = &(png_ptr->row_info);
   png_bytep row = png_ptr->row_buf + 1;
   int pass = png_ptr->pass;
   png_uint_32 transformations = png_ptr->transformations;
   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
   /* Offset to next interlace block */
   PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};

   png_debug(1, "in png_do_read_interlace");
   if (row != NULL && row_info != NULL)
   {
      png_uint_32 final_width;

      final_width = row_info->width * png_pass_inc[pass];

      switch (row_info->pixel_depth)
      {
         case 1:
         {
            png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
            png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
            int sshift, dshift;
            int s_start, s_end, s_inc;
            int jstop = png_pass_inc[pass];
            png_byte v;
            png_uint_32 i;
            int j;

#ifdef PNG_READ_PACKSWAP_SUPPORTED
            if (transformations & PNG_PACKSWAP)
            {
                sshift = (int)((row_info->width + 7) & 0x07);
                dshift = (int)((final_width + 7) & 0x07);
                s_start = 7;
                s_end = 0;
                s_inc = -1;
            }
            else
#endif
            {
                sshift = 7 - (int)((row_info->width + 7) & 0x07);
                dshift = 7 - (int)((final_width + 7) & 0x07);
                s_start = 0;
                s_end = 7;
                s_inc = 1;
            }

            for (i = 0; i < row_info->width; i++)
            {
               v = (png_byte)((*sp >> sshift) & 0x01);
               for (j = 0; j < jstop; j++)
               {
                  *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
                  *dp |= (png_byte)(v << dshift);
                  if (dshift == s_end)
                  {
                     dshift = s_start;
                     dp--;
                  }
                  else
                     dshift += s_inc;
               }
               if (sshift == s_end)
               {
                  sshift = s_start;
                  sp--;
               }
               else
                  sshift += s_inc;
            }
            break;
         }
         case 2:
         {
            png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
            png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
            int sshift, dshift;
            int s_start, s_end, s_inc;
            int jstop = png_pass_inc[pass];
            png_uint_32 i;

#ifdef PNG_READ_PACKSWAP_SUPPORTED
            if (transformations & PNG_PACKSWAP)
            {
               sshift = (int)(((row_info->width + 3) & 0x03) << 1);
               dshift = (int)(((final_width + 3) & 0x03) << 1);
               s_start = 6;
               s_end = 0;
               s_inc = -2;
            }
            else
#endif
            {
               sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
               dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
               s_start = 0;
               s_end = 6;
               s_inc = 2;
            }

            for (i = 0; i < row_info->width; i++)
            {
               png_byte v;
               int j;

               v = (png_byte)((*sp >> sshift) & 0x03);
               for (j = 0; j < jstop; j++)
               {
                  *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
                  *dp |= (png_byte)(v << dshift);
                  if (dshift == s_end)
                  {
                     dshift = s_start;
                     dp--;
                  }
                  else
                     dshift += s_inc;
               }
               if (sshift == s_end)
               {
                  sshift = s_start;
                  sp--;
               }
               else
                  sshift += s_inc;
            }
            break;
         }
         case 4:
         {
            png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
            png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
            int sshift, dshift;
            int s_start, s_end, s_inc;
            png_uint_32 i;
            int jstop = png_pass_inc[pass];

#ifdef PNG_READ_PACKSWAP_SUPPORTED
            if (transformations & PNG_PACKSWAP)
            {
               sshift = (int)(((row_info->width + 1) & 0x01) << 2);
               dshift = (int)(((final_width + 1) & 0x01) << 2);
               s_start = 4;
               s_end = 0;
               s_inc = -4;
            }
            else
#endif
            {
               sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
               dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
               s_start = 0;
               s_end = 4;
               s_inc = 4;
            }

            for (i = 0; i < row_info->width; i++)
            {
               png_byte v = (png_byte)((*sp >> sshift) & 0xf);
               int j;

               for (j = 0; j < jstop; j++)
               {
                  *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
                  *dp |= (png_byte)(v << dshift);
                  if (dshift == s_end)
                  {
                     dshift = s_start;
                     dp--;
                  }
                  else
                     dshift += s_inc;
               }
               if (sshift == s_end)
               {
                  sshift = s_start;
                  sp--;
               }
               else
                  sshift += s_inc;
            }
            break;
         }
         default:
         {
            png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
            png_bytep sp = row + (png_size_t)(row_info->width - 1)
                * pixel_bytes;
            png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;

            int jstop = png_pass_inc[pass];
            png_uint_32 i;

            for (i = 0; i < row_info->width; i++)
            {
               png_byte v[8];
               int j;

               png_memcpy(v, sp, pixel_bytes);
               for (j = 0; j < jstop; j++)
               {
                  png_memcpy(dp, v, pixel_bytes);
                  dp -= pixel_bytes;
               }
               sp -= pixel_bytes;
            }
            break;
         }
      }
      row_info->width = final_width;
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
   }
#ifndef PNG_READ_PACKSWAP_SUPPORTED
   transformations = transformations; /* Silence compiler warning */
#endif
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq 0x130(%rsp), %rax
addq $0x218, %rax            # imm = 0x218
movq %rax, 0x128(%rsp)
movq 0x130(%rsp), %rax
movq 0x1f0(%rax), %rax
addq $0x1, %rax
movq %rax, 0x120(%rsp)
movq 0x130(%rsp), %rax
movzbl 0x24c(%rax), %eax
movl %eax, 0x11c(%rsp)
movq 0x130(%rsp), %rax
movl 0x124(%rax), %eax
movl %eax, 0x118(%rsp)
movq 0x16f7e(%rip), %rax     # 0x13f040
movq %rax, 0xf0(%rsp)
movq 0x16f77(%rip), %rax     # 0x13f048
movq %rax, 0xf8(%rsp)
movq 0x16f70(%rip), %rax     # 0x13f050
movq %rax, 0x100(%rsp)
movl 0x16f6a(%rip), %eax     # 0x13f058
movl %eax, 0x108(%rsp)
cmpq $0x0, 0x120(%rsp)
je 0x128a0d
cmpq $0x0, 0x128(%rsp)
je 0x128a0d
movq 0x128(%rsp), %rax
movl (%rax), %eax
movslq 0x11c(%rsp), %rcx
movl 0xf0(%rsp,%rcx,4), %ecx
imull %ecx, %eax
movl %eax, 0xec(%rsp)
movq 0x128(%rsp), %rax
movzbl 0x13(%rax), %eax
movl %eax, 0x10(%rsp)
subl $0x1, %eax
je 0x12816e
jmp 0x12814d
movl 0x10(%rsp), %eax
subl $0x2, %eax
je 0x1283f9
jmp 0x12815c
movl 0x10(%rsp), %eax
subl $0x4, %eax
je 0x128680
jmp 0x128881
movq 0x120(%rsp), %rax
movq 0x128(%rsp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
shrl $0x3, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0xe0(%rsp)
movq 0x120(%rsp), %rax
movl 0xec(%rsp), %ecx
subl $0x1, %ecx
shrl $0x3, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0xd8(%rsp)
movslq 0x11c(%rsp), %rax
movl 0xf0(%rsp,%rax,4), %eax
movl %eax, 0xc0(%rsp)
movl 0x118(%rsp), %eax
andq $0x10000, %rax          # imm = 0x10000
cmpq $0x0, %rax
je 0x12822c
movq 0x128(%rsp), %rax
movl (%rax), %eax
addl $0x7, %eax
andl $0x7, %eax
movl %eax, 0xd4(%rsp)
movl 0xec(%rsp), %eax
addl $0x7, %eax
andl $0x7, %eax
movl %eax, 0xd0(%rsp)
movl $0x7, 0xcc(%rsp)
movl $0x0, 0xc8(%rsp)
movl $0xffffffff, 0xc4(%rsp) # imm = 0xFFFFFFFF
jmp 0x128286
movq 0x128(%rsp), %rax
movl (%rax), %ecx
addl $0x7, %ecx
andl $0x7, %ecx
movl $0x7, %eax
subl %ecx, %eax
movl %eax, 0xd4(%rsp)
movl 0xec(%rsp), %ecx
addl $0x7, %ecx
andl $0x7, %ecx
movl $0x7, %eax
subl %ecx, %eax
movl %eax, 0xd0(%rsp)
movl $0x0, 0xcc(%rsp)
movl $0x7, 0xc8(%rsp)
movl $0x1, 0xc4(%rsp)
movl $0x0, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
movq 0x128(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x1283f4
movq 0xe0(%rsp), %rax
movzbl (%rax), %eax
movl 0xd4(%rsp), %ecx
sarl %cl, %eax
andl $0x1, %eax
movb %al, 0xbf(%rsp)
movl $0x0, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
cmpl 0xc0(%rsp), %eax
jge 0x128393
movl $0x7, %ecx
subl 0xd0(%rsp), %ecx
movl $0x7f7f, %eax           # imm = 0x7F7F
sarl %cl, %eax
andl $0xff, %eax
movzbl %al, %edx
movq 0xd8(%rsp), %rax
movzbl (%rax), %ecx
andl %edx, %ecx
movb %cl, (%rax)
movzbl 0xbf(%rsp), %eax
movl 0xd0(%rsp), %ecx
shll %cl, %eax
movzbl %al, %edx
movq 0xd8(%rsp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl 0xd0(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jne 0x128366
movl 0xcc(%rsp), %eax
movl %eax, 0xd0(%rsp)
movq 0xd8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xd8(%rsp)
jmp 0x12837b
movl 0xc4(%rsp), %eax
addl 0xd0(%rsp), %eax
movl %eax, 0xd0(%rsp)
jmp 0x12837d
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x1282d1
movl 0xd4(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jne 0x1283c7
movl 0xcc(%rsp), %eax
movl %eax, 0xd4(%rsp)
movq 0xe0(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xe0(%rsp)
jmp 0x1283dc
movl 0xc4(%rsp), %eax
addl 0xd4(%rsp), %eax
movl %eax, 0xd4(%rsp)
jmp 0x1283de
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x128291
jmp 0x128994
movq 0x120(%rsp), %rax
movq 0x128(%rsp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
shrl $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0xa8(%rsp)
movq 0x120(%rsp), %rax
movl 0xec(%rsp), %ecx
subl $0x1, %ecx
shrl $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0xa0(%rsp)
movslq 0x11c(%rsp), %rax
movl 0xf0(%rsp,%rax,4), %eax
movl %eax, 0x88(%rsp)
movl 0x118(%rsp), %eax
andq $0x10000, %rax          # imm = 0x10000
cmpq $0x0, %rax
je 0x1284bb
movq 0x128(%rsp), %rax
movl (%rax), %eax
addl $0x3, %eax
andl $0x3, %eax
shll %eax
movl %eax, 0x9c(%rsp)
movl 0xec(%rsp), %eax
addl $0x3, %eax
andl $0x3, %eax
shll %eax
movl %eax, 0x98(%rsp)
movl $0x6, 0x94(%rsp)
movl $0x0, 0x90(%rsp)
movl $0xfffffffe, 0x8c(%rsp) # imm = 0xFFFFFFFE
jmp 0x128519
movq 0x128(%rsp), %rax
movl (%rax), %ecx
addl $0x3, %ecx
andl $0x3, %ecx
movl $0x3, %eax
subl %ecx, %eax
shll %eax
movl %eax, 0x9c(%rsp)
movl 0xec(%rsp), %ecx
addl $0x3, %ecx
andl $0x3, %ecx
movl $0x3, %eax
subl %ecx, %eax
shll %eax
movl %eax, 0x98(%rsp)
movl $0x0, 0x94(%rsp)
movl $0x6, 0x90(%rsp)
movl $0x2, 0x8c(%rsp)
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
movq 0x128(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x12867b
movq 0xa8(%rsp), %rax
movzbl (%rax), %eax
movl 0x9c(%rsp), %ecx
sarl %cl, %eax
andl $0x3, %eax
movb %al, 0x83(%rsp)
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0x88(%rsp), %eax
jge 0x12861a
movl $0x6, %ecx
subl 0x98(%rsp), %ecx
movl $0x3f3f, %eax           # imm = 0x3F3F
sarl %cl, %eax
andl $0xff, %eax
movzbl %al, %edx
movq 0xa0(%rsp), %rax
movzbl (%rax), %ecx
andl %edx, %ecx
movb %cl, (%rax)
movzbl 0x83(%rsp), %eax
movl 0x98(%rsp), %ecx
shll %cl, %eax
movzbl %al, %edx
movq 0xa0(%rsp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl 0x98(%rsp), %eax
cmpl 0x90(%rsp), %eax
jne 0x1285f3
movl 0x94(%rsp), %eax
movl %eax, 0x98(%rsp)
movq 0xa0(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0x128608
movl 0x8c(%rsp), %eax
addl 0x98(%rsp), %eax
movl %eax, 0x98(%rsp)
jmp 0x12860a
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x128561
movl 0x9c(%rsp), %eax
cmpl 0x90(%rsp), %eax
jne 0x12864e
movl 0x94(%rsp), %eax
movl %eax, 0x9c(%rsp)
movq 0xa8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xa8(%rsp)
jmp 0x128663
movl 0x8c(%rsp), %eax
addl 0x9c(%rsp), %eax
movl %eax, 0x9c(%rsp)
jmp 0x128665
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x128524
jmp 0x128994
movq 0x120(%rsp), %rax
movq 0x128(%rsp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0x120(%rsp), %rax
movl 0xec(%rsp), %ecx
subl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
movslq 0x11c(%rsp), %rax
movl 0xf0(%rsp,%rax,4), %eax
movl %eax, 0x4c(%rsp)
movl 0x118(%rsp), %eax
andq $0x10000, %rax          # imm = 0x10000
cmpq $0x0, %rax
je 0x12872a
movq 0x128(%rsp), %rax
movl (%rax), %eax
addl $0x1, %eax
andl $0x1, %eax
shll $0x2, %eax
movl %eax, 0x64(%rsp)
movl 0xec(%rsp), %eax
addl $0x1, %eax
andl $0x1, %eax
shll $0x2, %eax
movl %eax, 0x60(%rsp)
movl $0x4, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl $0xfffffffc, 0x54(%rsp) # imm = 0xFFFFFFFC
jmp 0x12877b
movq 0x128(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
andl $0x1, %ecx
movl $0x1, %eax
subl %ecx, %eax
shll $0x2, %eax
movl %eax, 0x64(%rsp)
movl 0xec(%rsp), %ecx
addl $0x1, %ecx
andl $0x1, %ecx
movl $0x1, %eax
subl %ecx, %eax
shll $0x2, %eax
movl %eax, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x4, 0x58(%rsp)
movl $0x4, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
movq 0x128(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x12887c
movq 0x70(%rsp), %rax
movzbl (%rax), %eax
movl 0x64(%rsp), %ecx
sarl %cl, %eax
andl $0xf, %eax
movb %al, 0x4b(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x12883c
movl $0x4, %ecx
subl 0x60(%rsp), %ecx
movl $0xf0f, %eax            # imm = 0xF0F
sarl %cl, %eax
andl $0xff, %eax
movzbl %al, %edx
movq 0x68(%rsp), %rax
movzbl (%rax), %ecx
andl %edx, %ecx
movb %cl, (%rax)
movzbl 0x4b(%rsp), %eax
movl 0x60(%rsp), %ecx
shll %cl, %eax
movzbl %al, %edx
movq 0x68(%rsp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl 0x60(%rsp), %eax
cmpl 0x58(%rsp), %eax
jne 0x12881e
movl 0x5c(%rsp), %eax
movl %eax, 0x60(%rsp)
movq 0x68(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x12882a
movl 0x54(%rsp), %eax
addl 0x60(%rsp), %eax
movl %eax, 0x60(%rsp)
jmp 0x12882c
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x1287b4
movl 0x64(%rsp), %eax
cmpl 0x58(%rsp), %eax
jne 0x12885e
movl 0x5c(%rsp), %eax
movl %eax, 0x64(%rsp)
movq 0x70(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x12886a
movl 0x54(%rsp), %eax
addl 0x64(%rsp), %eax
movl %eax, 0x64(%rsp)
jmp 0x12886c
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x128783
jmp 0x128994
movq 0x128(%rsp), %rax
movzbl 0x13(%rax), %eax
sarl $0x3, %eax
cltq
movq %rax, 0x38(%rsp)
movq 0x120(%rsp), %rax
movq 0x128(%rsp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq 0x38(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0x120(%rsp), %rax
movl 0xec(%rsp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq 0x38(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movslq 0x11c(%rsp), %rax
movl 0xf0(%rsp,%rax,4), %eax
movl %eax, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
movq 0x128(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x128992
leaq 0x18(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xf3d0
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0x12896b
movq 0x28(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xf3d0
movq 0x38(%rsp), %rdx
movq 0x28(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x128929
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x1288f9
jmp 0x128994
movl 0xec(%rsp), %ecx
movq 0x128(%rsp), %rax
movl %ecx, (%rax)
movq 0x128(%rsp), %rax
movzbl 0x13(%rax), %eax
cmpl $0x8, %eax
jl 0x1289d8
movl 0xec(%rsp), %eax
movq 0x128(%rsp), %rcx
movzbl 0x13(%rcx), %ecx
shrq $0x3, %rcx
imulq %rcx, %rax
movq %rax, 0x8(%rsp)
jmp 0x1289fc
movl 0xec(%rsp), %eax
movq 0x128(%rsp), %rcx
movzbl 0x13(%rcx), %ecx
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rcx
movq 0x128(%rsp), %rax
movq %rcx, 0x8(%rax)
addq $0x138, %rsp            # imm = 0x138
retq
nopw %cs:(%rax,%rax)