// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
cmpl $0xff, %edx
jne 0x9c50b
movq 0x1f0(%rdi), %rsi
incq %rsi
movzbl 0x22b(%rdi), %eax
movl 0x1bc(%rdi), %edx
cmpq $0x8, %rax
jb 0x9c5dc
shrl $0x3, %eax
imulq %rax, %rdx
jmp 0x9c5e8
movl %edx, %ebp
movzbl 0x22b(%rdi), %r14d
cmpl $0x4, %r14d
je 0x9c6ad
cmpl $0x2, %r14d
je 0x9c5fe
cmpl $0x1, %r14d
jne 0x9c74b
movl 0x124(%rdi), %edx
xorl %esi, %esi
btl $0x10, %edx
movl $0x7, %r8d
cmovbl %esi, %r8d
movl 0x1bc(%rdi), %r9d
adcl $-0x1, %esi
testl %r9d, %r9d
je 0x9c7a7
shll $0xf, %edx
sarl $0x1f, %edx
andl $0x7, %edx
orl $0x1, %esi
movq 0x1f0(%rdi), %rdi
incq %rdi
movl $0x80, %r10d
movl $0x80, %r11d
movl %r8d, %eax
testl %ebp, %r11d
je 0x9c5ae
movzbl (%rdi), %ecx
xorl %r14d, %r14d
btl %eax, %ecx
setb %r14b
movb $0x7, %cl
subb %al, %cl
movl $0x7f7f, %r15d          # imm = 0x7F7F
shrl %cl, %r15d
movl %eax, %ecx
shll %cl, %r14d
andb (%rbx), %r15b
orb %r15b, %r14b
movb %r14b, (%rbx)
xorl %ecx, %ecx
cmpl %edx, %eax
leal (%rax,%rsi), %eax
cmovel %r8d, %eax
sete %cl
addq %rcx, %rbx
addq %rcx, %rdi
movl %r11d, %ecx
sarl %ecx
cmpl $0x1, %r11d
cmovel %r10d, %ecx
movl %ecx, %r11d
decl %r9d
jne 0x9c581
jmp 0x9c7a7
imulq %rax, %rdx
addq $0x7, %rdx
shrq $0x3, %rdx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe370
movl 0x124(%rdi), %edx
movl 0x1bc(%rdi), %esi
xorl %eax, %eax
movl %edx, %r8d
andl $0x10000, %r8d          # imm = 0x10000
movl $0x6, %r9d
cmovnel %eax, %r9d
testl %esi, %esi
je 0x9c7a7
shll $0xf, %edx
sarl $0x1f, %edx
andl $0x6, %edx
shrl $0xe, %r8d
addl $-0x2, %r8d
movq 0x1f0(%rdi), %rdi
incq %rdi
movl $0x80, %r10d
movl %r9d, %eax
movl $0x80, %r11d
testl %ebp, %r11d
je 0x9c67f
movzbl (%rdi), %r14d
movl %eax, %ecx
shrl %cl, %r14d
andl $0x3, %r14d
movb $0x6, %cl
subb %al, %cl
movl $0x3f3f, %r15d          # imm = 0x3F3F
shrl %cl, %r15d
movl %eax, %ecx
shll %cl, %r14d
andb (%rbx), %r15b
orb %r15b, %r14b
movb %r14b, (%rbx)
xorl %ecx, %ecx
cmpl %edx, %eax
leal (%rax,%r8), %eax
cmovel %r9d, %eax
sete %cl
addq %rcx, %rdi
addq %rcx, %rbx
movl %r11d, %ecx
sarl %ecx
cmpl $0x1, %r11d
cmovel %r10d, %ecx
movl %ecx, %r11d
decl %esi
jne 0x9c652
jmp 0x9c7a7
movl 0x1bc(%rdi), %edx
testl %edx, %edx
je 0x9c7a7
movl $0x10000, %esi          # imm = 0x10000
andl 0x124(%rdi), %esi
movl %esi, %r8d
shrl $0xe, %r8d
movl %r8d, %r9d
xorl $0x4, %r9d
shrl $0xd, %esi
addl $-0x4, %esi
movq 0x1f0(%rdi), %rdi
incq %rdi
movl $0x80, %r10d
movl %r9d, %eax
movl $0x80, %r11d
testl %ebp, %r11d
je 0x9c720
movzbl (%rdi), %r14d
movl %eax, %ecx
shrl %cl, %r14d
andl $0xf, %r14d
movb $0x4, %cl
subb %al, %cl
movl $0xf0f, %r15d           # imm = 0xF0F
shrl %cl, %r15d
movl %eax, %ecx
shll %cl, %r14d
andb (%rbx), %r15b
orb %r15b, %r14b
movb %r14b, (%rbx)
xorl %ecx, %ecx
cmpl %r8d, %eax
leal (%rax,%rsi), %eax
cmovel %r9d, %eax
sete %cl
addq %rcx, %rdi
addq %rcx, %rbx
movl %r11d, %ecx
sarl %ecx
cmpl $0x1, %r11d
cmovel %r10d, %ecx
movl %ecx, %r11d
decl %edx
jne 0x9c6f3
jmp 0x9c7a7
movl 0x1bc(%rdi), %r15d
testl %r15d, %r15d
je 0x9c7a7
shrl $0x3, %r14d
movq 0x1f0(%rdi), %rax
incq %rax
movq %rax, (%rsp)
xorl %r13d, %r13d
movl $0x80, %r12d
testl %ebp, %r12d
je 0x9c78b
leaq (%rbx,%r13), %rdi
movq (%rsp), %rax
leaq (%rax,%r13), %rsi
movq %r14, %rdx
callq 0xe370
movl %r12d, %eax
shrl %eax
cmpl $0x1, %r12d
movl $0x80, %ecx
cmovel %ecx, %eax
addq %r14, %r13
movl %eax, %r12d
decl %r15d
jne 0x9c772
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq