// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_do_write_interlace
void /* PRIVATE */
png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
{
   /* 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};

   png_debug(1, "in png_do_write_interlace");

   /* We don't have to do anything on the last pass (6) */
   if (pass < 6)
   {
      /* Each pixel depth is handled separately */
      switch (row_info->pixel_depth)
      {
         case 1:
         {
            png_bytep sp;
            png_bytep dp;
            int shift;
            int d;
            int value;
            png_uint_32 i;
            png_uint_32 row_width = row_info->width;

            dp = row;
            d = 0;
            shift = 7;
            for (i = png_pass_start[pass]; i < row_width;
               i += png_pass_inc[pass])
            {
               sp = row + (png_size_t)(i >> 3);
               value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
               d |= (value << shift);

               if (shift == 0)
               {
                  shift = 7;
                  *dp++ = (png_byte)d;
                  d = 0;
               }
               else
                  shift--;

            }
            if (shift != 7)
               *dp = (png_byte)d;
            break;
         }
         case 2:
         {
            png_bytep sp;
            png_bytep dp;
            int shift;
            int d;
            int value;
            png_uint_32 i;
            png_uint_32 row_width = row_info->width;

            dp = row;
            shift = 6;
            d = 0;
            for (i = png_pass_start[pass]; i < row_width;
               i += png_pass_inc[pass])
            {
               sp = row + (png_size_t)(i >> 2);
               value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
               d |= (value << shift);

               if (shift == 0)
               {
                  shift = 6;
                  *dp++ = (png_byte)d;
                  d = 0;
               }
               else
                  shift -= 2;
            }
            if (shift != 6)
                   *dp = (png_byte)d;
            break;
         }
         case 4:
         {
            png_bytep sp;
            png_bytep dp;
            int shift;
            int d;
            int value;
            png_uint_32 i;
            png_uint_32 row_width = row_info->width;

            dp = row;
            shift = 4;
            d = 0;
            for (i = png_pass_start[pass]; i < row_width;
               i += png_pass_inc[pass])
            {
               sp = row + (png_size_t)(i >> 1);
               value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
               d |= (value << shift);

               if (shift == 0)
               {
                  shift = 4;
                  *dp++ = (png_byte)d;
                  d = 0;
               }
               else
                  shift -= 4;
            }
            if (shift != 4)
               *dp = (png_byte)d;
            break;
         }
         default:
         {
            png_bytep sp;
            png_bytep dp;
            png_uint_32 i;
            png_uint_32 row_width = row_info->width;
            png_size_t pixel_bytes;

            /* Start at the beginning */
            dp = row;
            /* Find out how many bytes each pixel takes up */
            pixel_bytes = (row_info->pixel_depth >> 3);
            /* Loop through the row, only looking at the pixels that
               matter */
            for (i = png_pass_start[pass]; i < row_width;
               i += png_pass_inc[pass])
            {
               /* Find out where the original pixel is */
               sp = row + (png_size_t)i * pixel_bytes;
               /* Move the pixel */
               if (dp != sp)
                  png_memcpy(dp, sp, pixel_bytes);
               /* Next pixel */
               dp += pixel_bytes;
            }
            break;
         }
      }
      /* Set new row width */
      row_info->width = (row_info->width +
         png_pass_inc[pass] - 1 -
         png_pass_start[pass]) /
         png_pass_inc[pass];
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
            row_info->width);
   }
}

