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

   if (row_info->bit_depth == 8 &&
      row_info->channels == 1)
   {
      switch ((int)bit_depth)
      {
         case 1:
         {
            png_bytep sp, dp;
            int mask, v;
            png_uint_32 i;
            png_uint_32 row_width = row_info->width;

            sp = row;
            dp = row;
            mask = 0x80;
            v = 0;

            for (i = 0; i < row_width; i++)
            {
               if (*sp != 0)
                  v |= mask;
               sp++;
               if (mask > 1)
                  mask >>= 1;
               else
               {
                  mask = 0x80;
                  *dp = (png_byte)v;
                  dp++;
                  v = 0;
               }
            }
            if (mask != 0x80)
               *dp = (png_byte)v;
            break;
         }
         case 2:
         {
            png_bytep sp, dp;
            int shift, v;
            png_uint_32 i;
            png_uint_32 row_width = row_info->width;

            sp = row;
            dp = row;
            shift = 6;
            v = 0;
            for (i = 0; i < row_width; i++)
            {
               png_byte value;

               value = (png_byte)(*sp & 0x03);
               v |= (value << shift);
               if (shift == 0)
               {
                  shift = 6;
                  *dp = (png_byte)v;
                  dp++;
                  v = 0;
               }
               else
                  shift -= 2;
               sp++;
            }
            if (shift != 6)
               *dp = (png_byte)v;
            break;
         }
         case 4:
         {
            png_bytep sp, dp;
            int shift, v;
            png_uint_32 i;
            png_uint_32 row_width = row_info->width;

            sp = row;
            dp = row;
            shift = 4;
            v = 0;
            for (i = 0; i < row_width; i++)
            {
               png_byte value;

               value = (png_byte)(*sp & 0x0f);
               v |= (value << shift);

               if (shift == 0)
               {
                  shift = 4;
                  *dp = (png_byte)v;
                  dp++;
                  v = 0;
               }
               else
                  shift -= 4;

               sp++;
            }
            if (shift != 4)
               *dp = (png_byte)v;
            break;
         }
      }
      row_info->bit_depth = (png_byte)bit_depth;
      row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
         row_info->width);
   }
}

