// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: unfilterScanline
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] >> 1);
        for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + ((recon[i - bytewidth] + precon[i]) >> 1);
      }
      else
      {
        for(i = 0; i != bytewidth; ++i) recon[i] = scanline[i];
        for(i = bytewidth; i < length; ++i) recon[i] = scanline[i] + (recon[i - bytewidth] >> 1);
      }
      break;
    case 4:
      if(precon)
      {
        for(i = 0; i != bytewidth; ++i)
        {
          recon[i] = (scanline[i] + precon[i]); /*paethPredictor(0, precon[i], 0) is always precon[i]*/
        }
        for(i = bytewidth; i < length; ++i)
        {
          recon[i] = (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)
        {
          /*paethPredictor(recon[i - bytewidth], 0, 0) is always recon[i - bytewidth]*/
          recon[i] = (scanline[i] + recon[i - bytewidth]);
        }
      }
      break;
    default: return 36; /*error: unexisting filter type given*/
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %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 0xff66
movq -0x48(%rbp), %rax
leaq 0x4655(%rip), %rcx      # 0x141c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0xfbae
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 0xfb80
jmp 0xff6f
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0xfbe9
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 0xfbbb
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0xfc34
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 0xfbf1
jmp 0xff6f
cmpq $0x0, -0x20(%rbp)
je 0xfc89
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0xfc87
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 0xfc48
jmp 0xfcc1
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0xfcbf
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 0xfc91
jmp 0xfcc1
jmp 0xff6f
cmpq $0x0, -0x20(%rbp)
je 0xfd7a
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0xfd1a
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
sarl %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 0xfcd9
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0xfd75
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
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %rsi
movzbl (%rdx,%rsi), %edx
addl %edx, %ecx
sarl %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 0xfd22
jmp 0xfdff
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0xfdb0
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 0xfd82
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0xfdfd
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
sarl %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 0xfdb8
jmp 0xfdff
jmp 0xff6f
cmpq $0x0, -0x20(%rbp)
je 0xfee1
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0xfe56
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 0xfe17
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0xfedc
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
subq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movw %ax, %dx
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rsi
subq -0x28(%rbp), %rsi
movzbl (%rax,%rsi), %eax
movswl %dx, %edi
movswl %cx, %esi
movswl %ax, %edx
callq 0xff80
movb %al, %cl
movl -0x4c(%rbp), %eax
movzbl %cl, %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 0xfe5e
jmp 0xff64
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0xff17
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 0xfee9
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0xff62
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 0xff1f
jmp 0xff64
jmp 0xff6f
movl $0x24, -0x4(%rbp)
jmp 0xff76
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop