// File: /workspace/github_cpp_makefile_star2_O3/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:
cmpb $0x8, 0x11(%rdi)
jne 0x91af2
cmpb $0x1, 0x12(%rdi)
jne 0x91af2
pushq %rbp
pushq %r14
pushq %rbx
cmpl $0x4, %edx
je 0x91a69
cmpl $0x2, %edx
je 0x91a02
cmpl $0x1, %edx
jne 0x91abe
movl (%rdi), %eax
testl %eax, %eax
je 0x91abe
negl %eax
xorl %r9d, %r9d
movq %rsi, %rcx
xorl %r10d, %r10d
leal (%rax,%r10), %ebx
movl $0x80, %ebp
xorl %r11d, %r11d
xorl %r8d, %r8d
movl %r8d, %r14d
cmpb $0x0, (%rsi,%r11)
movl %ebp, %r8d
cmovel %r9d, %r8d
orl %r14d, %r8d
cmpl $0x2, %ebp
jb 0x919dc
shrl %ebp
incq %r11
movl %ebx, %r14d
addl %r11d, %r14d
jne 0x919b3
jmp 0x91aaf
movb %r8b, (%rcx)
incq %rcx
movl %r10d, %r8d
addl %r11d, %r8d
addl %r11d, %r10d
incl %r10d
addl %eax, %r8d
addq %r11, %rsi
incq %rsi
cmpl $-0x1, %r8d
jne 0x919a4
jmp 0x91abe
movl (%rdi), %eax
testl %eax, %eax
je 0x91abe
negl %eax
xorl %r9d, %r9d
movq %rsi, %r10
leal (%rax,%r9), %ebx
movl $0x6, %ecx
xorl %r11d, %r11d
xorl %r8d, %r8d
movl %r8d, %ebp
movzbl (%r10,%r11), %r8d
andl $0x3, %r8d
shll %cl, %r8d
orl %ebp, %r8d
testl %ecx, %ecx
je 0x91a48
addl $-0x2, %ecx
incq %r11
movl %ebx, %ebp
addl %r11d, %ebp
jne 0x91a23
jmp 0x91aa8
movb %r8b, (%rsi)
incq %rsi
addq %r11, %r10
incq %r10
movl %r9d, %ecx
addl %r11d, %ecx
addl %r11d, %r9d
incl %r9d
addl %eax, %ecx
cmpl $-0x1, %ecx
jne 0x91a14
jmp 0x91abe
movl (%rdi), %eax
testl %eax, %eax
je 0x91abe
negl %eax
xorl %ecx, %ecx
movq %rsi, %r9
movb (%rsi,%rcx), %r8b
shlb $0x4, %r8b
leal (%rax,%rcx), %r10d
cmpl $-0x1, %r10d
je 0x91ab4
movb 0x1(%rsi,%rcx), %r10b
andb $0xf, %r10b
orb %r8b, %r10b
movb %r10b, (%r9)
incq %r9
addq $0x2, %rcx
movl %eax, %r8d
addl %ecx, %r8d
jne 0x91a76
jmp 0x91abe
cmpl $0x6, %ecx
jne 0x91abb
jmp 0x91abe
movq %rcx, %rsi
jmp 0x91abb
movzbl %r8b, %r8d
movq %r9, %rsi
movb %r8b, (%rsi)
movb %dl, 0x11(%rdi)
movb 0x12(%rdi), %al
mulb %dl
movb %al, 0x13(%rdi)
movl (%rdi), %ecx
cmpb $0x8, %al
jb 0x91adb
shrb $0x3, %al
movzbl %al, %eax
imulq %rax, %rcx
jmp 0x91aea
movzbl %al, %eax
imulq %rax, %rcx
addq $0x7, %rcx
shrq $0x3, %rcx
movq %rcx, 0x8(%rdi)
popq %rbx
popq %r14
popq %rbp
retq