// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_read_filter_row
void /* PRIVATE */
png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
   png_bytep prev_row, int filter)
{
   png_debug(1, "in png_read_filter_row");
   png_debug2(2, "row = %lu, filter = %d", png_ptr->row_number, filter);
   switch (filter)
   {
      case PNG_FILTER_VALUE_NONE:
         break;
      case PNG_FILTER_VALUE_SUB:
      {
         png_uint_32 i;
         png_uint_32 istop = row_info->rowbytes;
         png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
         png_bytep rp = row + bpp;
         png_bytep lp = row;

         for (i = bpp; i < istop; i++)
         {
            *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
            rp++;
         }
         break;
      }
      case PNG_FILTER_VALUE_UP:
      {
         png_uint_32 i;
         png_uint_32 istop = row_info->rowbytes;
         png_bytep rp = row;
         png_bytep pp = prev_row;

         for (i = 0; i < istop; i++)
         {
            *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
            rp++;
         }
         break;
      }
      case PNG_FILTER_VALUE_AVG:
      {
         png_uint_32 i;
         png_bytep rp = row;
         png_bytep pp = prev_row;
         png_bytep lp = row;
         png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
         png_uint_32 istop = row_info->rowbytes - bpp;

         for (i = 0; i < bpp; i++)
         {
            *rp = (png_byte)(((int)(*rp) +
               ((int)(*pp++) / 2 )) & 0xff);
            rp++;
         }

         for (i = 0; i < istop; i++)
         {
            *rp = (png_byte)(((int)(*rp) +
               (int)(*pp++ + *lp++) / 2 ) & 0xff);
            rp++;
         }
         break;
      }
      case PNG_FILTER_VALUE_PAETH:
      {
         png_uint_32 i;
         png_bytep rp = row;
         png_bytep pp = prev_row;
         png_bytep lp = row;
         png_bytep cp = prev_row;
         png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
         png_uint_32 istop=row_info->rowbytes - bpp;

         for (i = 0; i < bpp; i++)
         {
            *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
            rp++;
         }

         for (i = 0; i < istop; i++)   /* Use leftover rp,pp */
         {
            int a, b, c, pa, pb, pc, p;

            a = *lp++;
            b = *pp++;
            c = *cp++;

            p = b - c;
            pc = a - c;

#ifdef PNG_USE_ABS
            pa = abs(p);
            pb = abs(pc);
            pc = abs(p + pc);
#else
            pa = p < 0 ? -p : p;
            pb = pc < 0 ? -pc : pc;
            pc = (p + pc) < 0 ? -(p + pc) : p + pc;
#endif

            /*
               if (pa <= pb && pa <= pc)
                  p = a;
               else if (pb <= pc)
                  p = b;
               else
                  p = c;
             */

            p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c;

            *rp = (png_byte)(((int)(*rp) + p) & 0xff);
            rp++;
         }
         break;
      }
      default:
         png_warning(png_ptr, "Ignoring bad adaptive filter type");
         *row = 0;
         break;
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %rbx
cmpl $0x4, %r8d
ja 0x9d6f3
movl %r8d, %eax
leaq 0x151a6(%rip), %rdx     # 0xb2760
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movl 0x8(%rsi), %eax
movzbl 0x13(%rsi), %ecx
addl $0x7, %ecx
shrl $0x3, %ecx
subl %ecx, %eax
jbe 0x9d72b
addq %rbx, %rcx
xorl %edx, %edx
movb (%rbx,%rdx), %sil
addb %sil, (%rcx,%rdx)
incq %rdx
cmpl %edx, %eax
jne 0x9d5dd
jmp 0x9d72b
movzbl 0x13(%rsi), %r8d
leal 0x7(%r8), %edi
shrl $0x3, %edi
movl 0x8(%rsi), %esi
movq %rbx, %rdx
movq %rcx, %rax
testl %r8d, %r8d
je 0x9d635
addl $0x7, %r8d
shrl $0x3, %r8d
xorl %eax, %eax
xorl %r9d, %r9d
movb (%rcx,%rax), %dl
addb %dl, (%rbx,%rax)
decq %r9
incq %rax
cmpl %eax, %r8d
jne 0x9d618
movq %rcx, %rax
subq %r9, %rax
movq %rbx, %rdx
subq %r9, %rdx
cmpl %edi, %esi
je 0x9d72b
subl %edi, %esi
movl %esi, %esi
xorl %edi, %edi
movl $0xff, %r8d
movzbl (%rbx,%rdi), %r9d
movzbl (%rax,%rdi), %ebp
movzbl (%rcx,%rdi), %r10d
movl %ebp, %r15d
subl %r10d, %r15d
movl %r9d, %r12d
subl %r10d, %r12d
movl %r15d, %r11d
negl %r11d
cmovsl %r15d, %r11d
movl %r12d, %r14d
negl %r14d
cmovsl %r12d, %r14d
andl %r8d, %r14d
addl %r15d, %r12d
movl %r12d, %r15d
negl %r15d
cmovsl %r12d, %r15d
cmpl %r15d, %r14d
ja 0x9d68f
movl %ebp, %r10d
andl %r8d, %r11d
cmpl %r15d, %r11d
cmoval %r10d, %r9d
cmpl %r14d, %r11d
cmoval %r10d, %r9d
addb %r9b, (%rdx,%rdi)
incq %rdi
cmpl %edi, %esi
jne 0x9d649
jmp 0x9d72b
movq 0x8(%rsi), %rax
testl %eax, %eax
je 0x9d72b
xorl %edx, %edx
movb (%rcx,%rdx), %sil
addb %sil, (%rbx,%rdx)
incq %rdx
cmpl %edx, %eax
jne 0x9d6b7
jmp 0x9d72b
movzbl 0x13(%rsi), %eax
leal 0x7(%rax), %edx
shrl $0x3, %edx
movl 0x8(%rsi), %esi
testl %eax, %eax
je 0x9d704
movl %edx, %edi
movq %rbx, %rax
movb (%rcx), %r8b
shrb %r8b
addb %r8b, (%rax)
incq %rcx
incq %rax
decl %edi
jne 0x9d6de
jmp 0x9d707
leaq 0x15f32(%rip), %rsi     # 0xb362c
callq 0x92e6e
movb $0x0, (%rbx)
jmp 0x9d72b
movq %rbx, %rax
cmpl %edx, %esi
je 0x9d72b
subl %edx, %esi
movl %esi, %edx
xorl %esi, %esi
movzbl (%rcx,%rsi), %edi
movzbl (%rbx,%rsi), %r8d
addl %edi, %r8d
shrl %r8d
addb %r8b, (%rax,%rsi)
incq %rsi
cmpl %esi, %edx
jne 0x9d711
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq