// File: tomfunkhouser[P]gaps/pkgs/png/pngtrans.c
// Function: png_do_strip_filler
void /* PRIVATE */
png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
{
   png_debug(1, "in png_do_strip_filler");

   {
      png_bytep sp=row;
      png_bytep dp=row;
      png_uint_32 row_width=row_info->width;
      png_uint_32 i;

      if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
          (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
          (flags & PNG_FLAG_STRIP_ALPHA))) &&
          row_info->channels == 4)
      {
         if (row_info->bit_depth == 8)
         {
            /* This converts from RGBX or RGBA to RGB */
            if (flags & PNG_FLAG_FILLER_AFTER)
            {
               dp+=3; sp+=4;
               for (i = 1; i < row_width; i++)
               {
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  sp++;
               }
            }
            /* This converts from XRGB or ARGB to RGB */
            else
            {
               for (i = 0; i < row_width; i++)
               {
                  sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
               }
            }
            row_info->pixel_depth = 24;
            row_info->rowbytes = row_width * 3;
         }
         else /* if (row_info->bit_depth == 16) */
         {
            if (flags & PNG_FLAG_FILLER_AFTER)
            {
               /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
               sp += 8; dp += 6;
               for (i = 1; i < row_width; i++)
               {
                  /* This could be (although png_memcpy is probably slower):
                  png_memcpy(dp, sp, 6);
                  sp += 8;
                  dp += 6;
                  */

                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  sp += 2;
               }
            }
            else
            {
               /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
               for (i = 0; i < row_width; i++)
               {
                  /* This could be (although png_memcpy is probably slower):
                  png_memcpy(dp, sp, 6);
                  sp += 8;
                  dp += 6;
                  */

                  sp+=2;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
               }
            }
            row_info->pixel_depth = 48;
            row_info->rowbytes = row_width * 6;
         }
         row_info->channels = 3;
      }
      else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
         (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
         (flags & PNG_FLAG_STRIP_ALPHA))) &&
          row_info->channels == 2)
      {
         if (row_info->bit_depth == 8)
         {
            /* This converts from GX or GA to G */
            if (flags & PNG_FLAG_FILLER_AFTER)
            {
               for (i = 0; i < row_width; i++)
               {
                  *dp++ = *sp++;
                  sp++;
               }
            }
            /* This converts from XG or AG to G */
            else
            {
               for (i = 0; i < row_width; i++)
               {
                  sp++;
                  *dp++ = *sp++;
               }
            }
            row_info->pixel_depth = 8;
            row_info->rowbytes = row_width;
         }
         else /* if (row_info->bit_depth == 16) */
         {
            if (flags & PNG_FLAG_FILLER_AFTER)
            {
               /* This converts from GGXX or GGAA to GG */
               sp += 4; dp += 2;
               for (i = 1; i < row_width; i++)
               {
                  *dp++ = *sp++;
                  *dp++ = *sp++;
                  sp += 2;
               }
            }
            else
            {
               /* This converts from XXGG or AAGG to GG */
               for (i = 0; i < row_width; i++)
               {
                  sp += 2;
                  *dp++ = *sp++;
                  *dp++ = *sp++;
               }
            }
            row_info->pixel_depth = 16;
            row_info->rowbytes = row_width * 2;
         }
         row_info->channels = 1;
      }
      if (flags & PNG_FLAG_STRIP_ALPHA)
        row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
   }
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movl %edx, -0x14(%rsp)
movq -0x10(%rsp), %rax
movq %rax, -0x20(%rsp)
movq -0x10(%rsp), %rax
movq %rax, -0x28(%rsp)
movq -0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rsp)
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x2, %eax
je 0x12a4d1
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x6, %eax
jne 0x12a924
movl -0x14(%rsp), %eax
andq $0x400000, %rax         # imm = 0x400000
cmpq $0x0, %rax
je 0x12a924
movq -0x8(%rsp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x4, %eax
jne 0x12a924
movq -0x8(%rsp), %rax
movzbl 0x11(%rax), %eax
cmpl $0x8, %eax
jne 0x12a696
movl -0x14(%rsp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x12a5ce
movq -0x28(%rsp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rsp)
movq -0x20(%rsp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rsp)
movl $0x1, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x2c(%rsp), %eax
jae 0x12a5c9
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rsp)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x12a52b
jmp 0x12a676
movl $0x0, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x2c(%rsp), %eax
jae 0x12a674
movq -0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rsp)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x12a5d6
jmp 0x12a676
movq -0x8(%rsp), %rax
movb $0x18, 0x13(%rax)
imull $0x3, -0x2c(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0x12a916
movl -0x14(%rsp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x12a7e1
movq -0x20(%rsp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rsp)
movq -0x28(%rsp), %rax
addq $0x6, %rax
movq %rax, -0x28(%rsp)
movl $0x1, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x2c(%rsp), %eax
jae 0x12a7dc
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rsp)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x12a6cc
jmp 0x12a8fb
movl $0x0, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x2c(%rsp), %eax
jae 0x12a8f9
movq -0x20(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rsp)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x12a7e9
jmp 0x12a8fb
movq -0x8(%rsp), %rax
movb $0x30, 0x13(%rax)
imull $0x6, -0x2c(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rsp), %rax
movb $0x3, 0x12(%rax)
jmp 0x12ab9c
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x0, %eax
je 0x12a958
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x4, %eax
jne 0x12ab9a
movl -0x14(%rsp), %eax
andq $0x400000, %rax         # imm = 0x400000
cmpq $0x0, %rax
je 0x12ab9a
movq -0x8(%rsp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x2, %eax
jne 0x12ab9a
movq -0x8(%rsp), %rax
movzbl 0x11(%rax), %eax
cmpl $0x8, %eax
jne 0x12aa51
movl -0x14(%rsp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x12a9df
movl $0x0, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x2c(%rsp), %eax
jae 0x12a9dd
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rsp)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x12a992
jmp 0x12aa34
movl $0x0, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x2c(%rsp), %eax
jae 0x12aa32
movq -0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rsp)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x12a9e7
jmp 0x12aa34
movq -0x8(%rsp), %rax
movb $0x8, 0x13(%rax)
movl -0x2c(%rsp), %eax
movl %eax, %ecx
movq -0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0x12ab91
movl -0x14(%rsp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x12aafa
movq -0x20(%rsp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rsp)
movq -0x28(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rsp)
movl $0x1, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x2c(%rsp), %eax
jae 0x12aaf8
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rsp)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x12aa87
jmp 0x12ab75
movl $0x0, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0x2c(%rsp), %eax
jae 0x12ab73
movq -0x20(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rsp)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rsp)
movb (%rax), %cl
movq -0x28(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rsp)
movb %cl, (%rax)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x12ab02
jmp 0x12ab75
movq -0x8(%rsp), %rax
movb $0x10, 0x13(%rax)
movl -0x2c(%rsp), %eax
shll %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rsp), %rax
movb $0x1, 0x12(%rax)
jmp 0x12ab9c
movl -0x14(%rsp), %eax
andq $0x400000, %rax         # imm = 0x400000
cmpq $0x0, %rax
je 0x12abbb
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %ecx
andl $-0x5, %ecx
movb %cl, 0x10(%rax)
retq
nopl (%rax)