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

   if (row_info->bit_depth < 8)
   {
      png_uint_32 i;
      png_uint_32 row_width=row_info->width;

      switch (row_info->bit_depth)
      {
         case 1:
         {
            png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
            png_bytep dp = row + (png_size_t)row_width - 1;
            png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
            for (i = 0; i < row_width; i++)
            {
               *dp = (png_byte)((*sp >> shift) & 0x01);
               if (shift == 7)
               {
                  shift = 0;
                  sp--;
               }
               else
                  shift++;

               dp--;
            }
            break;
         }

         case 2:
         {

            png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
            png_bytep dp = row + (png_size_t)row_width - 1;
            png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
            for (i = 0; i < row_width; i++)
            {
               *dp = (png_byte)((*sp >> shift) & 0x03);
               if (shift == 6)
               {
                  shift = 0;
                  sp--;
               }
               else
                  shift += 2;

               dp--;
            }
            break;
         }

         case 4:
         {
            png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
            png_bytep dp = row + (png_size_t)row_width - 1;
            png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
            for (i = 0; i < row_width; i++)
            {
               *dp = (png_byte)((*sp >> shift) & 0x0f);
               if (shift == 4)
               {
                  shift = 0;
                  sp--;
               }
               else
                  shift = 4;

               dp--;
            }
            break;
         }
      }
      row_info->bit_depth = 8;
      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
      row_info->rowbytes = row_width * row_info->channels;
   }
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq -0x8(%rsp), %rax
movzbl 0x11(%rax), %eax
cmpl $0x8, %eax
jge 0x1109c1
movq -0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rsp)
movq -0x8(%rsp), %rax
movzbl 0x11(%rax), %eax
movl %eax, -0x60(%rsp)
subl $0x1, %eax
je 0x11075c
jmp 0x11073b
movl -0x60(%rsp), %eax
subl $0x2, %eax
je 0x110815
jmp 0x11074a
movl -0x60(%rsp), %eax
subl $0x4, %eax
je 0x1108d0
jmp 0x110985
movq -0x10(%rsp), %rax
movl -0x18(%rsp), %ecx
subl $0x1, %ecx
shrl $0x3, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x20(%rsp)
movq -0x10(%rsp), %rax
movl -0x18(%rsp), %ecx
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0x28(%rsp)
movl -0x18(%rsp), %ecx
addl $0x7, %ecx
andl $0x7, %ecx
movl $0x7, %eax
subl %ecx, %eax
movl %eax, -0x2c(%rsp)
movl $0x0, -0x14(%rsp)
movl -0x14(%rsp), %eax
cmpl -0x18(%rsp), %eax
jae 0x110810
movq -0x20(%rsp), %rax
movzbl (%rax), %eax
movl -0x2c(%rsp), %ecx
sarl %cl, %eax
andl $0x1, %eax
movb %al, %cl
movq -0x28(%rsp), %rax
movb %cl, (%rax)
cmpl $0x7, -0x2c(%rsp)
jne 0x1107ea
movl $0x0, -0x2c(%rsp)
movq -0x20(%rsp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rsp)
jmp 0x1107f5
movl -0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rsp)
movq -0x28(%rsp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rsp)
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
jmp 0x1107a7
jmp 0x110985
movq -0x10(%rsp), %rax
movl -0x18(%rsp), %ecx
subl $0x1, %ecx
shrl $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x38(%rsp)
movq -0x10(%rsp), %rax
movl -0x18(%rsp), %ecx
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0x40(%rsp)
movl -0x18(%rsp), %ecx
addl $0x3, %ecx
andl $0x3, %ecx
movl $0x3, %eax
subl %ecx, %eax
shll %eax
movl %eax, -0x44(%rsp)
movl $0x0, -0x14(%rsp)
movl -0x14(%rsp), %eax
cmpl -0x18(%rsp), %eax
jae 0x1108cb
movq -0x38(%rsp), %rax
movzbl (%rax), %eax
movl -0x44(%rsp), %ecx
sarl %cl, %eax
andl $0x3, %eax
movb %al, %cl
movq -0x40(%rsp), %rax
movb %cl, (%rax)
cmpl $0x6, -0x44(%rsp)
jne 0x1108a5
movl $0x0, -0x44(%rsp)
movq -0x38(%rsp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rsp)
jmp 0x1108b0
movl -0x44(%rsp), %eax
addl $0x2, %eax
movl %eax, -0x44(%rsp)
movq -0x40(%rsp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rsp)
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
jmp 0x110862
jmp 0x110985
movq -0x10(%rsp), %rax
movl -0x18(%rsp), %ecx
subl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x50(%rsp)
movq -0x10(%rsp), %rax
movl -0x18(%rsp), %ecx
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0x58(%rsp)
movl -0x18(%rsp), %ecx
addl $0x1, %ecx
andl $0x1, %ecx
movl $0x1, %eax
subl %ecx, %eax
shll $0x2, %eax
movl %eax, -0x5c(%rsp)
movl $0x0, -0x14(%rsp)
movl -0x14(%rsp), %eax
cmpl -0x18(%rsp), %eax
jae 0x110983
movq -0x50(%rsp), %rax
movzbl (%rax), %eax
movl -0x5c(%rsp), %ecx
sarl %cl, %eax
andl $0xf, %eax
movb %al, %cl
movq -0x58(%rsp), %rax
movb %cl, (%rax)
cmpl $0x4, -0x5c(%rsp)
jne 0x110960
movl $0x0, -0x5c(%rsp)
movq -0x50(%rsp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rsp)
jmp 0x110968
movl $0x4, -0x5c(%rsp)
movq -0x58(%rsp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rsp)
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
jmp 0x11091d
jmp 0x110985
movq -0x8(%rsp), %rax
movb $0x8, 0x11(%rax)
movq -0x8(%rsp), %rax
movzbl 0x12(%rax), %eax
shll $0x3, %eax
movb %al, %cl
movq -0x8(%rsp), %rax
movb %cl, 0x13(%rax)
movl -0x18(%rsp), %eax
movq -0x8(%rsp), %rcx
movzbl 0x12(%rcx), %ecx
imull %ecx, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
retq
nopw %cs:(%rax,%rax)