// File: /workspace/github_cpp_makefile_star2_O2/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
movl %edx, 0x4(%rsp)
cmpl $0xff, %edx
jne 0x8dfb8
movq 0x1f0(%rdi), %rsi
incq %rsi
movzbl 0x22b(%rdi), %eax
movl 0x1bc(%rdi), %edx
cmpq $0x8, %rax
jb 0x8e07f
shrl $0x3, %eax
imulq %rax, %rdx
jmp 0x8e08b
movzbl 0x22b(%rdi), %r14d
movq 0x1f0(%rdi), %r15
incq %r15
cmpl $0x4, %r14d
je 0x8e139
cmpl $0x2, %r14d
je 0x8e0a1
cmpl $0x1, %r14d
jne 0x8e1c7
movl 0x124(%rdi), %eax
movl 0x1bc(%rdi), %edx
movl %eax, %esi
shll $0xf, %esi
sarl $0x1f, %esi
andl $0x7, %esi
xorl %edi, %edi
btl $0x10, %eax
pushq $0x7
popq %r8
cmovbl %edi, %r8d
adcl $-0x1, %edi
orl $0x1, %edi
movl $0x80, %r9d
movl %r8d, %eax
movl $0x80, %r10d
subl $0x1, %edx
jb 0x8e20c
testl %r10d, 0x4(%rsp)
je 0x8e059
movzbl (%r15), %ecx
xorl %r11d, %r11d
btl %eax, %ecx
setb %r11b
movb $0x7, %cl
subb %al, %cl
movl $0x7f7f, %ebp           # imm = 0x7F7F
shrl %cl, %ebp
movl %eax, %ecx
shll %cl, %r11d
andb (%rbx), %bpl
orb %bpl, %r11b
movb %r11b, (%rbx)
xorl %ecx, %ecx
cmpl %esi, %eax
leal (%rax,%rdi), %eax
sete %cl
cmovel %r8d, %eax
addq %rcx, %rbx
addq %rcx, %r15
movl %r10d, %ecx
sarl %ecx
cmpl $0x1, %r10d
cmovel %r9d, %ecx
movl %ecx, %r10d
jmp 0x8e022
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 0xe380
movl 0x124(%rdi), %edx
movl 0x1bc(%rdi), %esi
movl %edx, %edi
shll $0xf, %edi
sarl $0x1f, %edi
xorl %eax, %eax
andl $0x10000, %edx          # imm = 0x10000
pushq $0x6
popq %r8
cmovnel %eax, %r8d
andl $0x6, %edi
shrl $0xe, %edx
addl $-0x2, %edx
movl $0x80, %r9d
movl $0x80, %r10d
movl %r8d, %eax
subl $0x1, %esi
jb 0x8e20c
testl %r10d, 0x4(%rsp)
je 0x8e113
movzbl (%r15), %r11d
movl %eax, %ecx
shrl %cl, %r11d
andl $0x3, %r11d
movb $0x6, %cl
subb %al, %cl
movl $0x3f3f, %ebp           # imm = 0x3F3F
shrl %cl, %ebp
movl %eax, %ecx
shll %cl, %r11d
andb (%rbx), %bpl
orb %bpl, %r11b
movb %r11b, (%rbx)
xorl %ecx, %ecx
cmpl %edi, %eax
leal (%rax,%rdx), %eax
sete %cl
cmovel %r8d, %eax
addq %rcx, %r15
addq %rcx, %rbx
movl %r10d, %ecx
sarl %ecx
cmpl $0x1, %r10d
cmovel %r9d, %ecx
movl %ecx, %r10d
jmp 0x8e0dd
movl 0x1bc(%rdi), %edx
movl $0x10000, %esi          # imm = 0x10000
andl 0x124(%rdi), %esi
movl %esi, %edi
shrl $0xe, %edi
movl %edi, %r8d
xorl $0x4, %r8d
shrl $0xd, %esi
addl $-0x4, %esi
movl $0x80, %r9d
movl $0x80, %r10d
movl %r8d, %eax
subl $0x1, %edx
jb 0x8e20c
testl %r10d, 0x4(%rsp)
je 0x8e1a1
movzbl (%r15), %r11d
movl %eax, %ecx
shrl %cl, %r11d
andl $0xf, %r11d
movb $0x4, %cl
subb %al, %cl
movl $0xf0f, %ebp            # imm = 0xF0F
shrl %cl, %ebp
movl %eax, %ecx
shll %cl, %r11d
andb (%rbx), %bpl
orb %bpl, %r11b
movb %r11b, (%rbx)
xorl %ecx, %ecx
cmpl %edi, %eax
leal (%rax,%rsi), %eax
sete %cl
cmovel %r8d, %eax
addq %rcx, %r15
addq %rcx, %rbx
movl %r10d, %ecx
sarl %ecx
cmpl $0x1, %r10d
cmovel %r9d, %ecx
movl %ecx, %r10d
jmp 0x8e16b
shrl $0x3, %r14d
movl 0x1bc(%rdi), %r12d
xorl %r13d, %r13d
movl $0x80, %ebp
subl $0x1, %r12d
jb 0x8e20c
testl %ebp, 0x4(%rsp)
je 0x8e1f6
leaq (%r15,%r13), %rsi
leaq (%rbx,%r13), %rdi
movq %r14, %rdx
callq 0xe380
movl %ebp, %eax
shrl %eax
cmpl $0x1, %ebp
movl $0x80, %ecx
cmovel %ecx, %eax
addq %r14, %r13
movl %eax, %ebp
jmp 0x8e1da
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq