// File: /workspace/github_cpp_makefile_star2_O3/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), %r8b
cmpb $0x3, %r8b
je 0x9115d
pushq %rbx
movzbl 0x11(%rdi), %eax
testb $0x2, %r8b
jne 0x90fef
movb 0x3(%rdx), %r10b
movl $0x1, %r9d
jmp 0x91016
movb (%rdx), %r10b
movzbl 0x1(%rdx), %ecx
movl %eax, %r9d
subl %ecx, %r9d
movl %r9d, -0xc(%rsp)
movzbl 0x2(%rdx), %ecx
movl %eax, %r9d
subl %ecx, %r9d
movl %r9d, -0x8(%rsp)
movl $0x3, %r9d
movl (%rdi), %ecx
movzbl %r10b, %r10d
movl %eax, %r11d
subl %r10d, %r11d
movl %r11d, -0x10(%rsp)
testb $0x4, %r8b
je 0x91042
movzbl 0x4(%rdx), %edx
movl %eax, %r8d
subl %edx, %r8d
movl %r9d, %edx
incl %r9d
movl %r8d, -0x10(%rsp,%rdx,4)
movl %r9d, %r8d
xorl %edx, %edx
movl $0x1, %r9d
xorl %r11d, %r11d
xorl %r10d, %r10d
movl -0x10(%rsp,%r11,4), %ebx
testl %ebx, %ebx
cmovlel %edx, %ebx
movl %ebx, -0x10(%rsp,%r11,4)
cmovgl %r9d, %r10d
incq %r11
cmpq %r11, %r8
jne 0x91053
testw %r10w, %r10w
je 0x9115c
addl $-0x2, %eax
rorl %eax
cmpl $0x7, %eax
ja 0x9115c
leaq 0x1bd7f(%rip), %rdx     # 0xace0c
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x8(%rdi), %rax
testl %eax, %eax
je 0x9115c
xorl %ecx, %ecx
movb (%rsi,%rcx), %dl
shrb %dl
andb $0x55, %dl
movb %dl, (%rsi,%rcx)
incq %rcx
cmpl %ecx, %eax
jne 0x910a4
jmp 0x9115c
imull %r8d, %ecx
testl %ecx, %ecx
je 0x9115c
movl %ecx, %r9d
xorl %edi, %edi
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movb -0x10(%rsp,%rdx,4), %cl
movzbl (%rsi,%rdi), %eax
shrl %cl, %eax
movb %al, (%rsi,%rdi)
incq %rdi
cmpl %edi, %r9d
jne 0x910cc
jmp 0x9115c
movl -0x10(%rsp), %ecx
movl $0xf0, %eax
shrl %cl, %eax
movq 0x8(%rdi), %rdx
movl $0xf, %edi
shrl %cl, %edi
testl %edx, %edx
je 0x9115c
andl $-0x10, %eax
orl %edi, %eax
xorl %edi, %edi
movzbl (%rsi,%rdi), %r8d
shrl %cl, %r8d
andl %eax, %r8d
movb %r8b, (%rsi,%rdi)
incq %rdi
cmpl %edi, %edx
jne 0x9110b
jmp 0x9115c
imull %r8d, %ecx
testl %ecx, %ecx
je 0x9115c
movl %ecx, %r9d
xorl %edi, %edi
movzwl (%rsi,%rdi,2), %eax
rolw $0x8, %ax
movzwl %ax, %r10d
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movb -0x10(%rsp,%rdx,4), %cl
shrl %cl, %r10d
rolw $0x8, %r10w
movw %r10w, (%rsi,%rdi,2)
incq %rdi
cmpl %edi, %r9d
jne 0x91130
popq %rbx
retq