// File: /workspace/github_cpp_makefile_star2_O3/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 0x23ad2
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leal 0x7(%r8), %eax
movl %eax, -0x2c(%rbp)
shrl $0x3, %eax
imull %r8d, %edx
addl $0x7, %edx
movl %edx, -0x3c(%rbp)
movl %edx, %r8d
shrl $0x3, %r8d
leaq 0x1(%r8), %rdx
movl %ecx, %ecx
movq %rcx, -0x48(%rbp)
leaq 0x1(%rsi), %r11
movq %r8, %r9
subq %rax, %r9
leaq (%rdi,%rax), %r15
movq %rax, -0x38(%rbp)
leaq (%rsi,%rax), %rbx
incq %rbx
xorl %ecx, %ecx
movq %rdi, %r14
xorl %r12d, %r12d
movq %rsi, -0x60(%rbp)
movq %rdi, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
movq %r8, -0x70(%rbp)
movq %rdx, %rax
imulq %rcx, %rax
movzbl (%rsi,%rax), %eax
cmpq $0x4, %rax
ja 0x23ad5
leaq 0xd033(%rip), %rdx      # 0x30888
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
movq %rcx, -0x68(%rbp)
jmpq *%rax
cmpl $0x8, -0x3c(%rbp)
jb 0x23a95
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %r8
jne 0x2386e
jmp 0x23a95
testq %r12, %r12
je 0x23a0b
cmpl $0x8, -0x2c(%rbp)
movq -0x38(%rbp), %rdx
jb 0x238ac
xorl %eax, %eax
movb (%r12,%rax), %cl
addb (%r11,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x23898
cmpl %r8d, %edx
jae 0x23a95
movq -0x38(%rbp), %rax
addq %r12, %rax
movq %rax, -0x78(%rbp)
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r9, %rcx
movzbl (%r14,%r13), %eax
movq -0x78(%rbp), %rdx
movzbl (%rdx,%r13), %esi
movzbl (%r12,%r13), %r10d
leal (%rsi,%rax), %r8d
subl %r10d, %r8d
movl %r8d, %r9d
subl %eax, %r9d
movl %r9d, %edx
negl %edx
cmovsl %r9d, %edx
movl %r8d, %r9d
subl %esi, %r9d
movl %r9d, %ebx
negl %ebx
cmovsl %r9d, %ebx
subl %r10d, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
cmpl %r9d, %ebx
ja 0x23916
movl %esi, %r10d
cmpl %r9d, %edx
cmoval %r10d, %eax
cmpl %ebx, %edx
cmoval %r10d, %eax
movq %rdi, %rbx
addb (%rdi,%r13), %al
movb %al, (%r15,%r13)
incq %r13
movq %rcx, %r9
cmpq %r13, %rcx
movq -0x70(%rbp), %r8
jne 0x238c3
jmp 0x23a95
testq %r12, %r12
je 0x23a43
cmpl $0x8, -0x3c(%rbp)
jb 0x23a95
xorl %eax, %eax
movb (%r12,%rax), %cl
addb (%r11,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %r8
jne 0x23957
jmp 0x23a95
testq %r12, %r12
je 0x23a5d
cmpl $0x8, -0x2c(%rbp)
movq -0x38(%rbp), %rdx
jb 0x2399b
xorl %eax, %eax
movb (%r12,%rax), %cl
shrb %cl
addb (%r11,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x23985
cmpl %r8d, %edx
jae 0x23a95
addq -0x38(%rbp), %r12
xorl %eax, %eax
movzbl (%r14,%rax), %ecx
movzbl (%r12,%rax), %edx
addl %ecx, %edx
shrl %edx
addb (%rbx,%rax), %dl
movb %dl, (%r15,%rax)
incq %rax
cmpq %rax, %r9
jne 0x239aa
jmp 0x23a95
cmpl $0x8, -0x2c(%rbp)
movq -0x38(%rbp), %rdx
jb 0x239e8
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x239d8
cmpl %r8d, %edx
jae 0x23a95
xorl %eax, %eax
movb (%r14,%rax), %cl
addb (%rbx,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r9
jne 0x239f3
jmp 0x23a95
cmpl $0x8, -0x2c(%rbp)
movq -0x38(%rbp), %rdx
jb 0x23a27
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x23a17
cmpl %r8d, %edx
jae 0x23a95
xorl %eax, %eax
movb (%r14,%rax), %cl
addb (%rbx,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r9
jne 0x23a2e
jmp 0x23a95
cmpl $0x8, -0x3c(%rbp)
jb 0x23a95
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %r8
jne 0x23a4b
jmp 0x23a95
cmpl $0x8, -0x2c(%rbp)
movq -0x38(%rbp), %rdx
jb 0x23a79
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x23a69
cmpl %r8d, %edx
jae 0x23a95
xorl %eax, %eax
movb (%r14,%rax), %cl
shrb %cl
addb (%rbx,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r9
jne 0x23a80
movq -0x68(%rbp), %rcx
movq %rcx, %r12
imulq %r8, %r12
addq -0x58(%rbp), %r12
incq %rcx
addq %r8, %r14
movq -0x50(%rbp), %rdx
addq %rdx, %r11
addq %r8, %r15
addq %rdx, %rbx
cmpq -0x48(%rbp), %rcx
movq -0x60(%rbp), %rsi
jne 0x23839
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq
movl $0x24, %eax
jmp 0x23ac7