// File: /workspace/github_c_makefile_star2_O2/pje[P]pixelsort/lodepng.c
// Function: filterScanline
static void filterScanline(unsigned char* out, const unsigned char* scanline, const unsigned char* prevline,
                           size_t length, size_t bytewidth, unsigned char filterType)
{
  size_t i;
  switch(filterType)
  {
    case 0: /*None*/
      for(i = 0; i < length; i++) out[i] = scanline[i];
      break;
    case 1: /*Sub*/
      if(prevline)
      {
        for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
        for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth];
      }
      else
      {
        for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
        for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth];
      }
      break;
    case 2: /*Up*/
      if(prevline)
      {
        for(i = 0; i < length; i++) out[i] = scanline[i] - prevline[i];
      }
      else
      {
        for(i = 0; i < length; i++) out[i] = scanline[i];
      }
      break;
    case 3: /*Average*/
      if(prevline)
      {
        for(i = 0; i < bytewidth; i++) out[i] = scanline[i] - prevline[i] / 2;
        for(i = bytewidth; i < length; i++) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) / 2);
      }
      else
      {
        for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
        for(i = bytewidth; i < length; i++) out[i] = scanline[i] - scanline[i - bytewidth] / 2;
      }
      break;
    case 4: /*Paeth*/
      if(prevline)
      {
        /*paethPredictor(0, prevline[i], 0) is always prevline[i]*/
        for(i = 0; i < bytewidth; i++) out[i] = (scanline[i] - prevline[i]);
        for(i = bytewidth; i < length; i++)
        {
          out[i] = (scanline[i] - paethPredictor(scanline[i - bytewidth], prevline[i], prevline[i - bytewidth]));
        }
      }
      else
      {
        for(i = 0; i < bytewidth; i++) out[i] = scanline[i];
        /*paethPredictor(scanline[i - bytewidth], 0, 0) is always scanline[i - bytewidth]*/
        for(i = bytewidth; i < length; i++) out[i] = (scanline[i] - scanline[i - bytewidth]);
      }
      break;
    default: return; /*unexisting filter type given*/
  }
}

// Assembly:
cmpl $0x4, %r9d
ja 0x97b4
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r14
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %r15
movl %r9d, %eax
leaq 0x1a4d(%rip), %rcx      # 0xb158
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpq %rax, %r13
je 0x97a6
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9716
xorl %eax, %eax
testq %r12, %r12
je 0x9755
cmpq %rax, %r14
je 0x985f
movb (%r15,%rax), %cl
subb (%r12,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9732
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r14
jne 0x974b
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x97a6
movb (%rax,%rcx), %dl
subb (%r15,%rcx), %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0x9763
xorl %eax, %eax
testq %r12, %r12
je 0x97a1
cmpq %rax, %r13
je 0x97a6
movb (%r15,%rax), %cl
subb (%r12,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9782
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r13
jne 0x9797
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testq %r12, %r12
je 0x97e3
cmpq %rax, %r14
je 0x98b5
movb (%r15,%rax), %cl
movb (%r12,%rax), %dl
shrb %dl
subb %dl, %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x97bc
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r14
jne 0x97d9
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x97a6
movb (%rax,%rcx), %dl
movb (%r15,%rcx), %sil
shrb %sil
subb %sil, %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0x97f1
xorl %eax, %eax
testq %r12, %r12
je 0x9835
cmpq %rax, %r14
je 0x98ec
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9816
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r14
jne 0x982b
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x97a6
movb (%rax,%rcx), %dl
subb (%r15,%rcx), %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0x9843
leaq (%r15,%r14), %rax
movq %rax, 0x8(%rsp)
leaq (%r12,%r14), %rax
movq %rax, (%rsp)
addq %r14, %rdi
xorl %ebp, %ebp
movq %rdi, 0x10(%rsp)
leaq (%r14,%rbp), %rax
cmpq %r13, %rax
jae 0x97a6
movq 0x8(%rsp), %rax
movb (%rax,%rbp), %bl
movzbl (%r15,%rbp), %edi
movq (%rsp), %rax
movzbl (%rax,%rbp), %esi
movzbl (%r12,%rbp), %edx
callq 0x8e10
subb %al, %bl
movq 0x10(%rsp), %rax
movb %bl, (%rax,%rbp)
incq %rbp
jmp 0x987a
leaq (%r15,%r14), %rax
addq %r14, %r12
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x97a6
movb (%rax,%rcx), %dl
movzbl (%r15,%rcx), %esi
movzbl (%r12,%rcx), %r9d
addl %esi, %r9d
shrl %r9d
subb %r9b, %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0x98c1
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x97a6
movb (%rax,%rcx), %dl
subb (%r15,%rcx), %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0x98f5