// File: /workspace/github_cpp_makefile_star2_O1/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), %al
cmpb $0x3, %al
je 0x91e26
movzbl 0x11(%rdi), %ecx
testb $0x2, %al
jne 0x91cbf
movzbl 0x3(%rdx), %r8d
subl %r8d, %ecx
movl %ecx, -0x18(%rsp)
movl $0x1, %ecx
jmp 0x91cef
movzbl (%rdx), %r8d
movl %ecx, %r9d
subl %r8d, %r9d
movl %r9d, -0x18(%rsp)
movzbl 0x1(%rdx), %r8d
movl %ecx, %r9d
subl %r8d, %r9d
movl %r9d, -0x14(%rsp)
movzbl 0x2(%rdx), %r8d
subl %r8d, %ecx
movl %ecx, -0x10(%rsp)
movl $0x3, %ecx
testb $0x4, %al
je 0x91d05
movzbl 0x11(%rdi), %eax
movzbl 0x4(%rdx), %edx
subl %edx, %eax
movl %ecx, %edx
incl %ecx
movl %eax, -0x18(%rsp,%rdx,4)
movl (%rdi), %eax
movl %ecx, %r8d
xorl %ecx, %ecx
movl $0x1, %edx
xorl %r10d, %r10d
xorl %r9d, %r9d
movl -0x18(%rsp,%r10,4), %r11d
testl %r11d, %r11d
cmovlel %ecx, %r11d
movl %r11d, -0x18(%rsp,%r10,4)
cmovgl %edx, %r9d
incq %r10
cmpq %r10, %r8
jne 0x91d17
testw %r9w, %r9w
je 0x91e26
movzbl 0x11(%rdi), %ecx
addl $-0x2, %ecx
rorl %ecx
cmpl $0x7, %ecx
ja 0x91e26
leaq 0x1b075(%rip), %rdx     # 0xacdcc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x8(%rdi), %rax
testl %eax, %eax
je 0x91e26
xorl %ecx, %ecx
movb (%rsi,%rcx), %dl
shrb %dl
andb $0x55, %dl
movb %dl, (%rsi,%rcx)
incq %rcx
cmpl %ecx, %eax
jne 0x91d6e
jmp 0x91e26
imull %r8d, %eax
testl %eax, %eax
je 0x91e26
movl %eax, %r9d
xorl %edi, %edi
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movb -0x18(%rsp,%rdx,4), %cl
movzbl (%rsi,%rdi), %eax
shrl %cl, %eax
movb %al, (%rsi,%rdi)
incq %rdi
cmpl %edi, %r9d
jne 0x91d96
jmp 0x91e26
movl -0x18(%rsp), %ecx
movl $0xf0, %eax
shrl %cl, %eax
movq 0x8(%rdi), %rdx
movl $0xf, %edi
shrl %cl, %edi
testl %edx, %edx
je 0x91e26
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 0x91dd5
jmp 0x91e26
imull %r8d, %eax
testl %eax, %eax
je 0x91e26
movl %eax, %r9d
xorl %edi, %edi
movzwl (%rsi,%rdi,2), %eax
rolw $0x8, %ax
movzwl %ax, %r10d
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movb -0x18(%rsp,%rdx,4), %cl
shrl %cl, %r10d
rolw $0x8, %r10w
movw %r10w, (%rsi,%rdi,2)
incq %rdi
cmpl %edi, %r9d
jne 0x91dfa
retq