// File: /workspace/github_c_makefile_star2_O2/Joy-Division[P]tools-mgs/lodepng/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*/
      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 0x9c99
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 0x1568(%rip), %rcx      # 0xb158
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpq %rax, %r13
je 0x9c8b
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9bfb
xorl %eax, %eax
testq %r12, %r12
je 0x9c3a
cmpq %rax, %r14
je 0x9d2c
movb (%r15,%rax), %cl
subb (%r12,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9c17
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r14
jne 0x9c30
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x9c8b
movb (%rax,%rcx), %dl
subb (%r15,%rcx), %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0x9c48
xorl %eax, %eax
testq %r12, %r12
je 0x9c86
cmpq %rax, %r13
je 0x9c8b
movb (%r15,%rax), %cl
subb (%r12,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9c67
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r13
jne 0x9c7c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testq %r12, %r12
je 0x9cc8
cmpq %rax, %r14
je 0x9d82
movb (%r15,%rax), %cl
movb (%r12,%rax), %dl
shrb %dl
subb %dl, %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9ca1
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %r14
jne 0x9cbe
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x9c8b
movb (%rax,%rcx), %dl
movb (%r15,%rcx), %sil
shrb %sil
subb %sil, %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0x9cd6
xorl %eax, %eax
cmpq %rax, %r14
je 0x9d07
movb (%r15,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
jmp 0x9cf6
leaq (%r15,%r14), %rax
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x9c8b
movb (%rax,%rcx), %dl
subb (%r15,%rcx), %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0x9d10
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 0x9c8b
movq 0x8(%rsp), %rax
movb (%rax,%rbp), %bl
movzbl (%r15,%rbp), %edi
movq (%rsp), %rax
movzbl (%rax,%rbp), %esi
movzbl (%r12,%rbp), %edx
callq 0x93a4
subb %al, %bl
movq 0x10(%rsp), %rax
movb %bl, (%rax,%rbp)
incq %rbp
jmp 0x9d47
leaq (%r15,%r14), %rax
addq %r14, %r12
addq %r14, %rdi
xorl %ecx, %ecx
leaq (%r14,%rcx), %rdx
cmpq %r13, %rdx
jae 0x9c8b
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 0x9d8e