// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_combine_row
void /* PRIVATE */
png_combine_row(png_structp png_ptr, png_bytep row, int mask)
{
   png_debug(1, "in png_combine_row");
   if (mask == 0xff)
   {
      png_memcpy(row, png_ptr->row_buf + 1,
         PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
   }
   else
   {
      switch (png_ptr->row_info.pixel_depth)
      {
         case 1:
         {
            png_bytep sp = png_ptr->row_buf + 1;
            png_bytep dp = row;
            int s_inc, s_start, s_end;
            int m = 0x80;
            int shift;
            png_uint_32 i;
            png_uint_32 row_width = png_ptr->width;

#ifdef PNG_READ_PACKSWAP_SUPPORTED
            if (png_ptr->transformations & PNG_PACKSWAP)
            {
                s_start = 0;
                s_end = 7;
                s_inc = 1;
            }
            else
#endif
            {
                s_start = 7;
                s_end = 0;
                s_inc = -1;
            }

            shift = s_start;

            for (i = 0; i < row_width; i++)
            {
               if (m & mask)
               {
                  int value;

                  value = (*sp >> shift) & 0x01;
                  *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
                  *dp |= (png_byte)(value << shift);
               }

               if (shift == s_end)
               {
                  shift = s_start;
                  sp++;
                  dp++;
               }
               else
                  shift += s_inc;

               if (m == 1)
                  m = 0x80;
               else
                  m >>= 1;
            }
            break;
         }
         case 2:
         {
            png_bytep sp = png_ptr->row_buf + 1;
            png_bytep dp = row;
            int s_start, s_end, s_inc;
            int m = 0x80;
            int shift;
            png_uint_32 i;
            png_uint_32 row_width = png_ptr->width;
            int value;

#ifdef PNG_READ_PACKSWAP_SUPPORTED
            if (png_ptr->transformations & PNG_PACKSWAP)
            {
               s_start = 0;
               s_end = 6;
               s_inc = 2;
            }
            else
#endif
            {
               s_start = 6;
               s_end = 0;
               s_inc = -2;
            }

            shift = s_start;

            for (i = 0; i < row_width; i++)
            {
               if (m & mask)
               {
                  value = (*sp >> shift) & 0x03;
                  *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
                  *dp |= (png_byte)(value << shift);
               }

               if (shift == s_end)
               {
                  shift = s_start;
                  sp++;
                  dp++;
               }
               else
                  shift += s_inc;
               if (m == 1)
                  m = 0x80;
               else
                  m >>= 1;
            }
            break;
         }
         case 4:
         {
            png_bytep sp = png_ptr->row_buf + 1;
            png_bytep dp = row;
            int s_start, s_end, s_inc;
            int m = 0x80;
            int shift;
            png_uint_32 i;
            png_uint_32 row_width = png_ptr->width;
            int value;

#ifdef PNG_READ_PACKSWAP_SUPPORTED
            if (png_ptr->transformations & PNG_PACKSWAP)
            {
               s_start = 0;
               s_end = 4;
               s_inc = 4;
            }
            else
#endif
            {
               s_start = 4;
               s_end = 0;
               s_inc = -4;
            }
            shift = s_start;

            for (i = 0; i < row_width; i++)
            {
               if (m & mask)
               {
                  value = (*sp >> shift) & 0xf;
                  *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
                  *dp |= (png_byte)(value << shift);
               }

               if (shift == s_end)
               {
                  shift = s_start;
                  sp++;
                  dp++;
               }
               else
                  shift += s_inc;
               if (m == 1)
                  m = 0x80;
               else
                  m >>= 1;
            }
            break;
         }
         default:
         {
            png_bytep sp = png_ptr->row_buf + 1;
            png_bytep dp = row;
            png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
            png_uint_32 i;
            png_uint_32 row_width = png_ptr->width;
            png_byte m = 0x80;


            for (i = 0; i < row_width; i++)
            {
               if (m & mask)
               {
                  png_memcpy(dp, sp, pixel_bytes);
               }

               sp += pixel_bytes;
               dp += pixel_bytes;

               if (m == 1)
                  m = 0x80;
               else
                  m >>= 1;
            }
            break;
         }
      }
   }
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movl %edx, 0xe4(%rsp)
cmpl $0xff, 0xe4(%rsp)
jne 0x1279cb
movq 0xe8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xf0(%rsp), %rax
movq 0x1f0(%rax), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
movq 0xf0(%rsp), %rax
movzbl 0x22b(%rax), %eax
cmpl $0x8, %eax
jl 0x127984
movq 0xf0(%rsp), %rax
movl 0x1bc(%rax), %eax
movq 0xf0(%rsp), %rcx
movzbl 0x22b(%rcx), %ecx
shrq $0x3, %rcx
imulq %rcx, %rax
movq %rax, 0x10(%rsp)
jmp 0x1279b2
movq 0xf0(%rsp), %rax
movl 0x1bc(%rax), %eax
movq 0xf0(%rsp), %rcx
movzbl 0x22b(%rcx), %ecx
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
callq 0xf3d0
jmp 0x128040
movq 0xf0(%rsp), %rax
movzbl 0x22b(%rax), %eax
movl %eax, 0xc(%rsp)
subl $0x1, %eax
je 0x127a06
jmp 0x1279e5
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0x127bfa
jmp 0x1279f4
movl 0xc(%rsp), %eax
subl $0x4, %eax
je 0x127dee
jmp 0x127f67
movq 0xf0(%rsp), %rax
movq 0x1f0(%rax), %rax
addq $0x1, %rax
movq %rax, 0xd8(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0xd0(%rsp)
movl $0x80, 0xc0(%rsp)
movq 0xf0(%rsp), %rax
movl 0x1bc(%rax), %eax
movl %eax, 0xb4(%rsp)
movq 0xf0(%rsp), %rax
movl 0x124(%rax), %eax
andq $0x10000, %rax          # imm = 0x10000
cmpq $0x0, %rax
je 0x127a8e
movl $0x0, 0xc8(%rsp)
movl $0x7, 0xc4(%rsp)
movl $0x1, 0xcc(%rsp)
jmp 0x127aaf
movl $0x7, 0xc8(%rsp)
movl $0x0, 0xc4(%rsp)
movl $0xffffffff, 0xcc(%rsp) # imm = 0xFFFFFFFF
movl 0xc8(%rsp), %eax
movl %eax, 0xbc(%rsp)
movl $0x0, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jae 0x127bf5
movl 0xc0(%rsp), %eax
andl 0xe4(%rsp), %eax
cmpl $0x0, %eax
je 0x127b59
movq 0xd8(%rsp), %rax
movzbl (%rax), %eax
movl 0xbc(%rsp), %ecx
sarl %cl, %eax
andl $0x1, %eax
movl %eax, 0xb0(%rsp)
movl $0x7, %ecx
subl 0xbc(%rsp), %ecx
movl $0x7f7f, %eax           # imm = 0x7F7F
sarl %cl, %eax
andl $0xff, %eax
movzbl %al, %edx
movq 0xd0(%rsp), %rax
movzbl (%rax), %ecx
andl %edx, %ecx
movb %cl, (%rax)
movl 0xb0(%rsp), %eax
movl 0xbc(%rsp), %ecx
shll %cl, %eax
movzbl %al, %edx
movq 0xd0(%rsp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl 0xbc(%rsp), %eax
cmpl 0xc4(%rsp), %eax
jne 0x127ba1
movl 0xc8(%rsp), %eax
movl %eax, 0xbc(%rsp)
movq 0xd8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd8(%rsp)
movq 0xd0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd0(%rsp)
jmp 0x127bb6
movl 0xcc(%rsp), %eax
addl 0xbc(%rsp), %eax
movl %eax, 0xbc(%rsp)
cmpl $0x1, 0xc0(%rsp)
jne 0x127bcd
movl $0x80, 0xc0(%rsp)
jmp 0x127bdd
movl 0xc0(%rsp), %eax
sarl %eax
movl %eax, 0xc0(%rsp)
jmp 0x127bdf
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x127ac8
jmp 0x12803e
movq 0xf0(%rsp), %rax
movq 0x1f0(%rax), %rax
addq $0x1, %rax
movq %rax, 0xa8(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl $0x80, 0x90(%rsp)
movq 0xf0(%rsp), %rax
movl 0x1bc(%rax), %eax
movl %eax, 0x84(%rsp)
movq 0xf0(%rsp), %rax
movl 0x124(%rax), %eax
andq $0x10000, %rax          # imm = 0x10000
cmpq $0x0, %rax
je 0x127c82
movl $0x0, 0x9c(%rsp)
movl $0x6, 0x98(%rsp)
movl $0x2, 0x94(%rsp)
jmp 0x127ca3
movl $0x6, 0x9c(%rsp)
movl $0x0, 0x98(%rsp)
movl $0xfffffffe, 0x94(%rsp) # imm = 0xFFFFFFFE
movl 0x9c(%rsp), %eax
movl %eax, 0x8c(%rsp)
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
cmpl 0x84(%rsp), %eax
jae 0x127de9
movl 0x90(%rsp), %eax
andl 0xe4(%rsp), %eax
cmpl $0x0, %eax
je 0x127d4d
movq 0xa8(%rsp), %rax
movzbl (%rax), %eax
movl 0x8c(%rsp), %ecx
sarl %cl, %eax
andl $0x3, %eax
movl %eax, 0x80(%rsp)
movl $0x6, %ecx
subl 0x8c(%rsp), %ecx
movl $0x3f3f, %eax           # imm = 0x3F3F
sarl %cl, %eax
andl $0xff, %eax
movzbl %al, %edx
movq 0xa0(%rsp), %rax
movzbl (%rax), %ecx
andl %edx, %ecx
movb %cl, (%rax)
movl 0x80(%rsp), %eax
movl 0x8c(%rsp), %ecx
shll %cl, %eax
movzbl %al, %edx
movq 0xa0(%rsp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl 0x8c(%rsp), %eax
cmpl 0x98(%rsp), %eax
jne 0x127d95
movl 0x9c(%rsp), %eax
movl %eax, 0x8c(%rsp)
movq 0xa8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa8(%rsp)
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0x127daa
movl 0x94(%rsp), %eax
addl 0x8c(%rsp), %eax
movl %eax, 0x8c(%rsp)
cmpl $0x1, 0x90(%rsp)
jne 0x127dc1
movl $0x80, 0x90(%rsp)
jmp 0x127dd1
movl 0x90(%rsp), %eax
sarl %eax
movl %eax, 0x90(%rsp)
jmp 0x127dd3
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0x127cbc
jmp 0x12803e
movq 0xf0(%rsp), %rax
movq 0x1f0(%rax), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x70(%rsp)
movl $0x80, 0x60(%rsp)
movq 0xf0(%rsp), %rax
movl 0x1bc(%rax), %eax
movl %eax, 0x54(%rsp)
movq 0xf0(%rsp), %rax
movl 0x124(%rax), %eax
andq $0x10000, %rax          # imm = 0x10000
cmpq $0x0, %rax
je 0x127e61
movl $0x0, 0x6c(%rsp)
movl $0x4, 0x68(%rsp)
movl $0x4, 0x64(%rsp)
jmp 0x127e79
movl $0x4, 0x6c(%rsp)
movl $0x0, 0x68(%rsp)
movl $0xfffffffc, 0x64(%rsp) # imm = 0xFFFFFFFC
movl 0x6c(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x54(%rsp), %eax
jae 0x127f62
movl 0x60(%rsp), %eax
andl 0xe4(%rsp), %eax
cmpl $0x0, %eax
je 0x127ef9
movq 0x78(%rsp), %rax
movzbl (%rax), %eax
movl 0x5c(%rsp), %ecx
sarl %cl, %eax
andl $0xf, %eax
movl %eax, 0x50(%rsp)
movl $0x4, %ecx
subl 0x5c(%rsp), %ecx
movl $0xf0f, %eax            # imm = 0xF0F
sarl %cl, %eax
andl $0xff, %eax
movzbl %al, %edx
movq 0x70(%rsp), %rax
movzbl (%rax), %ecx
andl %edx, %ecx
movb %cl, (%rax)
movl 0x50(%rsp), %eax
movl 0x5c(%rsp), %ecx
shll %cl, %eax
movzbl %al, %edx
movq 0x70(%rsp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl 0x5c(%rsp), %eax
cmpl 0x68(%rsp), %eax
jne 0x127f29
movl 0x6c(%rsp), %eax
movl %eax, 0x5c(%rsp)
movq 0x78(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x127f35
movl 0x64(%rsp), %eax
addl 0x5c(%rsp), %eax
movl %eax, 0x5c(%rsp)
cmpl $0x1, 0x60(%rsp)
jne 0x127f46
movl $0x80, 0x60(%rsp)
jmp 0x127f50
movl 0x60(%rsp), %eax
sarl %eax
movl %eax, 0x60(%rsp)
jmp 0x127f52
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x127e89
jmp 0x12803e
movq 0xf0(%rsp), %rax
movq 0x1f0(%rax), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xf0(%rsp), %rax
movzbl 0x22b(%rax), %eax
sarl $0x3, %eax
cltq
movq %rax, 0x38(%rsp)
movq 0xf0(%rsp), %rax
movl 0x1bc(%rax), %eax
movl %eax, 0x30(%rsp)
movb $-0x80, 0x2f(%rsp)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x30(%rsp), %eax
jae 0x12803c
movzbl 0x2f(%rsp), %eax
andl 0xe4(%rsp), %eax
cmpl $0x0, %eax
je 0x127ff3
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xf3d0
movq 0x38(%rsp), %rax
addq 0x48(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x38(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movzbl 0x2f(%rsp), %eax
cmpl $0x1, %eax
jne 0x128022
movb $-0x80, 0x2f(%rsp)
jmp 0x12802d
movzbl 0x2f(%rsp), %eax
sarl %eax
movb %al, 0x2f(%rsp)
jmp 0x12802f
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x127fc4
jmp 0x12803e
jmp 0x128040
addq $0xf8, %rsp
retq
nopl (%rax,%rax)