// File: /workspace/github_cpp_makefile_star2_O1/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 0xa0749
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movzbl 0x13(%rdi), %r15d
movl (%rdi), %ebp
movslq %edx, %rbx
cmpl $0x4, %r15d
movq %rdi, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
leaq 0x135ba(%rip), %rax     # 0xb3ae0
je 0xa061c
cmpl $0x2, %r15d
je 0xa05aa
cmpl $0x1, %r15d
jne 0xa069c
movl (%rax,%rbx,4), %edx
xorl %eax, %eax
cmpl %ebp, %edx
jae 0xa06e2
leaq 0x135b0(%rip), %rcx     # 0xb3b00
movl (%rcx,%rbx,4), %edi
movl $0x7, %ecx
movq %r14, %rsi
movl %eax, %r8d
movl %edx, %eax
shrl $0x3, %eax
movzbl (%r14,%rax), %r9d
movl %edx, %eax
notb %al
movzbl %al, %r10d
andl $0x7, %r10d
xorl %eax, %eax
btl %r10d, %r9d
setb %al
shll %cl, %eax
orl %r8d, %eax
testl %ecx, %ecx
je 0xa058a
decl %ecx
jmp 0xa0596
movb %al, (%rsi)
incq %rsi
movl $0x7, %ecx
xorl %eax, %eax
addl %edi, %edx
cmpl %ebp, %edx
jb 0xa055b
cmpl $0x7, %ecx
sete %cl
movq %rsi, %r14
jmp 0xa06e4
movl (%rax,%rbx,4), %esi
xorl %edx, %edx
cmpl %ebp, %esi
jae 0xa0691
leaq 0x13542(%rip), %rax     # 0xb3b00
movl (%rax,%rbx,4), %edi
leal (%rsi,%rsi), %r9d
leal (%rdi,%rdi), %r10d
movl $0x6, %eax
movq %r14, %r8
movl %edx, %r11d
movl %esi, %ecx
shrl $0x2, %ecx
movzbl (%r14,%rcx), %edx
movl %r9d, %ecx
notb %cl
andb $0x6, %cl
shrl %cl, %edx
andl $0x3, %edx
movl %eax, %ecx
shll %cl, %edx
orl %r11d, %edx
testl %eax, %eax
je 0xa05fb
addl $-0x2, %eax
jmp 0xa0608
movb %dl, (%r8)
incq %r8
movl $0x6, %eax
xorl %edx, %edx
addl %edi, %esi
addl %r10d, %r9d
cmpl %ebp, %esi
jb 0xa05d1
cmpl $0x6, %eax
sete %al
movq %r8, %r14
jmp 0xa0693
movl (%rax,%rbx,4), %esi
xorl %edx, %edx
cmpl %ebp, %esi
jae 0xa0691
leaq 0x134d4(%rip), %rax     # 0xb3b00
movl (%rax,%rbx,4), %edi
leal (,%rsi,4), %r8d
leal (,%rdi,4), %r9d
movl $0x4, %eax
movq %r14, %r10
movl %edx, %r11d
movl %esi, %ecx
shrl %ecx
movzbl (%r14,%rcx), %edx
movl %r8d, %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %edx
andl $0xf, %edx
movl %eax, %ecx
shll %cl, %edx
orl %r11d, %edx
testl %eax, %eax
je 0xa0670
addl $-0x4, %eax
jmp 0xa067d
movb %dl, (%r10)
incq %r10
xorl %edx, %edx
movl $0x4, %eax
addl %edi, %esi
addl %r9d, %r8d
cmpl %ebp, %esi
jb 0xa0647
cmpl $0x4, %eax
sete %al
movq %r10, %r14
jmp 0xa0693
movb $0x1, %al
testb %al, %al
jne 0xa06eb
movb %dl, (%r14)
jmp 0xa06eb
movl (%rax,%rbx,4), %r13d
cmpl %ebp, %r13d
jae 0xa06eb
shrl $0x3, %r15d
leaq 0x13450(%rip), %rax     # 0xb3b00
movq 0x8(%rsp), %rcx
movl (%rax,%rcx,4), %ebx
movq %r14, %r12
movl %r13d, %esi
imulq %r15, %rsi
addq %r14, %rsi
cmpq %rsi, %r12
je 0xa06d5
movq %r12, %rdi
movq %r15, %rdx
callq 0xe370
addq %r15, %r12
addl %ebx, %r13d
cmpl %ebp, %r13d
jb 0xa06bb
jmp 0xa06eb
movb $0x1, %cl
testb %cl, %cl
jne 0xa06eb
movb %al, (%r14)
leaq 0x1340e(%rip), %rax     # 0xb3b00
movq 0x8(%rsp), %rdi
movl (%rax,%rdi,4), %ecx
movq 0x10(%rsp), %rsi
movl (%rsi), %edx
addl %ecx, %edx
leaq 0x133d6(%rip), %rax     # 0xb3ae0
movl (%rax,%rdi,4), %eax
notl %eax
addl %edx, %eax
xorl %edx, %edx
divl %ecx
movl %eax, (%rsi)
movzbl 0x13(%rsi), %ecx
cmpq $0x8, %rcx
leaq 0x18(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jb 0xa0739
shrl $0x3, %ecx
imulq %rax, %rcx
jmp 0xa0745
imulq %rax, %rcx
addq $0x7, %rcx
shrq $0x3, %rcx
movq %rcx, 0x8(%rsi)
retq