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

   if (
      row_info->color_type != PNG_COLOR_TYPE_PALETTE)
   {
      int shift_start[4], shift_dec[4];
      int channels = 0;

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

      /* With low row depths, could only be grayscale, so one channel */
      if (row_info->bit_depth < 8)
      {
         png_bytep bp = row;
         png_uint_32 i;
         png_byte mask;
         png_uint_32 row_bytes = row_info->rowbytes;

         if (bit_depth->gray == 1 && row_info->bit_depth == 2)
            mask = 0x55;
         else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
            mask = 0x11;
         else
            mask = 0xff;

         for (i = 0; i < row_bytes; i++, bp++)
         {
            png_uint_16 v;
            int j;

            v = *bp;
            *bp = 0;
            for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
            {
               if (j > 0)
                  *bp |= (png_byte)((v << j) & 0xff);
               else
                  *bp |= (png_byte)((v >> (-j)) & mask);
            }
         }
      }
      else if (row_info->bit_depth == 8)
      {
         png_bytep bp = row;
         png_uint_32 i;
         png_uint_32 istop = channels * row_info->width;

         for (i = 0; i < istop; i++, bp++)
         {

            png_uint_16 v;
            int j;
            int c = (int)(i%channels);

            v = *bp;
            *bp = 0;
            for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
            {
               if (j > 0)
                  *bp |= (png_byte)((v << j) & 0xff);
               else
                  *bp |= (png_byte)((v >> (-j)) & 0xff);
            }
         }
      }
      else
      {
         png_bytep bp;
         png_uint_32 i;
         png_uint_32 istop = channels * row_info->width;

         for (bp = row, i = 0; i < istop; i++)
         {
            int c = (int)(i%channels);
            png_uint_16 value, v;
            int j;

            v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
            value = 0;
            for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
            {
               if (j > 0)
                  value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
               else
                  value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
            }
            *bp++ = (png_byte)(value >> 8);
            *bp++ = (png_byte)(value & 0xff);
         }
      }
   }
}

// Assembly:
movb 0x10(%rdi), %cl
cmpb $0x3, %cl
je 0x84635
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movzbl 0x11(%rdi), %eax
testb $0x2, %cl
jne 0x8445e
movb 0x3(%rdx), %r9b
movl $0x1, %r8d
jmp 0x84491
movb (%rdx), %r9b
movzbl 0x1(%rdx), %r8d
movl %eax, %r10d
subl %r8d, %r10d
movl %r10d, -0x14(%rsp)
movl %r8d, -0x24(%rsp)
movzbl 0x2(%rdx), %r8d
movl %eax, %r10d
subl %r8d, %r10d
movl %r10d, -0x10(%rsp)
movl %r8d, -0x20(%rsp)
movl $0x3, %r8d
movzbl %r9b, %r9d
movl %eax, %r10d
subl %r9d, %r10d
movl %r10d, -0x18(%rsp)
movl %r9d, -0x28(%rsp)
testb $0x4, %cl
je 0x844c8
movzbl 0x4(%rdx), %ecx
movl %eax, %r11d
subl %ecx, %r11d
leal (,%r8,4), %ebx
movl %r11d, -0x18(%rsp,%rbx)
movl %ecx, -0x28(%rsp,%rbx)
incl %r8d
cmpb $0x7, %al
ja 0x84562
movl 0x8(%rdi), %edi
movb 0x3(%rdx), %cl
movl %ecx, %edx
xorb $0x1, %dl
movl %eax, %r8d
xorb $0x2, %r8b
movl %eax, %r11d
xorb $0x4, %r11b
xorb $0x3, %cl
orb %r11b, %cl
movl $0x11, %ecx
movl $0xff, %r11d
cmovel %ecx, %r11d
orb %dl, %r8b
movl $0x55, %r8d
cmovnel %r11d, %r8d
movl %r9d, %r11d
negl %r11d
movl %r9d, %ebx
subl %eax, %ebx
xorl %ebp, %ebp
cmpl %edi, %ebp
je 0x8462b
movzbl (%rsi), %r14d
movb $0x0, (%rsi)
xorl %r15d, %r15d
movl %ebx, %eax
movl %r10d, %edx
cmpl %r11d, %edx
jle 0x8455b
movl %r14d, %r12d
movl %eax, %ecx
shrl %cl, %r12d
movl %r14d, %r13d
movl %edx, %ecx
shll %cl, %r13d
andl %r8d, %r12d
testl %edx, %edx
cmovlel %r12d, %r13d
orb %r13b, %r15b
movb %r15b, (%rsi)
subl %r9d, %edx
addl %r9d, %eax
jmp 0x8452f
incl %ebp
incq %rsi
jmp 0x84518
movl (%rdi), %r9d
imull %r8d, %r9d
xorl %edi, %edi
cmpl $0x8, %eax
jne 0x845ca
cmpl %r9d, %edi
je 0x8462b
xorl %r10d, %r10d
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movzbl (%rsi), %r11d
movb $0x0, (%rsi)
shll $0x2, %edx
movl -0x18(%rsp,%rdx), %eax
movl -0x28(%rsp,%rdx), %ebx
movl %ebx, %ebp
negl %ebp
movl %eax, %edx
negl %edx
cmpl %ebp, %eax
jle 0x845c3
movl %r11d, %r14d
movl %edx, %ecx
shrl %cl, %r14d
movl %r11d, %r15d
movl %eax, %ecx
shll %cl, %r15d
testl %eax, %eax
cmovlel %r14d, %r15d
orb %r15b, %r10b
movb %r10b, (%rsi)
subl %ebx, %eax
addl %ebx, %edx
jmp 0x8459d
incl %edi
incq %rsi
jmp 0x84570
cmpl %r9d, %edi
je 0x8462b
xorl %r10d, %r10d
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movzwl (%rsi), %eax
rolw $0x8, %ax
movzwl %ax, %r11d
shll $0x2, %edx
movl -0x18(%rsp,%rdx), %eax
movl -0x28(%rsp,%rdx), %ebx
movl %ebx, %ebp
negl %ebp
movl %eax, %edx
negl %edx
cmpl %ebp, %eax
jle 0x8461a
movl %r11d, %r14d
movl %eax, %ecx
shll %cl, %r14d
movl %r11d, %r15d
movl %edx, %ecx
shrl %cl, %r15d
testl %eax, %eax
cmovgl %r14d, %r15d
orl %r15d, %r10d
subl %ebx, %eax
addl %ebx, %edx
jmp 0x845f7
rolw $0x8, %r10w
movw %r10w, (%rsi)
addq $0x2, %rsi
incl %edi
jmp 0x845ca
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq