// File: /workspace/github_cpp_makefile_star2_O1/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:
cmpb $0x3, 0x10(%rdi)
jne 0x8fdb0
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %rax
movl (%rdi), %r9d
movzbl 0x11(%rdi), %ecx
cmpl $0x7, %ecx
ja 0x8fca7
cmpl $0x4, %ecx
je 0x8fc4d
cmpl $0x2, %ecx
je 0x8fbf6
cmpl $0x1, %ecx
jne 0x8fc9b
testl %r9d, %r9d
je 0x8fc9b
movl %r9d, %r14d
negl %r14d
andl $0x7, %r14d
leal -0x1(%r9), %ecx
shrl $0x3, %ecx
addq %rsi, %rcx
leaq (%r9,%rsi), %r10
decq %r10
xorl %r11d, %r11d
movl %r9d, %ebx
movzbl (%rcx), %ebp
btl %r14d, %ebp
setb (%r10)
xorl %r15d, %r15d
cmpl $0x7, %r14d
leal 0x1(%r14), %ebp
sete %r15b
cmovel %r11d, %ebp
subq %r15, %rcx
decq %r10
movl %ebp, %r14d
decl %ebx
jne 0x8fbc6
jmp 0x8fc9b
testl %r9d, %r9d
je 0x8fc9b
leal 0x6(,%r9,2), %ecx
notl %ecx
andl $0x6, %ecx
leal -0x1(%r9), %r10d
shrl $0x2, %r10d
addq %rsi, %r10
leaq (%r9,%rsi), %r11
decq %r11
xorl %ebx, %ebx
movl %r9d, %ebp
movzbl (%r10), %r14d
shrl %cl, %r14d
andb $0x3, %r14b
movb %r14b, (%r11)
xorl %r14d, %r14d
cmpl $0x6, %ecx
leal 0x2(%rcx), %ecx
sete %r14b
cmovel %ebx, %ecx
subq %r14, %r10
decq %r11
decl %ebp
jne 0x8fc23
jmp 0x8fc9b
testl %r9d, %r9d
je 0x8fc9b
leal (,%r9,4), %ecx
andl $0x4, %ecx
leal -0x1(%r9), %r10d
shrl %r10d
addq %rsi, %r10
leaq (%r9,%rsi), %r11
decq %r11
xorl %ebx, %ebx
movl %r9d, %ebp
movzbl (%r10), %r14d
shrl %cl, %r14d
andb $0xf, %r14b
movb %r14b, (%r11)
xorl %r14d, %r14d
cmpl $0x4, %ecx
leal 0x4(%rcx), %ecx
sete %r14b
cmovel %ebx, %ecx
subq %r14, %r10
decq %r11
decl %ebp
jne 0x8fc73
movb $0x8, %cl
movb %cl, 0x11(%rdi)
movb %cl, 0x13(%rdi)
movq %r9, 0x8(%rdi)
cmpb $0x8, 0x11(%rdi)
jne 0x8fda8
testq %rax, %rax
je 0x8fd3a
leal (,%r9,4), %ecx
movb $0x4, %r10b
movb $0x6, %r11b
movb $0x20, %bl
testl %r9d, %r9d
je 0x8fd95
leaq (%rsi,%rcx), %r14
decq %r14
addq %r9, %rsi
decq %rsi
xorl %r15d, %r15d
movzbl (%rsi,%r15), %r12d
movb $-0x1, %bpl
cmpl %r8d, %r12d
jge 0x8fcf4
movb (%rax,%r12), %bpl
movb %bpl, (%r14,%r15,4)
movzbl (%rsi,%r15), %r12d
leaq (%r12,%r12,2), %r12
movb 0x2(%rdx,%r12), %bpl
movb %bpl, -0x1(%r14,%r15,4)
movzbl (%rsi,%r15), %r12d
leaq (%r12,%r12,2), %r12
movb 0x1(%rdx,%r12), %bpl
movb %bpl, -0x2(%r14,%r15,4)
movzbl (%rsi,%r15), %r12d
leaq (%r12,%r12,2), %r12
movb (%rdx,%r12), %bpl
movb %bpl, -0x3(%r14,%r15,4)
decq %r15
decl %r9d
jne 0x8fce3
jmp 0x8fd95
leal (%r9,%r9,2), %ecx
movb $0x3, %r10b
movb $0x2, %r11b
movb $0x18, %bl
testl %r9d, %r9d
je 0x8fd95
leaq (%rsi,%rcx), %rax
decq %rax
addq %r9, %rsi
decq %rsi
movzbl (%rsi), %r8d
leaq (%r8,%r8,2), %r8
movb 0x2(%rdx,%r8), %r8b
movb %r8b, (%rax)
movzbl (%rsi), %r8d
leaq (%r8,%r8,2), %r8
movb 0x1(%rdx,%r8), %r8b
movb %r8b, -0x1(%rax)
movzbl (%rsi), %r8d
leaq (%r8,%r8,2), %r8
movb (%rdx,%r8), %r8b
movb %r8b, -0x2(%rax)
decq %rsi
addq $-0x3, %rax
decl %r9d
jne 0x8fd58
movb $0x8, 0x11(%rdi)
movb %bl, 0x13(%rdi)
movq %rcx, 0x8(%rdi)
movb %r11b, 0x10(%rdi)
movb %r10b, 0x12(%rdi)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq