// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/png/pngrtran.c
// Function: png_do_expand
void /* PRIVATE */
png_do_expand(png_row_infop row_info, png_bytep row,
   png_color_16p trans_value)
{
   int shift, value;
   png_bytep sp, dp;
   png_uint_32 i;
   png_uint_32 row_width=row_info->width;

   png_debug(1, "in png_do_expand");

   {
      if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
      {
         png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);

         if (row_info->bit_depth < 8)
         {
            switch (row_info->bit_depth)
            {
               case 1:
               {
                  gray = (png_uint_16)((gray&0x01)*0xff);
                  sp = row + (png_size_t)((row_width - 1) >> 3);
                  dp = row + (png_size_t)row_width - 1;
                  shift = 7 - (int)((row_width + 7) & 0x07);
                  for (i = 0; i < row_width; i++)
                  {
                     if ((*sp >> shift) & 0x01)
                        *dp = 0xff;
                     else
                        *dp = 0;
                     if (shift == 7)
                     {
                        shift = 0;
                        sp--;
                     }
                     else
                        shift++;

                     dp--;
                  }
                  break;
               }

               case 2:
               {
                  gray = (png_uint_16)((gray&0x03)*0x55);
                  sp = row + (png_size_t)((row_width - 1) >> 2);
                  dp = row + (png_size_t)row_width - 1;
                  shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
                  for (i = 0; i < row_width; i++)
                  {
                     value = (*sp >> shift) & 0x03;
                     *dp = (png_byte)(value | (value << 2) | (value << 4) |
                        (value << 6));
                     if (shift == 6)
                     {
                        shift = 0;
                        sp--;
                     }
                     else
                        shift += 2;

                     dp--;
                  }
                  break;
               }

               case 4:
               {
                  gray = (png_uint_16)((gray&0x0f)*0x11);
                  sp = row + (png_size_t)((row_width - 1) >> 1);
                  dp = row + (png_size_t)row_width - 1;
                  shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
                  for (i = 0; i < row_width; i++)
                  {
                     value = (*sp >> shift) & 0x0f;
                     *dp = (png_byte)(value | (value << 4));
                     if (shift == 4)
                     {
                        shift = 0;
                        sp--;
                     }
                     else
                        shift = 4;

                     dp--;
                  }
                  break;
               }
            }

            row_info->bit_depth = 8;
            row_info->pixel_depth = 8;
            row_info->rowbytes = row_width;
         }

         if (trans_value != NULL)
         {
            if (row_info->bit_depth == 8)
            {
               gray = gray & 0xff;
               sp = row + (png_size_t)row_width - 1;
               dp = row + (png_size_t)(row_width << 1) - 1;
               for (i = 0; i < row_width; i++)
               {
                  if (*sp == gray)
                     *dp-- = 0;
                  else
                     *dp-- = 0xff;
                  *dp-- = *sp--;
               }
            }

            else if (row_info->bit_depth == 16)
            {
               png_byte gray_high = (gray >> 8) & 0xff;
               png_byte gray_low = gray & 0xff;
               sp = row + row_info->rowbytes - 1;
               dp = row + (row_info->rowbytes << 1) - 1;
               for (i = 0; i < row_width; i++)
               {
                  if (*(sp - 1) == gray_high && *(sp) == gray_low)
                  {
                     *dp-- = 0;
                     *dp-- = 0;
                  }
                  else
                  {
                     *dp-- = 0xff;
                     *dp-- = 0xff;
                  }
                  *dp-- = *sp--;
                  *dp-- = *sp--;
               }
            }

            row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
            row_info->channels = 2;
            row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
            row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
               row_width);
         }
      }
      else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
      {
         if (row_info->bit_depth == 8)
         {
            png_byte red = trans_value->red & 0xff;
            png_byte green = trans_value->green & 0xff;
            png_byte blue = trans_value->blue & 0xff;
            sp = row + (png_size_t)row_info->rowbytes - 1;
            dp = row + (png_size_t)(row_width << 2) - 1;
            for (i = 0; i < row_width; i++)
            {
               if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
                  *dp-- = 0;
               else
                  *dp-- = 0xff;
               *dp-- = *sp--;
               *dp-- = *sp--;
               *dp-- = *sp--;
            }
         }
         else if (row_info->bit_depth == 16)
         {
            png_byte red_high = (trans_value->red >> 8) & 0xff;
            png_byte green_high = (trans_value->green >> 8) & 0xff;
            png_byte blue_high = (trans_value->blue >> 8) & 0xff;
            png_byte red_low = trans_value->red & 0xff;
            png_byte green_low = trans_value->green & 0xff;
            png_byte blue_low = trans_value->blue & 0xff;
            sp = row + row_info->rowbytes - 1;
            dp = row + (png_size_t)(row_width << 3) - 1;
            for (i = 0; i < row_width; i++)
            {
               if (*(sp - 5) == red_high &&
                  *(sp - 4) == red_low &&
                  *(sp - 3) == green_high &&
                  *(sp - 2) == green_low &&
                  *(sp - 1) == blue_high &&
                  *(sp    ) == blue_low)
               {
                  *dp-- = 0;
                  *dp-- = 0;
               }
               else
               {
                  *dp-- = 0xff;
                  *dp-- = 0xff;
               }
               *dp-- = *sp--;
               *dp-- = *sp--;
               *dp-- = *sp--;
               *dp-- = *sp--;
               *dp-- = *sp--;
               *dp-- = *sp--;
            }
         }
         row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
         row_info->channels = 4;
         row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
      }
   }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl (%rdi), %eax
movb 0x10(%rdi), %cl
testb %cl, %cl
je 0x8f187
cmpb $0x2, %cl
setne %cl
testq %rdx, %rdx
sete %r8b
orb %cl, %r8b
jne 0x8f4ac
movzbl 0x11(%rdi), %ecx
cmpl $0x10, %ecx
je 0x8f22b
cmpl $0x8, %ecx
jne 0x8f2e8
testl %eax, %eax
je 0x8f2e8
leal (,%rax,4), %ecx
addq %rsi, %rcx
decq %rcx
movq 0x8(%rdi), %r8
leaq -0x1(%rsi,%r8), %rsi
movb 0x6(%rdx), %r8b
movb 0x2(%rdx), %r9b
movb 0x4(%rdx), %dl
movl %eax, %r10d
cmpb %r9b, -0x2(%rsi)
jne 0x8f158
cmpb %dl, -0x1(%rsi)
jne 0x8f158
cmpb %r8b, (%rsi)
jne 0x8f158
xorl %r11d, %r11d
jmp 0x8f15b
movb $-0x1, %r11b
movb %r11b, (%rcx)
movb (%rsi), %r11b
movb %r11b, -0x1(%rcx)
movb -0x1(%rsi), %r11b
movb %r11b, -0x2(%rcx)
movb -0x2(%rsi), %r11b
addq $-0x3, %rsi
movb %r11b, -0x3(%rcx)
addq $-0x4, %rcx
decl %r10d
jne 0x8f143
jmp 0x8f2e8
testq %rdx, %rdx
je 0x8f193
movzwl 0x8(%rdx), %r8d
jmp 0x8f196
xorl %r8d, %r8d
movzbl 0x11(%rdi), %ecx
cmpl $0x7, %ecx
ja 0x8f3c9
cmpl $0x1, %ecx
je 0x8f35f
cmpl $0x2, %ecx
je 0x8f2fb
cmpl $0x4, %ecx
jne 0x8f3ba
andl $0xf, %r8d
movl %r8d, %ecx
shll $0x4, %ecx
orl %r8d, %ecx
movl %ecx, %r8d
testl %eax, %eax
je 0x8f4b1
leal (,%rax,4), %ecx
andl $0x4, %ecx
leal -0x1(%rax), %r9d
shrl %r9d
addq %rsi, %r9
leaq (%rax,%rsi), %r10
decq %r10
movl %eax, %r11d
movzbl (%r9), %ebx
shrl %cl, %ebx
movl %ebx, %ebp
andl $0xf, %ebp
shll $0x4, %ebx
orl %ebp, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
testl %ecx, %ecx
sete %bpl
movb %bl, (%r10)
setne %r14b
subq %r14, %r9
shll $0x2, %ebp
decq %r10
movl %ebp, %ecx
decl %r11d
jne 0x8f1f4
jmp 0x8f3ba
testl %eax, %eax
je 0x8f2e8
movzwl 0x2(%rdx), %ecx
movl %ecx, %r8d
shrl $0x8, %r8d
movzwl 0x4(%rdx), %r9d
movl %r9d, %r10d
shrl $0x8, %r10d
movzwl 0x6(%rdx), %edx
movl %edx, %r11d
shrl $0x8, %r11d
leal (,%rax,8), %ebx
addq %rsi, %rbx
decq %rbx
movq 0x8(%rdi), %r14
addq %r14, %rsi
decq %rsi
movl %eax, %ebp
movzbl -0x5(%rsi), %r14d
cmpw %r14w, %r8w
jne 0x8f2a3
cmpb %cl, -0x4(%rsi)
jne 0x8f2a3
movzbl -0x3(%rsi), %r14d
cmpw %r14w, %r10w
jne 0x8f2a3
cmpb %r9b, -0x2(%rsi)
jne 0x8f2a3
movzbl -0x1(%rsi), %r14d
cmpw %r14w, %r11w
jne 0x8f2a3
cmpb %dl, (%rsi)
jne 0x8f2a3
xorl %r14d, %r14d
jmp 0x8f2a6
movb $-0x1, %r14b
movb %r14b, (%rbx)
movb %r14b, -0x1(%rbx)
movb (%rsi), %r14b
movb %r14b, -0x2(%rbx)
movb -0x1(%rsi), %r14b
movb %r14b, -0x3(%rbx)
movb -0x2(%rsi), %r14b
movb %r14b, -0x4(%rbx)
movb -0x3(%rsi), %r14b
movb %r14b, -0x5(%rbx)
movb -0x4(%rsi), %r14b
movb %r14b, -0x6(%rbx)
movb -0x5(%rsi), %r14b
addq $-0x6, %rsi
movb %r14b, -0x7(%rbx)
addq $-0x8, %rbx
decl %ebp
jne 0x8f26e
movb $0x6, 0x10(%rdi)
movb $0x4, 0x12(%rdi)
movb 0x11(%rdi), %cl
shlb $0x2, %cl
jmp 0x8f485
andl $0x3, %r8d
imull $0x55, %r8d, %r8d
xorl %r9d, %r9d
testl %eax, %eax
je 0x8f3bd
leal 0x6(,%rax,2), %ecx
notl %ecx
andl $0x6, %ecx
leal -0x1(%rax), %r10d
shrl $0x2, %r10d
addq %rsi, %r10
leaq (%rax,%rsi), %r11
decq %r11
movl %eax, %ebx
movzbl (%r10), %ebp
shrl %cl, %ebp
andb $0x3, %bpl
movzbl %bpl, %ebp
imull $0x55, %ebp, %ebp
movb %bpl, (%r11)
xorl %r14d, %r14d
cmpl $0x6, %ecx
leal 0x2(%rcx), %ecx
sete %r14b
cmovel %r9d, %ecx
subq %r14, %r10
decq %r11
decl %ebx
jne 0x8f32e
jmp 0x8f3ba
xorl %r9d, %r9d
testb $0x1, %r8b
movl $0xff, %r8d
cmovel %r9d, %r8d
testl %eax, %eax
je 0x8f3bd
movl %eax, %ebx
negl %ebx
andl $0x7, %ebx
leal -0x1(%rax), %ecx
shrl $0x3, %ecx
addq %rsi, %rcx
leaq (%rax,%rsi), %r10
decq %r10
movl %eax, %r11d
movzbl (%rcx), %ebp
btl %ebx, %ebp
movl $0x0, %ebp
sbbl %ebp, %ebp
movb %bpl, (%r10)
xorl %r14d, %r14d
cmpl $0x7, %ebx
leal 0x1(%rbx), %ebx
sete %r14b
cmovel %r9d, %ebx
subq %r14, %rcx
decq %r10
decl %r11d
jne 0x8f38e
movq %rax, %r9
movb $0x8, %cl
movb %cl, 0x11(%rdi)
movb %cl, 0x13(%rdi)
movq %r9, 0x8(%rdi)
testq %rdx, %rdx
je 0x8f4ac
cmpb $0x10, %cl
je 0x8f422
movzbl %cl, %ecx
cmpl $0x8, %ecx
jne 0x8f478
testl %eax, %eax
je 0x8f478
leal (%rax,%rax), %ecx
addq %rsi, %rcx
decq %rcx
leaq (%rax,%rsi), %rdx
decq %rdx
xorl %esi, %esi
movl %eax, %r9d
cmpb %r8b, (%rdx,%rsi)
setne %r10b
negb %r10b
movb %r10b, (%rcx,%rsi,2)
movb (%rdx,%rsi), %r10b
movb %r10b, -0x1(%rcx,%rsi,2)
decq %rsi
decl %r9d
jne 0x8f400
jmp 0x8f478
testl %eax, %eax
je 0x8f478
movzwl %r8w, %ecx
movl %ecx, %edx
shrl $0x8, %edx
movq 0x8(%rdi), %r8
movl %eax, %r9d
movzbl -0x2(%rsi,%r8), %r10d
cmpw %r10w, %dx
jne 0x8f44e
cmpb %cl, -0x1(%rsi,%r8)
jne 0x8f44e
xorl %r10d, %r10d
jmp 0x8f451
movb $-0x1, %r10b
movb %r10b, -0x1(%rsi,%r8,2)
movb %r10b, -0x2(%rsi,%r8,2)
movb -0x1(%rsi,%r8), %r10b
movb %r10b, -0x3(%rsi,%r8,2)
movb -0x2(%rsi,%r8), %r10b
movb %r10b, -0x4(%rsi,%r8,2)
addq $-0x2, %r8
decl %r9d
jne 0x8f436
movb $0x4, 0x10(%rdi)
movb $0x2, 0x12(%rdi)
movb 0x11(%rdi), %cl
addb %cl, %cl
movb %cl, 0x13(%rdi)
cmpb $0x8, %cl
jb 0x8f499
shrb $0x3, %cl
movzbl %cl, %ecx
imulq %rax, %rcx
jmp 0x8f4a8
movzbl %cl, %ecx
imulq %rax, %rcx
addq $0x7, %rcx
shrq $0x3, %rcx
movq %rcx, 0x8(%rdi)
popq %rbx
popq %r14
popq %rbp
retq
xorl %r9d, %r9d
jmp 0x8f3bd