// File: /workspace/github_cpp_makefile_star2_O2/phillip-h[P]fractal-gen/lodepng.cpp
// Function: filterScanline(unsigned char*, unsigned char const*, unsigned char const*, unsigned long, unsigned long, unsigned char)
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*/
      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] >> 1);
        for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - ((scanline[i - bytewidth] + prevline[i]) >> 1);
      }
      else
      {
        for(i = 0; i != bytewidth; ++i) out[i] = scanline[i];
        for(i = bytewidth; i < length; ++i) out[i] = scanline[i] - (scanline[i - bytewidth] >> 1);
      }
      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 0xcc71
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r12
leaq 0x18a0(%rip), %rdx      # 0xe45c
movl %r9d, %eax
movq %r8, %r14
movq %rcx, %r13
movq %rsi, %r15
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
xorl %eax, %eax
cmpq %rax, %r13
je 0xcc63
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0xcbd3
xorl %eax, %eax
testq %r12, %r12
je 0xcc12
cmpq %rax, %r14
je 0xcd04
movb (%r15,%rax), %cl
subb (%r12,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0xcbef
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r14
jne 0xcc08
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0xcc63
movb (%rax,%rcx), %dl
subb (%r15,%rcx), %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0xcc20
xorl %eax, %eax
testq %r12, %r12
je 0xcc5e
cmpq %rax, %r13
je 0xcc63
movb (%r15,%rax), %cl
subb (%r12,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0xcc3f
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r13
jne 0xcc54
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testq %r12, %r12
je 0xcca0
cmpq %rax, %r14
je 0xcd5a
movb (%r12,%rax), %dl
movb (%r15,%rax), %cl
shrb %dl
subb %dl, %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0xcc79
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r14
jne 0xcc96
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0xcc63
movb (%r15,%rcx), %sil
movb (%rax,%rcx), %dl
shrb %sil
subb %sil, %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0xccae
xorl %eax, %eax
cmpq %rax, %r14
je 0xccdf
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0xccce
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0xcc63
movb (%rax,%rcx), %dl
subb (%r15,%rcx), %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0xcce8
leaq (%r15,%r14), %rax
leaq (%r12,%r14), %rcx
addq %r14, %rdi
xorl %ebp, %ebp
movq %rax, 0x8(%rsp)
movq %rcx, (%rsp)
movq %rdi, 0x10(%rsp)
leaq (%r14,%rbp), %rax
cmpq %r13, %rax
jae 0xcc63
movq 0x8(%rsp), %rax
movzbl (%r15,%rbp), %edi
movzbl (%r12,%rbp), %edx
movb (%rax,%rbp), %bl
movq (%rsp), %rax
movzbl (%rax,%rbp), %esi
callq 0xc37a
movq 0x10(%rsp), %rcx
subb %al, %bl
movb %bl, (%rcx,%rbp)
incq %rbp
jmp 0xcd1f
leaq (%r15,%r14), %rax
addq %r14, %r12
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0xcc63
movzbl (%r15,%rcx), %esi
movzbl (%r12,%rcx), %r9d
movb (%rax,%rcx), %dl
addl %esi, %r9d
shrl %r9d
subb %r9b, %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0xcd66