// File: /workspace/github_cpp_makefile_star2_O2/mhe[P]raytracerframework_cpp/lodepng.cpp
// Function: unfilter(unsigned char*, unsigned char const*, unsigned int, unsigned int, unsigned int)
static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp)
{
  /*
  For PNG filter method 0
  this function unfilters a single image (e.g. without interlacing this is called once, with Adam7 it's called 7 times)
  out must have enough bytes allocated already, in must have the scanlines + 1 filtertype byte per scanline
  w and h are image dimensions or dimensions of reduced image, bpp is bits per pixel
  in and out are allowed to be the same memory address!
  */
  
  unsigned y;
  unsigned char* prevline = 0;
  
  size_t bytewidth = (bpp + 7) / 8; /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/
  size_t linebytes = (w * bpp + 7) / 8;
  
  for(y = 0; y < h; y++)
  {
    size_t outindex = linebytes * y;
    size_t inindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/
    unsigned char filterType = in[inindex];
    
    unsigned error = unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes);
    if(error) return error;
    
    prevline = &out[outindex];
  }
  
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r14
leal 0x7(%r8), %r13d
shrl $0x3, %r13d
imull %r8d, %edx
addl $0x7, %edx
shrl $0x3, %edx
leaq 0x1(%rdx), %rax
movl %ecx, %ecx
movq %rcx, -0x58(%rbp)
leaq 0x1(%rsi), %r8
leaq (%rdi,%r13), %r9
movq %rsi, -0x50(%rbp)
leaq (%rsi,%r13), %r10
incq %r10
movq %rdi, -0x48(%rbp)
xorl %esi, %esi
xorl %r12d, %r12d
movq %rax, -0x40(%rbp)
movq %rdx, -0x70(%rbp)
cmpq -0x58(%rbp), %rsi
je 0x176f2
imulq %rsi, %rax
movq -0x50(%rbp), %rcx
movzbl (%rcx,%rax), %eax
cmpq $0x4, %rax
ja 0x17703
leaq 0xb36a(%rip), %rcx      # 0x2286c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rsi, -0x60(%rbp)
jmpq *%rax
xorl %eax, %eax
cmpq %rax, %rdx
je 0x17592
movb (%r8,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
jmp 0x17511
testq %r12, %r12
je 0x176be
movq %r10, -0x78(%rbp)
movq %r9, -0x30(%rbp)
xorl %r15d, %r15d
movq %r8, -0x38(%rbp)
cmpq %r15, %r13
je 0x1763e
movb (%r8,%r15), %bl
movzbl (%r12,%r15), %esi
xorl %edi, %edi
xorl %edx, %edx
callq 0x178b2
movq -0x38(%rbp), %r8
addb %bl, %al
movb %al, (%r14,%r15)
incq %r15
jmp 0x1753b
xorl %eax, %eax
testq %r12, %r12
je 0x1758d
cmpq %rax, %rdx
je 0x17592
movb (%r12,%rax), %cl
addb (%r8,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
jmp 0x1756c
movb (%r8,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x17582
movq -0x60(%rbp), %rsi
movq %rsi, %r12
imulq %rdx, %r12
addq -0x48(%rbp), %r12
incq %rsi
addq %rdx, %r14
movq -0x40(%rbp), %rax
addq %rax, %r8
addq %rdx, %r9
addq %rax, %r10
jmp 0x174db
xorl %eax, %eax
testq %r12, %r12
je 0x175e7
cmpq %rax, %r13
je 0x17691
movb (%r12,%rax), %cl
shrb %cl
addb (%r8,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
jmp 0x175c0
movb (%r8,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %r13
jne 0x175dc
xorl %eax, %eax
leaq (%rax,%r13), %rcx
cmpq %rdx, %rcx
jae 0x17592
movb (%r14,%rax), %cl
shrb %cl
addb (%r10,%rax), %cl
movb %cl, (%r9,%rax)
incq %rax
jmp 0x175ee
xorl %eax, %eax
cmpq %rax, %r13
je 0x1761e
movb (%r8,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
jmp 0x1760c
xorl %eax, %eax
leaq (%rax,%r13), %rcx
cmpq %rdx, %rcx
jae 0x17592
movb (%r14,%rax), %cl
addb (%r10,%rax), %cl
movb %cl, (%r9,%rax)
incq %rax
jmp 0x17620
leaq (%r12,%r13), %rax
movq %rax, -0x68(%rbp)
xorl %r15d, %r15d
movq -0x30(%rbp), %r9
leaq (%r15,%r13), %rax
movq -0x70(%rbp), %rdx
cmpq %rdx, %rax
movq -0x78(%rbp), %r10
jae 0x17592
movb (%r10,%r15), %bl
movzbl (%r14,%r15), %edi
movq -0x68(%rbp), %rax
movzbl (%rax,%r15), %esi
movzbl (%r12,%r15), %edx
callq 0x178b2
movq -0x30(%rbp), %r9
movq -0x38(%rbp), %r8
addb %bl, %al
movb %al, (%r9,%r15)
incq %r15
jmp 0x1764d
addq %r13, %r12
xorl %eax, %eax
leaq (%rax,%r13), %rcx
cmpq %rdx, %rcx
jae 0x17592
movzbl (%r14,%rax), %ecx
movzbl (%r12,%rax), %esi
addl %ecx, %esi
shrl %esi
addb (%r10,%rax), %sil
movb %sil, (%r9,%rax)
incq %rax
jmp 0x17696
xorl %eax, %eax
cmpq %rax, %r13
je 0x176d2
movb (%r8,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
jmp 0x176c0
xorl %eax, %eax
leaq (%rax,%r13), %rcx
cmpq %rdx, %rcx
jae 0x17592
movb (%r14,%rax), %cl
addb (%r10,%rax), %cl
movb %cl, (%r9,%rax)
incq %rax
jmp 0x176d4
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x24
popq %rax
jmp 0x176f4