// Assembly:
cmpl $0x5, %edx
jg 0x9fdb8
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movzbl 0x13(%rdi), %r15d
movl (%rdi), %r13d
movslq %edx, %r12
leaq 0x13fae(%rip), %rax     # 0xb3b30
cmpl $0x4, %r15d
je 0x9fc8a
cmpl $0x2, %r15d
je 0x9fc11
cmpl $0x1, %r15d
jne 0x9fd07
movl (%rax,%r12,4), %eax
cmpl %r13d, %eax
jae 0x9fd6d
leaq 0x13fa0(%rip), %rcx     # 0xb3b50
movl (%rcx,%r12,4), %ebx
movq %r14, %rdx
movl %eax, %r11d
xorl %esi, %esi
movl $0x7, %ecx
movl %esi, %r8d
movl %r11d, %esi
shrl $0x3, %esi
movzbl (%r14,%rsi), %r9d
movl %r11d, %esi
notb %sil
movzbl %sil, %r10d
andl $0x7, %r10d
xorl %esi, %esi
btl %r10d, %r9d
setb %sil
shll %cl, %esi
orl %r8d, %esi
subl $0x1, %ecx
jb 0x9fbfe
addl %ebx, %r11d
cmpl %r13d, %r11d
jb 0x9fbc1
jmp 0x9fdc0
movb %sil, (%rdx)
incq %rdx
addl %ebx, %r11d
cmpl %r13d, %r11d
jb 0x9fbba
jmp 0x9fd6d
movl (%rax,%r12,4), %eax
cmpl %r13d, %eax
jae 0x9fd6d
leaq 0x13f2b(%rip), %rcx     # 0xb3b50
movl (%rcx,%r12,4), %ebx
leal (%rbx,%rbx), %r8d
movq %r14, %rdx
movl %eax, %r9d
leal (%r9,%r9), %r10d
xorl %esi, %esi
movl $0x6, %ebp
movl %esi, %r11d
movl %r9d, %ecx
shrl $0x2, %ecx
movzbl (%r14,%rcx), %esi
movl %r10d, %ecx
notb %cl
andb $0x6, %cl
shrl %cl, %esi
andl $0x3, %esi
movl %ebp, %ecx
shll %cl, %esi
orl %r11d, %esi
testl %ebp, %ebp
je 0x9fc77
addl $-0x2, %ebp
addl %ebx, %r9d
addl %r8d, %r10d
cmpl %r13d, %r9d
jb 0x9fc3e
jmp 0x9fd65
movb %sil, (%rdx)
incq %rdx
addl %ebx, %r9d
cmpl %r13d, %r9d
jb 0x9fc33
jmp 0x9fd6d
movl (%rax,%r12,4), %eax
cmpl %r13d, %eax
jae 0x9fd6d
leaq 0x13eb2(%rip), %rcx     # 0xb3b50
movl (%rcx,%r12,4), %ebx
leal (,%rbx,4), %r8d
movl %eax, %r9d
movq %r14, %rdx
leal (,%r9,4), %r10d
movl $0x4, %ebp
xorl %esi, %esi
movl %esi, %r11d
movl %r9d, %ecx
shrl %ecx
movzbl (%r14,%rcx), %esi
movl %r10d, %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %esi
andl $0xf, %esi
movl %ebp, %ecx
shll %cl, %esi
orl %r11d, %esi
testl %ebp, %ebp
je 0x9fcf7
addl $-0x4, %ebp
addl %ebx, %r9d
addl %r8d, %r10d
cmpl %r13d, %r9d
jb 0x9fcbf
jmp 0x9fdb9
movb %sil, (%rdx)
incq %rdx
addl %ebx, %r9d
cmpl %r13d, %r9d
jb 0x9fcb0
jmp 0x9fd6d
movl (%rax,%r12,4), %eax
cmpl %r13d, %eax
jae 0x9fd6d
movq %rdi, 0x10(%rsp)
shrl $0x3, %r15d
leaq 0x13e30(%rip), %rcx     # 0xb3b50
movq %r12, 0x8(%rsp)
movl (%rcx,%r12,4), %ebx
movl %eax, 0x4(%rsp)
movl %eax, %ebp
movq %r14, %r12
movl %ebp, %esi
imulq %r15, %rsi
addq %r14, %rsi
cmpq %rsi, %r12
je 0x9fd4b
movq %r12, %rdi
movq %r15, %rdx
callq 0xe370
addq %r15, %r12
addl %ebx, %ebp
cmpl %r13d, %ebp
jb 0x9fd32
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %eax
movq 0x8(%rsp), %r12
jmp 0x9fd6d
cmpl $0x6, %ebp
je 0x9fd6d
movb %sil, (%rdx)
leaq 0x13ddc(%rip), %rcx     # 0xb3b50
movl (%rcx,%r12,4), %ecx
movl (%rdi), %edx
addl %ecx, %edx
notl %eax
addl %edx, %eax
xorl %edx, %edx
divl %ecx
movl %eax, (%rdi)
movzbl 0x13(%rdi), %ecx
cmpq $0x8, %rcx
leaq 0x18(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jb 0x9fda8
shrl $0x3, %ecx
imulq %rax, %rcx
jmp 0x9fdb4
imulq %rax, %rcx
addq $0x7, %rcx
shrq $0x3, %rcx
movq %rcx, 0x8(%rdi)
retq
cmpl $0x4, %ebp
jne 0x9fd6a
jmp 0x9fd6d
cmpl $0x7, %ecx
jne 0x9fd6a
jmp 0x9fd6d