// File: mhe[P]raytracerframework_cpp/lodepng.cpp
// Function: unfilterScanline(unsigned char*, unsigned char const*, unsigned char const*, unsigned long, unsigned char, unsigned long)
static unsigned unfilterScanline(unsigned char* recon, const unsigned char* scanline, const unsigned char* precon, size_t bytewidth, unsigned char filterType, size_t length)
{
  /*
  For PNG filter method 0
  unfilter a PNG image scanline by scanline. when the pixels are smaller than 1 byte, the filter works byte per byte (bytewidth = 1)
  precon is the previous unfiltered scanline, recon the result, scanline the current one
  the incoming scanlines do NOT include the filtertype byte, that one is given in the parameter filterType instead
  recon and scanline MAY be the same memory address! precon must be disjoint.
  */
  
  size_t i;
  switch(filterType)
  {
    case 0:
      for(i = 0; i < length; i++) recon[i] = scanline[i];
      break;
    case 1:
      for(i =         0; i < bytewidth; i++) recon[i] = scanline[i];
      for(i = bytewidth; i <    length; i++) recon[i] = scanline[i] + recon[i - bytewidth];
      break;
    case 2: 
      if(precon) for(i = 0; i < length; i++) recon[i] = scanline[i] + precon[i];
      else       for(i = 0; i < length; i++) recon[i] = scanline[i];
      break;
    case 3:
      if(precon)
      {
        for(i =         0; i < bytewidth; i++) recon[i] = scanline[i] + precon[i] / 2;
        for(i = bytewidth; i <    length; i++) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) / 2);
      }
      else
      {
        for(i =         0; i < bytewidth; i++) recon[i] = scanline[i];
        for(i = bytewidth; i <    length; i++) recon[i] = scanline[i] + recon[i - bytewidth] / 2;
      }
      break;
    case 4:
      if(precon)
      {
        for(i =         0; i < bytewidth; i++) recon[i] = (unsigned char)(scanline[i] + paethPredictor(0, precon[i], 0));
        for(i = bytewidth; i <    length; i++) recon[i] = (unsigned char)(scanline[i] + paethPredictor(recon[i - bytewidth], precon[i], precon[i - bytewidth]));
      }
      else
      {
        for(i =         0; i < bytewidth; i++) recon[i] = scanline[i];
        for(i = bytewidth; i <    length; i++) recon[i] = (unsigned char)(scanline[i] + paethPredictor(recon[i - bytewidth], 0, 0));
      }
      break;
    default: return 36; /*error: unexisting filter type given*/
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movb %al, -0x29(%rbp)
movq %r9, -0x38(%rbp)
movzbl -0x29(%rbp), %eax
movq %rax, -0x48(%rbp)
subq $0x4, %rax
ja 0x30720
movq -0x48(%rbp), %rax
leaq 0x1b541(%rip), %rcx     # 0x4b830
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x3032e
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x30300
jmp 0x30729
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x30369
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3033b
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x303b4
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq -0x40(%rbp), %rdx
subq -0x28(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x30371
jmp 0x30729
cmpq $0x0, -0x20(%rbp)
je 0x30409
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x30407
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x303c8
jmp 0x30441
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x3043f
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x30411
jmp 0x30441
jmp 0x30729
cmpq $0x0, -0x20(%rbp)
je 0x30516
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x304a8
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4c(%rbp), %eax
addl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x30459
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x30511
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
subq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x50(%rbp), %eax
addl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x304b0
jmp 0x305a9
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x3054c
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3051e
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x305a7
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
subq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x54(%rbp), %eax
addl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x30554
jmp 0x305a9
jmp 0x30729
cmpq $0x0, -0x20(%rbp)
je 0x3068a
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x30611
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %esi
xorl %edx, %edx
movl %edx, %edi
callq 0x30740
movl %eax, %ecx
movl -0x58(%rbp), %eax
addl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x305c1
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x30685
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
subq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %edi
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %esi
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
subq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %edx
callq 0x30740
movl %eax, %ecx
movl -0x5c(%rbp), %eax
addl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x30619
jmp 0x3071e
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x306c0
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x30692
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x3071c
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
subq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %edi
xorl %edx, %edx
movl %edx, %esi
callq 0x30740
movl %eax, %ecx
movl -0x60(%rbp), %eax
addl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x306c8
jmp 0x3071e
jmp 0x30729
movl $0x24, -0x4(%rbp)
jmp 0x30730
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)