// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngrtran.c
// Function: png_do_unshift
void /* PRIVATE */
png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
{
   png_debug(1, "in png_do_unshift");

   if (
       row_info->color_type != PNG_COLOR_TYPE_PALETTE)
   {
      int shift[4];
      int channels = 0;
      int c;
      png_uint_16 value = 0;
      png_uint_32 row_width = row_info->width;

      if (row_info->color_type & PNG_COLOR_MASK_COLOR)
      {
         shift[channels++] = row_info->bit_depth - sig_bits->red;
         shift[channels++] = row_info->bit_depth - sig_bits->green;
         shift[channels++] = row_info->bit_depth - sig_bits->blue;
      }
      else
      {
         shift[channels++] = row_info->bit_depth - sig_bits->gray;
      }
      if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
      {
         shift[channels++] = row_info->bit_depth - sig_bits->alpha;
      }

      for (c = 0; c < channels; c++)
      {
         if (shift[c] <= 0)
            shift[c] = 0;
         else
            value = 1;
      }

      if (!value)
         return;

      switch (row_info->bit_depth)
      {
         case 2:
         {
            png_bytep bp;
            png_uint_32 i;
            png_uint_32 istop = row_info->rowbytes;

            for (bp = row, i = 0; i < istop; i++)
            {
               *bp >>= 1;
               *bp++ &= 0x55;
            }
            break;
         }

         case 4:
         {
            png_bytep bp = row;
            png_uint_32 i;
            png_uint_32 istop = row_info->rowbytes;
            png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
               (png_byte)((int)0xf >> shift[0]));

            for (i = 0; i < istop; i++)
            {
               *bp >>= shift[0];
               *bp++ &= mask;
            }
            break;
         }

         case 8:
         {
            png_bytep bp = row;
            png_uint_32 i;
            png_uint_32 istop = row_width * channels;

            for (i = 0; i < istop; i++)
            {
               *bp++ >>= shift[i%channels];
            }
            break;
         }

         case 16:
         {
            png_bytep bp = row;
            png_uint_32 i;
            png_uint_32 istop = channels * row_width;

            for (i = 0; i < istop; i++)
            {
               value = (png_uint_16)((*bp << 8) + *(bp + 1));
               value >>= shift[i%channels];
               *bp++ = (png_byte)(value >> 8);
               *bp++ = (png_byte)(value & 0xff);
            }
            break;
         }
      }
   }
}

// Assembly:
movb 0x10(%rdi), %r9b
cmpb $0x3, %r9b
je 0x83b5f
pushq %rbx
movzbl 0x11(%rdi), %eax
movl $0x1, %ecx
testb $0x2, %r9b
jne 0x83a07
movb 0x3(%rdx), %r11b
movl %ecx, %r10d
jmp 0x83a30
movb (%rdx), %r11b
movzbl 0x1(%rdx), %r8d
movl %eax, %r10d
subl %r8d, %r10d
movl %r10d, -0xc(%rsp)
movzbl 0x2(%rdx), %r8d
movl %eax, %r10d
subl %r8d, %r10d
movl %r10d, -0x8(%rsp)
movl $0x3, %r10d
movl (%rdi), %r8d
movzbl %r11b, %r11d
movl %eax, %ebx
subl %r11d, %ebx
movl %ebx, -0x10(%rsp)
testb $0x4, %r9b
je 0x83a5b
movzbl 0x4(%rdx), %edx
movl %eax, %r9d
subl %edx, %r9d
movl %r10d, %edx
incl %r10d
movl %r9d, -0x10(%rsp,%rdx,4)
movl %r10d, %r9d
xorl %edx, %edx
xorl %r11d, %r11d
xorl %r10d, %r10d
cmpq %r11, %r9
je 0x83a83
movl -0x10(%rsp,%r11,4), %ebx
testl %ebx, %ebx
cmovlel %edx, %ebx
movl %ebx, -0x10(%rsp,%r11,4)
cmovgl %ecx, %r10d
incq %r11
jmp 0x83a66
testw %r10w, %r10w
je 0x83b5e
addl $-0x2, %eax
rorl %eax
cmpl $0x7, %eax
ja 0x83b5e
leaq 0x1a04a(%rip), %rcx     # 0x9daec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rdi), %rax
xorl %ecx, %ecx
cmpl %ecx, %eax
je 0x83b5e
movb (%rsi,%rcx), %dl
shrb %dl
andb $0x55, %dl
movb %dl, (%rsi,%rcx)
incq %rcx
jmp 0x83ab1
imull %r9d, %r8d
xorl %edi, %edi
cmpl %edi, %r8d
je 0x83b5e
movl %edi, %eax
xorl %edx, %edx
divl %r9d
movb -0x10(%rsp,%rdx,4), %cl
movzbl (%rsi,%rdi), %eax
shrl %cl, %eax
movb %al, (%rsi,%rdi)
incq %rdi
jmp 0x83acf
movl -0x10(%rsp), %ecx
movl $0xf0, %r8d
shrl %cl, %r8d
movl $0xf, %eax
shrl %cl, %eax
movq 0x8(%rdi), %rdx
andl $-0x10, %r8d
orl %r8d, %eax
xorl %edi, %edi
cmpl %edi, %edx
je 0x83b5e
movzbl (%rsi,%rdi), %r8d
shrl %cl, %r8d
andl %eax, %r8d
movb %r8b, (%rsi,%rdi)
incq %rdi
jmp 0x83b12
imull %r9d, %r8d
xorl %edi, %edi
cmpl %edi, %r8d
je 0x83b5e
movzwl (%rsi,%rdi,2), %eax
rolw $0x8, %ax
movzwl %ax, %r10d
movl %edi, %eax
xorl %edx, %edx
divl %r9d
movb -0x10(%rsp,%rdx,4), %cl
shrl %cl, %r10d
rolw $0x8, %r10w
movw %r10w, (%rsi,%rdi,2)
incq %rdi
jmp 0x83b30
popq %rbx
retq