// File: 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:
subq $0x48, %rsp
movb %r9b, %al
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movb %al, 0x1f(%rsp)
movzbl 0x1f(%rsp), %eax
movq %rax, 0x8(%rsp)
subq $0x4, %rax
ja 0x19b1d
movq 0x8(%rsp), %rax
leaq 0x2e74(%rip), %rcx      # 0x1c4f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x196cc
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x19696
jmp 0x19b1f
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x19710
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x196da
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
jae 0x19768
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x38(%rsp), %rcx
movq 0x10(%rsp), %rdx
subq 0x20(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x1971a
jmp 0x19b1f
cmpq $0x0, 0x30(%rsp)
je 0x197c9
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x197c7
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x1977e
jmp 0x1980a
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x19808
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x197d2
jmp 0x1980a
jmp 0x19b1f
cmpq $0x0, 0x30(%rsp)
je 0x198de
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x1986f
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
sarl %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x19824
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
jae 0x198d9
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x38(%rsp), %rcx
movq 0x10(%rsp), %rdx
subq 0x20(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
movq 0x30(%rsp), %rdx
movq 0x10(%rsp), %rsi
movzbl (%rdx,%rsi), %edx
addl %edx, %ecx
sarl %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x19879
jmp 0x19979
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x1991d
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x198e7
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
jae 0x19977
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x38(%rsp), %rcx
movq 0x10(%rsp), %rdx
subq 0x20(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
sarl %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x19927
jmp 0x19979
jmp 0x19b1f
cmpq $0x0, 0x30(%rsp)
je 0x19a82
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x199dc
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x19993
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
jae 0x19a7d
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, 0x4(%rsp)
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
subq 0x20(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movw %ax, %dx
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rsi
subq 0x20(%rsp), %rsi
movzbl (%rax,%rsi), %eax
movswl %dx, %edi
movswl %cx, %esi
movswl %ax, %edx
callq 0x181e0
movb %al, %cl
movl 0x4(%rsp), %eax
movzbl %cl, %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x199e6
jmp 0x19b1b
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x19ac1
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x19a8b
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
jae 0x19b19
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x38(%rsp), %rcx
movq 0x10(%rsp), %rdx
subq 0x20(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x19acb
jmp 0x19b1b
jmp 0x19b1f
jmp 0x19b1f
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)