// File: /workspace/github_c_makefile_star2_O1/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 0xc7da
movl %r9d, %eax
leaq 0x1c01(%rip), %r9       # 0xe158
movslq (%r9,%rax,4), %rax
addq %r9, %rax
jmpq *%rax
testq %rcx, %rcx
je 0xc7da
xorl %eax, %eax
movb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %rcx
jne 0xc56b
jmp 0xc7da
testq %rdx, %rdx
je 0xc711
testq %r8, %r8
je 0xc5a2
xorl %eax, %eax
movb (%rsi,%rax), %r9b
subb (%rdx,%rax), %r9b
movb %r9b, (%rdi,%rax)
incq %rax
cmpq %rax, %r8
jne 0xc58e
cmpq %r8, %rcx
jbe 0xc7da
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
xorl %eax, %eax
movl $0xff, %r9d
movzbl (%rsi,%rax), %r14d
movzbl (%rdx,%r8), %r11d
movzbl (%rdx,%rax), %r10d
movl %r11d, %ebp
subl %r10d, %ebp
movl %ebp, %ebx
negl %ebx
cmovsl %ebp, %ebx
andl %r9d, %ebx
movl %r14d, %r15d
subl %r10d, %r15d
movl %r15d, %ebp
negl %ebp
cmovsl %r15d, %ebp
andl %r9d, %ebp
leal (%r11,%r14), %r12d
subl %r10d, %r12d
subl %r10d, %r12d
movl %r12d, %r15d
negl %r15d
cmovsl %r12d, %r15d
cmpl %ebx, %ebp
jb 0xc607
movl %r14d, %r11d
movb (%rsi,%r8), %r14b
movzwl %r15w, %r15d
cmpl %ebp, %r15d
cmovael %r11d, %r10d
cmpl %ebx, %r15d
cmovael %r11d, %r10d
subb %r10b, %r14b
movb %r14b, (%rdi,%r8)
incq %r8
incq %rax
cmpq %r8, %rcx
jne 0xc5bb
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
testq %rdx, %rdx
je 0xc74e
testq %rcx, %rcx
je 0xc7da
xorl %eax, %eax
movb (%rsi,%rax), %r8b
subb (%rdx,%rax), %r8b
movb %r8b, (%rdi,%rax)
incq %rax
cmpq %rax, %rcx
jne 0xc64c
jmp 0xc7da
testq %rdx, %rdx
je 0xc769
testq %r8, %r8
je 0xc68f
xorl %eax, %eax
movb (%rsi,%rax), %r9b
movb (%rdx,%rax), %r10b
shrb %r10b
subb %r10b, %r9b
movb %r9b, (%rdi,%rax)
incq %rax
cmpq %rax, %r8
jne 0xc675
subq %r8, %rcx
jbe 0xc7da
addq %r8, %rdi
addq %r8, %rdx
addq %rsi, %r8
xorl %eax, %eax
movb (%r8,%rax), %r9b
movzbl (%rsi,%rax), %r10d
movzbl (%rdx,%rax), %r11d
addl %r10d, %r11d
shrl %r11d
subb %r11b, %r9b
movb %r9b, (%rdi,%rax)
incq %rax
cmpq %rax, %rcx
jne 0xc6a3
jmp 0xc7da
testq %rdx, %rdx
je 0xc7a6
testq %r8, %r8
je 0xc6e9
xorl %eax, %eax
movb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %r8
jne 0xc6db
subq %r8, %rcx
jbe 0xc7da
addq %r8, %rdi
addq %rsi, %r8
xorl %eax, %eax
movb (%r8,%rax), %dl
subb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %rcx
jne 0xc6fa
jmp 0xc7da
testq %r8, %r8
je 0xc726
xorl %eax, %eax
movb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %r8
jne 0xc718
subq %r8, %rcx
jbe 0xc7da
addq %r8, %rdi
addq %rsi, %r8
xorl %eax, %eax
movb (%r8,%rax), %dl
subb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %rcx
jne 0xc737
jmp 0xc7da
testq %rcx, %rcx
je 0xc7da
xorl %eax, %eax
movb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %rcx
jne 0xc759
jmp 0xc7da
testq %r8, %r8
je 0xc77e
xorl %eax, %eax
movb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %r8
jne 0xc770
subq %r8, %rcx
jbe 0xc7da
addq %r8, %rdi
addq %rsi, %r8
xorl %eax, %eax
movb (%r8,%rax), %dl
movb (%rsi,%rax), %r9b
shrb %r9b
subb %r9b, %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %rcx
jne 0xc78b
jmp 0xc7da
testq %r8, %r8
je 0xc7bb
xorl %eax, %eax
movb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %r8
jne 0xc7ad
subq %r8, %rcx
jbe 0xc7da
addq %r8, %rdi
addq %rsi, %r8
xorl %eax, %eax
movb (%r8,%rax), %dl
subb (%rsi,%rax), %dl
movb %dl, (%rdi,%rax)
incq %rax
cmpq %rax, %rcx
jne 0xc7c8
retq
nop