// File: /workspace/github_cpp_makefile_star2_O1/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), %al
cmpb $0x3, %al
je 0x929d7
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movzbl 0x11(%rdi), %ecx
testb $0x2, %al
jne 0x927d1
movzbl 0x3(%rdx), %r8d
subl %r8d, %ecx
movl %ecx, -0x18(%rsp)
movl %r8d, -0x28(%rsp)
movl $0x1, %r8d
jmp 0x92811
movzbl (%rdx), %r8d
movl %ecx, %r9d
subl %r8d, %r9d
movl %r9d, -0x18(%rsp)
movl %r8d, -0x28(%rsp)
movzbl 0x1(%rdx), %r8d
movl %ecx, %r9d
subl %r8d, %r9d
movl %r9d, -0x14(%rsp)
movl %r8d, -0x24(%rsp)
movzbl 0x2(%rdx), %r8d
subl %r8d, %ecx
movl %ecx, -0x10(%rsp)
movl %r8d, -0x20(%rsp)
movl $0x3, %r8d
testb $0x4, %al
je 0x92834
movzbl 0x11(%rdi), %eax
movzbl 0x4(%rdx), %ecx
subl %ecx, %eax
leal (,%r8,4), %r9d
movl %eax, -0x18(%rsp,%r9)
movl %ecx, -0x28(%rsp,%r9)
incl %r8d
movb 0x11(%rdi), %al
cmpb $0x7, %al
ja 0x928e7
movl 0x8(%rdi), %edi
movb 0x3(%rdx), %cl
movl %ecx, %edx
xorb $0x1, %dl
movl %eax, %r8d
xorb $0x2, %r8b
xorb $0x4, %al
xorb $0x3, %cl
orb %al, %cl
movl $0x11, %eax
movl $0xff, %ecx
cmovel %eax, %ecx
orb %dl, %r8b
movl $0x55, %r8d
cmovnel %ecx, %r8d
testl %edi, %edi
je 0x929cd
movl -0x18(%rsp), %r9d
movl -0x28(%rsp), %r10d
movl %r10d, %r11d
negl %r11d
movl %r9d, %eax
negl %eax
movl %eax, -0x4(%rsp)
xorl %ebp, %ebp
movzbl (%rsi), %ebx
movb $0x0, (%rsi)
cmpl %r11d, %r9d
jle 0x928d9
movb (%rsi), %r15b
movl -0x4(%rsp), %eax
movl %r9d, %edx
movl %r9d, %r12d
movl %ebx, %r13d
movl %eax, %ecx
shrl %cl, %r13d
andl %r8d, %r13d
movl %ebx, %r14d
movl %edx, %ecx
shll %cl, %r14d
testl %edx, %edx
cmovlel %r13d, %r14d
orb %r14b, %r15b
subl %r10d, %r12d
addl %r10d, %eax
testl %edx, %edx
movl %r12d, %edx
jg 0x928ad
movb %r15b, (%rsi)
incl %ebp
incq %rsi
cmpl %edi, %ebp
jne 0x92895
jmp 0x929cd
movl (%rdi), %r9d
imull %r8d, %r9d
cmpb $0x8, %al
jne 0x9295b
testl %r9d, %r9d
je 0x929cd
xorl %edi, %edi
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movzbl (%rsi), %r10d
movb $0x0, (%rsi)
shll $0x2, %edx
movl -0x18(%rsp,%rdx), %eax
movl -0x28(%rsp,%rdx), %r11d
movl %r11d, %ecx
negl %ecx
cmpl %ecx, %eax
jle 0x9294f
movb (%rsi), %bl
movl %eax, %edx
negl %edx
movl %eax, %ebp
movl %r10d, %r14d
movl %edx, %ecx
shrl %cl, %r14d
movl %r10d, %r15d
movl %eax, %ecx
shll %cl, %r15d
testl %eax, %eax
cmovlel %r14d, %r15d
orb %r15b, %bl
subl %r11d, %ebp
addl %r11d, %edx
testl %eax, %eax
movl %ebp, %eax
jg 0x92928
movb %bl, (%rsi)
incl %edi
incq %rsi
cmpl %r9d, %edi
jne 0x928fd
jmp 0x929cd
testl %r9d, %r9d
je 0x929cd
xorl %edi, %edi
xorl %r10d, %r10d
movl %edi, %eax
xorl %edx, %edx
divl %r8d
shll $0x2, %edx
movl -0x18(%rsp,%rdx), %eax
movl -0x28(%rsp,%rdx), %r11d
movl %r11d, %ecx
negl %ecx
cmpl %ecx, %eax
jle 0x929b9
movzwl (%rsi), %ecx
rolw $0x8, %cx
movzwl %cx, %ebx
movl %eax, %edx
negl %edx
xorl %r10d, %r10d
movl %eax, %ebp
movl %ebx, %r14d
movl %eax, %ecx
shll %cl, %r14d
movl %ebx, %r15d
movl %edx, %ecx
shrl %cl, %r15d
testl %eax, %eax
cmovgl %r14d, %r15d
orl %r15d, %r10d
subl %r11d, %ebp
addl %r11d, %edx
testl %eax, %eax
movl %ebp, %eax
jg 0x92994
rolw $0x8, %r10w
movw %r10w, (%rsi)
addq $0x2, %rsi
incl %edi
cmpl %r9d, %edi
jne 0x92962
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq