// File: /workspace/github_cpp_makefile_star2_O1/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 0x8fe5e
cmpb $0x2, %cl
setne %cl
testq %rdx, %rdx
sete %r8b
orb %cl, %r8b
jne 0x90182
movzbl 0x11(%rdi), %ecx
cmpl $0x10, %ecx
je 0x8fefa
cmpl $0x8, %ecx
jne 0x8ffb7
testl %eax, %eax
je 0x8ffb7
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 0x8fe2f
cmpb %dl, -0x1(%rsi)
jne 0x8fe2f
cmpb %r8b, (%rsi)
jne 0x8fe2f
xorl %r11d, %r11d
jmp 0x8fe32
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 0x8fe1a
jmp 0x8ffb7
testq %rdx, %rdx
je 0x8fe6a
movzwl 0x8(%rdx), %r8d
jmp 0x8fe6d
xorl %r8d, %r8d
movzbl 0x11(%rdi), %ecx
cmpl $0x7, %ecx
ja 0x9009e
cmpl $0x4, %ecx
je 0x9002e
cmpl $0x2, %ecx
je 0x8ffca
cmpl $0x1, %ecx
jne 0x90092
xorl %ecx, %ecx
testb $0x1, %r8b
movl $0xff, %r8d
cmovel %ecx, %r8d
testl %eax, %eax
je 0x90092
movl %eax, %ebx
negl %ebx
andl $0x7, %ebx
leal -0x1(%rax), %r9d
shrl $0x3, %r9d
addq %rsi, %r9
leaq (%rax,%rsi), %r10
decq %r10
movl %eax, %r11d
movzbl (%r9), %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 %ecx, %ebx
subq %r14, %r9
decq %r10
decl %r11d
jne 0x8fec9
jmp 0x90092
testl %eax, %eax
je 0x8ffb7
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 0x8ff72
cmpb %cl, -0x4(%rsi)
jne 0x8ff72
movzbl -0x3(%rsi), %r14d
cmpw %r14w, %r10w
jne 0x8ff72
cmpb %r9b, -0x2(%rsi)
jne 0x8ff72
movzbl -0x1(%rsi), %r14d
cmpw %r14w, %r11w
jne 0x8ff72
cmpb %dl, (%rsi)
jne 0x8ff72
xorl %r14d, %r14d
jmp 0x8ff75
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 0x8ff3d
movb $0x6, 0x10(%rdi)
movb $0x4, 0x12(%rdi)
movb 0x11(%rdi), %cl
shlb $0x2, %cl
jmp 0x9015b
andl $0x3, %r8d
imull $0x55, %r8d, %r8d
testl %eax, %eax
je 0x90092
leal 0x6(,%rax,2), %ecx
notl %ecx
andl $0x6, %ecx
leal -0x1(%rax), %r9d
shrl $0x2, %r9d
addq %rsi, %r9
leaq (%rax,%rsi), %r10
decq %r10
xorl %r11d, %r11d
movl %eax, %ebx
movzbl (%r9), %ebp
shrl %cl, %ebp
andb $0x3, %bpl
movzbl %bpl, %ebp
imull $0x55, %ebp, %ebp
movb %bpl, (%r10)
xorl %r14d, %r14d
cmpl $0x6, %ecx
leal 0x2(%rcx), %ecx
sete %r14b
cmovel %r11d, %ecx
subq %r14, %r9
decq %r10
decl %ebx
jne 0x8fffd
jmp 0x90092
andl $0xf, %r8d
movl %r8d, %ecx
shll $0x4, %ecx
orl %r8d, %ecx
movl %ecx, %r8d
testl %eax, %eax
je 0x90092
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 0x90060
movb $0x8, %cl
movb %cl, 0x11(%rdi)
movb %cl, 0x13(%rdi)
movq %rax, 0x8(%rdi)
testq %rdx, %rdx
je 0x90182
movzbl 0x11(%rdi), %ecx
cmpl $0x10, %ecx
je 0x900f8
cmpl $0x8, %ecx
jne 0x9014e
testl %eax, %eax
je 0x9014e
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 0x900d6
jmp 0x9014e
testl %eax, %eax
je 0x9014e
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 0x90124
cmpb %cl, -0x1(%rsi,%r8)
jne 0x90124
xorl %r10d, %r10d
jmp 0x90127
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 0x9010c
movb $0x4, 0x10(%rdi)
movb $0x2, 0x12(%rdi)
movb 0x11(%rdi), %cl
addb %cl, %cl
movb %cl, 0x13(%rdi)
cmpb $0x8, %cl
jb 0x9016f
shrb $0x3, %cl
movzbl %cl, %ecx
imulq %rax, %rcx
jmp 0x9017e
movzbl %cl, %ecx
imulq %rax, %rcx
addq $0x7, %rcx
shrq $0x3, %rcx
movq %rcx, 0x8(%rdi)
popq %rbx
popq %r14
popq %rbp
retq