// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movl (%rdi), %eax
movb 0x10(%rdi), %cl
testb %cl, %cl
je 0x81d3a
cmpb $0x2, %cl
setne %cl
testq %rdx, %rdx
sete %r8b
orb %cl, %r8b
jne 0x82058
movzbl 0x11(%rdi), %ecx
cmpl $0x10, %ecx
je 0x81dc9
cmpl $0x8, %ecx
jne 0x81e8c
movb 0x2(%rdx), %cl
movb 0x4(%rdx), %r8b
movb 0x6(%rdx), %dl
movq 0x8(%rdi), %r9
addq %rsi, %r9
decq %r9
leal (,%rax,4), %r10d
addq %r10, %rsi
decq %rsi
movl %eax, %r10d
negl %r10d
xorl %r11d, %r11d
cmpl %r11d, %r10d
je 0x81e8c
cmpb %cl, -0x2(%r9)
jne 0x81d11
cmpb %r8b, -0x1(%r9)
jne 0x81d11
cmpb %dl, (%r9)
jne 0x81d11
xorl %ebx, %ebx
jmp 0x81d13
movb $-0x1, %bl
movb %bl, (%rsi,%r11,4)
movb (%r9), %bl
movb %bl, -0x1(%rsi,%r11,4)
movb -0x1(%r9), %bl
movb %bl, -0x2(%rsi,%r11,4)
movb -0x2(%r9), %bl
addq $-0x3, %r9
movb %bl, -0x3(%rsi,%r11,4)
decq %r11
jmp 0x81cf3
testq %rdx, %rdx
je 0x81d46
movzwl 0x8(%rdx), %r8d
jmp 0x81d49
xorl %r8d, %r8d
movzbl 0x11(%rdi), %ecx
cmpl $0x7, %ecx
ja 0x81f6a
cmpl $0x1, %ecx
je 0x81efa
cmpl $0x2, %ecx
je 0x81e9f
cmpl $0x4, %ecx
jne 0x81f5e
andl $0xf, %r8d
leal -0x1(%rax), %r9d
shrl %r9d
addq %rsi, %r9
leal (,%rax,4), %ecx
andl $0x4, %ecx
movq %rax, %r10
testl %r10d, %r10d
je 0x81f56
movzbl (%r9), %r11d
shrl %cl, %r11d
movl %r11d, %ebx
andl $0xf, %ebx
shll $0x4, %r11d
orl %ebx, %r11d
xorl %ebx, %ebx
xorl %r14d, %r14d
testl %ecx, %ecx
sete %bl
movb %r11b, -0x1(%rsi,%r10)
setne %r14b
subq %r14, %r9
shll $0x2, %ebx
decq %r10
movl %ebx, %ecx
jmp 0x81d8c
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
movq 0x8(%rdi), %rbx
addq %rsi, %rbx
decq %rbx
leal (,%rax,8), %r14d
addq %r14, %rsi
decq %rsi
movl %eax, %r14d
negl %r14d
xorl %r15d, %r15d
cmpl %r15d, %r14d
je 0x81e8c
movzbl -0x5(%rbx), %ebp
cmpw %bp, %r8w
jne 0x81e42
cmpb %cl, -0x4(%rbx)
jne 0x81e42
movzbl -0x3(%rbx), %ebp
cmpw %bp, %r10w
jne 0x81e42
cmpb %r9b, -0x2(%rbx)
jne 0x81e42
movzbl -0x1(%rbx), %ebp
cmpw %bp, %r11w
jne 0x81e42
cmpb %dl, (%rbx)
jne 0x81e42
xorl %ebp, %ebp
jmp 0x81e45
movb $-0x1, %bpl
movb %bpl, (%rsi,%r15,8)
movb %bpl, -0x1(%rsi,%r15,8)
movb (%rbx), %bpl
movb %bpl, -0x2(%rsi,%r15,8)
movb -0x1(%rbx), %bpl
movb %bpl, -0x3(%rsi,%r15,8)
movb -0x2(%rbx), %bpl
movb %bpl, -0x4(%rsi,%r15,8)
movb -0x3(%rbx), %bpl
movb %bpl, -0x5(%rsi,%r15,8)
movb -0x4(%rbx), %bpl
movb %bpl, -0x6(%rsi,%r15,8)
movb -0x5(%rbx), %bpl
addq $-0x6, %rbx
movb %bpl, -0x7(%rsi,%r15,8)
decq %r15
jmp 0x81e0c
movb $0x6, 0x10(%rdi)
movb $0x4, 0x12(%rdi)
movb 0x11(%rdi), %cl
shlb $0x2, %cl
jmp 0x82031
andl $0x3, %r8d
leal -0x1(%rax), %r9d
shrl $0x2, %r9d
addq %rsi, %r9
leal 0x6(,%rax,2), %ecx
notl %ecx
andl $0x6, %ecx
xorl %r10d, %r10d
movq %rax, %r11
testl %r11d, %r11d
je 0x81ef0
movzbl (%r9), %ebx
shrl %cl, %ebx
andb $0x3, %bl
movzbl %bl, %ebx
imull $0x55, %ebx, %ebx
movb %bl, -0x1(%rsi,%r11)
xorl %ebx, %ebx
cmpl $0x6, %ecx
leal 0x2(%rcx), %ecx
cmovel %r10d, %ecx
sete %bl
subq %rbx, %r9
decq %r11
jmp 0x81ec0
movzwl %r8w, %ecx
imull $0x55, %ecx, %r8d
jmp 0x81f5e
leal -0x1(%rax), %ecx
shrl $0x3, %ecx
addq %rsi, %rcx
movl %eax, %r11d
negl %r11d
andl $0x7, %r11d
xorl %r9d, %r9d
movq %rax, %r10
testl %r10d, %r10d
je 0x81f44
movzbl (%rcx), %ebx
btl %r11d, %ebx
movl $0x0, %ebx
sbbl %ebx, %ebx
movb %bl, -0x1(%rsi,%r10)
xorl %ebx, %ebx
cmpl $0x7, %r11d
leal 0x1(%r11), %r11d
cmovel %r9d, %r11d
sete %bl
subq %rbx, %rcx
decq %r10
jmp 0x81f13
xorl %ecx, %ecx
testb $0x1, %r8b
movl $0xff, %r8d
cmovel %ecx, %r8d
jmp 0x81f5e
movzwl %r8w, %ecx
imull $0x11, %ecx, %r8d
movb $0x8, %cl
movb %cl, 0x11(%rdi)
movb %cl, 0x13(%rdi)
movq %rax, 0x8(%rdi)
testq %rdx, %rdx
je 0x82058
cmpb $0x10, %cl
je 0x81fc0
movzbl %cl, %ecx
cmpl $0x8, %ecx
jne 0x82024
leal (%rax,%rax), %ecx
addq %rsi, %rcx
decq %rcx
movl %eax, %edx
negl %edx
addq %rax, %rsi
decq %rsi
xorl %r9d, %r9d
cmpl %r9d, %edx
je 0x82024
cmpb %r8b, (%rsi,%r9)
setne %r10b
negb %r10b
movb %r10b, (%rcx,%r9,2)
movb (%rsi,%r9), %r10b
movb %r10b, -0x1(%rcx,%r9,2)
decq %r9
jmp 0x81f9a
movzwl %r8w, %ecx
movl %ecx, %edx
shrl $0x8, %edx
movq 0x8(%rdi), %r9
leaq (%rsi,%r9), %r8
decq %r8
leaq (%rsi,%r9,2), %rsi
decq %rsi
movl %eax, %r9d
negl %r9d
xorl %r10d, %r10d
cmpl %r10d, %r9d
je 0x82024
movzbl -0x1(%r8,%r10,2), %r11d
cmpw %r11w, %dx
jne 0x82000
cmpb %cl, (%r8,%r10,2)
jne 0x82000
xorl %r11d, %r11d
jmp 0x82003
movb $-0x1, %r11b
movb %r11b, (%rsi,%r10,4)
movb %r11b, -0x1(%rsi,%r10,4)
movb (%r8,%r10,2), %r11b
movb %r11b, -0x2(%rsi,%r10,4)
movb -0x1(%r8,%r10,2), %r11b
movb %r11b, -0x3(%rsi,%r10,4)
decq %r10
jmp 0x81fe4
movb $0x4, 0x10(%rdi)
movb $0x2, 0x12(%rdi)
movb 0x11(%rdi), %cl
addb %cl, %cl
movb %cl, 0x13(%rdi)
cmpb $0x8, %cl
jb 0x82045
shrb $0x3, %cl
movzbl %cl, %ecx
imulq %rax, %rcx
jmp 0x82054
movzbl %cl, %ecx
imulq %rax, %rcx
addq $0x7, %rcx
shrq $0x3, %rcx
movq %rcx, 0x8(%rdi)
popq %rbx
popq %r14
popq %r15
popq %rbp
retq