// Assembly:
subq $0x10, %rsp
movq %rdi, 0x8(%rsp)
movq %rsi, (%rsp)
movl %edx, -0x4(%rsp)
movq 0x8(%rsp), %rax
movzbl 0x11(%rax), %eax
cmpl $0x8, %eax
jne 0x1124c3
movq 0x8(%rsp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x1, %eax
jne 0x1124c3
movl -0x4(%rsp), %eax
movl %eax, -0x78(%rsp)
subl $0x1, %eax
je 0x1121c5
jmp 0x1121a4
movl -0x78(%rsp), %eax
subl $0x2, %eax
je 0x112294
jmp 0x1121b3
movl -0x78(%rsp), %eax
subl $0x4, %eax
je 0x11236b
jmp 0x11243f
movq 0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, -0x28(%rsp)
movq (%rsp), %rax
movq %rax, -0x10(%rsp)
movq (%rsp), %rax
movq %rax, -0x18(%rsp)
movl $0x80, -0x1c(%rsp)
movl $0x0, -0x20(%rsp)
movl $0x0, -0x24(%rsp)
movl -0x24(%rsp), %eax
cmpl -0x28(%rsp), %eax
jae 0x112278
movq -0x10(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x11221d
movl -0x1c(%rsp), %eax
orl -0x20(%rsp), %eax
movl %eax, -0x20(%rsp)
movq -0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rsp)
cmpl $0x1, -0x1c(%rsp)
jle 0x11223e
movl -0x1c(%rsp), %eax
sarl %eax
movl %eax, -0x1c(%rsp)
jmp 0x112269
movl $0x80, -0x1c(%rsp)
movl -0x20(%rsp), %eax
movb %al, %cl
movq -0x18(%rsp), %rax
movb %cl, (%rax)
movq -0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rsp)
movl $0x0, -0x20(%rsp)
jmp 0x11226b
movl -0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rsp)
jmp 0x1121fa
cmpl $0x80, -0x1c(%rsp)
je 0x11228f
movl -0x20(%rsp), %eax
movb %al, %cl
movq -0x18(%rsp), %rax
movb %cl, (%rax)
jmp 0x11243f
movq 0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, -0x48(%rsp)
movq (%rsp), %rax
movq %rax, -0x30(%rsp)
movq (%rsp), %rax
movq %rax, -0x38(%rsp)
movl $0x6, -0x3c(%rsp)
movl $0x0, -0x40(%rsp)
movl $0x0, -0x44(%rsp)
movl -0x44(%rsp), %eax
cmpl -0x48(%rsp), %eax
jae 0x112352
movq -0x30(%rsp), %rax
movzbl (%rax), %eax
andl $0x3, %eax
movb %al, -0x49(%rsp)
movzbl -0x49(%rsp), %eax
movl -0x3c(%rsp), %ecx
shll %cl, %eax
orl -0x40(%rsp), %eax
movl %eax, -0x40(%rsp)
cmpl $0x0, -0x3c(%rsp)
jne 0x112329
movl $0x6, -0x3c(%rsp)
movl -0x40(%rsp), %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movb %cl, (%rax)
movq -0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rsp)
movl $0x0, -0x40(%rsp)
jmp 0x112334
movl -0x3c(%rsp), %eax
subl $0x2, %eax
movl %eax, -0x3c(%rsp)
movq -0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rsp)
movl -0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rsp)
jmp 0x1122c9
cmpl $0x6, -0x3c(%rsp)
je 0x112366
movl -0x40(%rsp), %eax
movb %al, %cl
movq -0x38(%rsp), %rax
movb %cl, (%rax)
jmp 0x11243f
movq 0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, -0x70(%rsp)
movq (%rsp), %rax
movq %rax, -0x58(%rsp)
movq (%rsp), %rax
movq %rax, -0x60(%rsp)
movl $0x4, -0x64(%rsp)
movl $0x0, -0x68(%rsp)
movl $0x0, -0x6c(%rsp)
movl -0x6c(%rsp), %eax
cmpl -0x70(%rsp), %eax
jae 0x112429
movq -0x58(%rsp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
movb %al, -0x71(%rsp)
movzbl -0x71(%rsp), %eax
movl -0x64(%rsp), %ecx
shll %cl, %eax
orl -0x68(%rsp), %eax
movl %eax, -0x68(%rsp)
cmpl $0x0, -0x64(%rsp)
jne 0x112400
movl $0x4, -0x64(%rsp)
movl -0x68(%rsp), %eax
movb %al, %cl
movq -0x60(%rsp), %rax
movb %cl, (%rax)
movq -0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rsp)
movl $0x0, -0x68(%rsp)
jmp 0x11240b
movl -0x64(%rsp), %eax
subl $0x4, %eax
movl %eax, -0x64(%rsp)
movq -0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rsp)
movl -0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rsp)
jmp 0x1123a0
cmpl $0x4, -0x64(%rsp)
je 0x11243d
movl -0x68(%rsp), %eax
movb %al, %cl
movq -0x60(%rsp), %rax
movb %cl, (%rax)
jmp 0x11243f
movl -0x4(%rsp), %eax
movb %al, %cl
movq 0x8(%rsp), %rax
movb %cl, 0x11(%rax)
movl -0x4(%rsp), %eax
movq 0x8(%rsp), %rcx
movzbl 0x12(%rcx), %ecx
imull %ecx, %eax
movb %al, %cl
movq 0x8(%rsp), %rax
movb %cl, 0x13(%rax)
movq 0x8(%rsp), %rax
movzbl 0x13(%rax), %eax
cmpl $0x8, %eax
jl 0x112494
movq 0x8(%rsp), %rax
movl (%rax), %eax
movq 0x8(%rsp), %rcx
movzbl 0x13(%rcx), %ecx
shrq $0x3, %rcx
imulq %rcx, %rax
movq %rax, -0x80(%rsp)
jmp 0x1124b5
movq 0x8(%rsp), %rax
movl (%rax), %eax
movq 0x8(%rsp), %rcx
movzbl 0x13(%rcx), %ecx
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, -0x80(%rsp)
movq -0x80(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
addq $0x10, %rsp
retq
nopl (%rax,%rax)