// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngrtran.c
// Function: png_do_expand_palette
void /* PRIVATE */
png_do_expand_palette(png_row_infop row_info, png_bytep row,
   png_colorp palette, png_bytep trans_alpha, int num_trans)
{
   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_palette");

   if (
       row_info->color_type == PNG_COLOR_TYPE_PALETTE)
   {
      if (row_info->bit_depth < 8)
      {
         switch (row_info->bit_depth)
         {
            case 1:
            {
               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 = 1;
                  else
                     *dp = 0;
                  if (shift == 7)
                  {
                     shift = 0;
                     sp--;
                  }
                  else
                     shift++;

                  dp--;
               }
               break;
            }

            case 2:
            {
               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;
                  if (shift == 6)
                  {
                     shift = 0;
                     sp--;
                  }
                  else
                     shift += 2;

                  dp--;
               }
               break;
            }

            case 4:
            {
               sp = row + (png_size_t)((row_width - 1) >> 1);
               dp = row + (png_size_t)row_width - 1;
               shift = (int)((row_width & 0x01) << 2);
               for (i = 0; i < row_width; i++)
               {
                  value = (*sp >> shift) & 0x0f;
                  *dp = (png_byte)value;
                  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;
      }
      switch (row_info->bit_depth)
      {
         case 8:
         {
            if (trans_alpha != NULL)
            {
               sp = row + (png_size_t)row_width - 1;
               dp = row + (png_size_t)(row_width << 2) - 1;

               for (i = 0; i < row_width; i++)
               {
                  if ((int)(*sp) >= num_trans)
                     *dp-- = 0xff;
                  else
                     *dp-- = trans_alpha[*sp];
                  *dp-- = palette[*sp].blue;
                  *dp-- = palette[*sp].green;
                  *dp-- = palette[*sp].red;
                  sp--;
               }
               row_info->bit_depth = 8;
               row_info->pixel_depth = 32;
               row_info->rowbytes = row_width * 4;
               row_info->color_type = 6;
               row_info->channels = 4;
            }
            else
            {
               sp = row + (png_size_t)row_width - 1;
               dp = row + (png_size_t)(row_width * 3) - 1;

               for (i = 0; i < row_width; i++)
               {
                  *dp-- = palette[*sp].blue;
                  *dp-- = palette[*sp].green;
                  *dp-- = palette[*sp].red;
                  sp--;
               }

               row_info->bit_depth = 8;
               row_info->pixel_depth = 24;
               row_info->rowbytes = row_width * 3;
               row_info->color_type = 2;
               row_info->channels = 3;
            }
            break;
         }
      }
   }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
cmpb $0x3, 0x10(%rdi)
jne 0x81c84
movq %rcx, %rax
movl (%rdi), %r9d
movzbl 0x11(%rdi), %ecx
cmpl $0x7, %ecx
ja 0x81af9
cmpl $0x1, %ecx
je 0x81b51
cmpl $0x2, %ecx
je 0x81b07
cmpl $0x4, %ecx
jne 0x81b93
leal -0x1(%r9), %r10d
shrl %r10d
addq %rsi, %r10
leal (,%r9,4), %ecx
andl $0x4, %ecx
xorl %r11d, %r11d
movq %r9, %rbx
testl %ebx, %ebx
je 0x81b93
movzbl (%r10), %ebp
shrl %cl, %ebp
andb $0xf, %bpl
movb %bpl, -0x1(%rsi,%rbx)
xorl %r14d, %r14d
cmpl $0x4, %ecx
leal 0x4(%rcx), %ecx
cmovel %r11d, %ecx
sete %r14b
subq %r14, %r10
decq %rbx
jmp 0x81ac9
cmpl $0x8, %ecx
je 0x81b9f
jmp 0x81c84
leal -0x1(%r9), %r10d
shrl $0x2, %r10d
addq %rsi, %r10
leal 0x6(,%r9,2), %ecx
notl %ecx
andl $0x6, %ecx
xorl %r11d, %r11d
movq %r9, %rbx
testl %ebx, %ebx
je 0x81b93
movzbl (%r10), %ebp
shrl %cl, %ebp
andb $0x3, %bpl
movb %bpl, -0x1(%rsi,%rbx)
xorl %r14d, %r14d
cmpl $0x6, %ecx
leal 0x2(%rcx), %ecx
cmovel %r11d, %ecx
sete %r14b
subq %r14, %r10
decq %rbx
jmp 0x81b25
leal -0x1(%r9), %ecx
shrl $0x3, %ecx
addq %rsi, %rcx
movl %r9d, %ebx
negl %ebx
andl $0x7, %ebx
xorl %r10d, %r10d
movq %r9, %r11
testl %r11d, %r11d
je 0x81b93
movzbl (%rcx), %ebp
btl %ebx, %ebp
setb -0x1(%rsi,%r11)
xorl %r14d, %r14d
cmpl $0x7, %ebx
leal 0x1(%rbx), %ebx
cmovel %r10d, %ebx
sete %r14b
subq %r14, %rcx
decq %r11
jmp 0x81b69
movb $0x8, %cl
movb %cl, 0x11(%rdi)
movb %cl, 0x13(%rdi)
movq %r9, 0x8(%rdi)
testq %rax, %rax
je 0x81c1b
leal (,%r9,4), %ecx
leaq (%rsi,%rcx), %r10
decq %r10
addq %r9, %rsi
decq %rsi
negl %r9d
xorl %r11d, %r11d
cmpl %r11d, %r9d
je 0x81c12
movzbl (%rsi,%r11), %r14d
movb $-0x1, %bl
cmpl %r8d, %r14d
jge 0x81bd4
movb (%rax,%r14), %bl
movb %bl, (%r10,%r11,4)
movzbl (%rsi,%r11), %ebx
leaq (%rbx,%rbx,2), %rbx
movb 0x2(%rdx,%rbx), %bl
movb %bl, -0x1(%r10,%r11,4)
movzbl (%rsi,%r11), %ebx
leaq (%rbx,%rbx,2), %rbx
movb 0x1(%rdx,%rbx), %bl
movb %bl, -0x2(%r10,%r11,4)
movzbl (%rsi,%r11), %ebx
leaq (%rbx,%rbx,2), %rbx
movb (%rdx,%rbx), %bl
movb %bl, -0x3(%r10,%r11,4)
decq %r11
jmp 0x81bbf
movb $0x4, %al
movb $0x6, %dl
movb $0x20, %sil
jmp 0x81c72
leal (%r9,%r9,2), %ecx
movq %rcx, %rax
testl %r9d, %r9d
je 0x81c6b
movzbl -0x1(%rsi,%r9), %r8d
leaq (%r8,%r8,2), %r8
movb 0x2(%rdx,%r8), %r8b
movb %r8b, -0x1(%rsi,%rax)
movzbl -0x1(%rsi,%r9), %r8d
leaq (%r8,%r8,2), %r8
movb 0x1(%rdx,%r8), %r8b
movb %r8b, -0x2(%rsi,%rax)
movzbl -0x1(%rsi,%r9), %r8d
leaq (%r8,%r8,2), %r8
movb (%rdx,%r8), %r8b
movb %r8b, -0x3(%rsi,%rax)
decq %r9
addq $-0x3, %rax
jmp 0x81c22
movb $0x3, %al
movb $0x2, %dl
movb $0x18, %sil
movb $0x8, 0x11(%rdi)
movb %sil, 0x13(%rdi)
movq %rcx, 0x8(%rdi)
movb %dl, 0x10(%rdi)
movb %al, 0x12(%rdi)
popq %rbx
popq %r14
popq %rbp
retq