// File: /workspace/github_cpp_makefile_star2_O1/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:
testl %ecx, %ecx
je 0x24fd2
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leal 0x7(%r8), %eax
movl %eax, %r10d
shrl $0x3, %r10d
imull %r8d, %edx
addl $0x7, %edx
movl %edx, -0x3c(%rbp)
movl %edx, %r14d
shrl $0x3, %r14d
leaq 0x1(%r14), %r8
movl %ecx, %ecx
movq %rcx, -0x68(%rbp)
leaq 0x1(%rsi), %rbx
movq %r14, %rdx
subq %r10, %rdx
leaq (%rdi,%r10), %r15
leaq (%rsi,%r10), %r12
incq %r12
xorl %ecx, %ecx
movq %rdi, -0x70(%rbp)
movq %rdi, %r11
movl %eax, %edi
xorl %r13d, %r13d
movq %rcx, %r9
movq %r8, %rcx
movq %r9, -0x38(%rbp)
imulq %r9, %rcx
movzbl (%rsi,%rcx), %ecx
cmpq $0x4, %rcx
ja 0x24ee3
leaq 0xcb75(%rip), %r9       # 0x3186c
movslq (%r9,%rcx,4), %rcx
addq %r9, %rcx
jmpq *%rcx
xorl %r9d, %r9d
movb $0x1, %r13b
cmpl $0x8, -0x3c(%rbp)
jb 0x24f94
movl %eax, %r13d
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%r11,%rax)
incq %rax
cmpq %rax, %r14
jne 0x24d15
jmp 0x24f4c
movl %eax, -0x2c(%rbp)
testq %r13, %r13
je 0x24ef6
cmpl $0x8, %edi
jb 0x24d50
xorl %eax, %eax
movb (%r13,%rax), %cl
addb (%rbx,%rax), %cl
movb %cl, (%r11,%rax)
incq %rax
cmpq %rax, %r10
jne 0x24d3c
xorl %r9d, %r9d
cmpl %r14d, %r10d
jae 0x24ef1
movq %r8, -0x48(%rbp)
movq %r14, -0x50(%rbp)
movl %edi, -0x40(%rbp)
movq %rsi, -0x60(%rbp)
movq %r10, -0x58(%rbp)
leaq (%r10,%r13), %rax
movq %rax, -0x78(%rbp)
xorl %esi, %esi
movq %rdx, %rdi
movzbl (%r11,%rsi), %edx
movq -0x78(%rbp), %rax
movzbl (%rax,%rsi), %r14d
movzbl (%r13,%rsi), %ecx
leal (%r14,%rdx), %r8d
subl %ecx, %r8d
movl %r8d, %r9d
subl %edx, %r9d
movl %r9d, %eax
negl %eax
cmovsl %r9d, %eax
movl %r8d, %r9d
subl %r14d, %r9d
movl %r9d, %r10d
negl %r10d
cmovsl %r9d, %r10d
subl %ecx, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
cmpl %r9d, %r10d
ja 0x24dcb
movl %r14d, %ecx
cmpl %r9d, %eax
cmoval %ecx, %edx
cmpl %r10d, %eax
cmoval %ecx, %edx
addb (%r12,%rsi), %dl
movb %dl, (%r15,%rsi)
incq %rsi
movq %rdi, %rdx
cmpq %rsi, %rdi
jne 0x24d79
movq -0x60(%rbp), %rsi
movl -0x40(%rbp), %edi
movq -0x58(%rbp), %r10
movq -0x50(%rbp), %r14
movq -0x48(%rbp), %r8
jmp 0x24e97
xorl %r9d, %r9d
testq %r13, %r13
je 0x24f2f
cmpl $0x8, -0x3c(%rbp)
jb 0x24f4f
movl %eax, -0x2c(%rbp)
xorl %eax, %eax
movb (%r13,%rax), %cl
addb (%rbx,%rax), %cl
movb %cl, (%r11,%rax)
incq %rax
cmpq %rax, %r14
jne 0x24e1d
jmp 0x24ef1
movl %eax, -0x2c(%rbp)
testq %r13, %r13
je 0x24f58
cmpl $0x8, %edi
jb 0x24e5f
xorl %eax, %eax
movb (%r13,%rax), %cl
shrb %cl
addb (%rbx,%rax), %cl
movb %cl, (%r11,%rax)
incq %rax
cmpq %rax, %r10
jne 0x24e49
xorl %r9d, %r9d
cmpl %r14d, %r10d
jae 0x24ef1
movq %r8, %r9
addq %r10, %r13
xorl %eax, %eax
movzbl (%r11,%rax), %ecx
movzbl (%r13,%rax), %r8d
addl %ecx, %r8d
shrl %r8d
addb (%r12,%rax), %r8b
movb %r8b, (%r15,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x24e73
movq %r9, %r8
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rcx
xorl %r9d, %r9d
jmp 0x24f53
movl %eax, %r13d
cmpl $0x8, %edi
jb 0x24ebf
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%r11,%rax)
incq %rax
cmpq %rax, %r10
jne 0x24eb0
xorl %r9d, %r9d
cmpl %r14d, %r10d
jae 0x24f4c
xorl %eax, %eax
movb (%r11,%rax), %cl
addb (%r12,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x24ecd
jmp 0x24f4c
xorl %r13d, %r13d
movl $0x24, %r9d
jmp 0x24f94
movl -0x2c(%rbp), %eax
jmp 0x24f4f
cmpl $0x8, %edi
jb 0x24f0c
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%r11,%rax)
incq %rax
cmpq %rax, %r10
jne 0x24efd
xorl %r9d, %r9d
movb $0x1, %r13b
cmpl %r14d, %r10d
jae 0x24f91
xorl %eax, %eax
movb (%r11,%rax), %cl
addb (%r12,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x24f19
jmp 0x24f91
movb $0x1, %r13b
cmpl $0x8, -0x3c(%rbp)
jb 0x24f94
movl %eax, %r13d
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%r11,%rax)
incq %rax
cmpq %rax, %r14
jne 0x24f3d
movl %r13d, %eax
movq -0x38(%rbp), %rcx
movb $0x1, %r13b
jmp 0x24f98
cmpl $0x8, %edi
jb 0x24f6e
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%r11,%rax)
incq %rax
cmpq %rax, %r10
jne 0x24f5f
xorl %r9d, %r9d
movb $0x1, %r13b
cmpl %r14d, %r10d
jae 0x24f91
xorl %eax, %eax
movb (%r11,%rax), %cl
shrb %cl
addb (%r12,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x24f7b
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rcx
testb %r13b, %r13b
cmovel %r9d, %eax
je 0x24fc7
movq %rcx, %r13
imulq %r14, %r13
addq -0x70(%rbp), %r13
incq %rcx
addq %r14, %r11
addq %r8, %rbx
addq %r14, %r15
addq %r8, %r12
cmpq -0x68(%rbp), %rcx
jne 0x24cd4
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq