// File: /workspace/github_cpp_makefile_star2_O1/Lut99[P]RayTracer/src/lib/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 seven 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 (but aren't the same size since in has the extra filter bytes)
  */

  unsigned y;
  unsigned char* prevline = 0;

  /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/
  size_t bytewidth = (bpp + 7u) / 8u;
  size_t linebytes = (w * bpp + 7u) / 8u;

  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];

    CERROR_TRY_RETURN(unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes));

    prevline = &out[outindex];
  }

  return 0;
}

// Assembly:
testl %ecx, %ecx
je 0x71bbc
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r10
movq %rdi, %r15
leal 0x7(%r8), %r13d
movl %r13d, %r11d
shrl $0x3, %r11d
imull %r8d, %edx
addl $0x7, %edx
movl %edx, -0x54(%rsp)
movl %edx, %ebp
shrl $0x3, %ebp
leaq 0x1(%rbp), %r12
movl %ecx, %r8d
leaq 0x1(%rsi), %rdi
movq %r11, %rax
negq %rax
movq %rax, -0x38(%rsp)
movq %r15, %r9
subq %r11, %r9
movl $0x2, %eax
subq %r11, %rax
movq %rax, 0x8(%rsp)
movq %rbp, %rsi
subq %r11, %rsi
leaq (%r15,%r11), %rax
movq %rax, -0x78(%rsp)
leaq (%r10,%r11), %rax
incq %rax
movq %rax, -0x68(%rsp)
xorl %edx, %edx
movq %r15, %rbx
xorl %r14d, %r14d
movl %r13d, -0x6c(%rsp)
movq %rbp, -0x40(%rsp)
movq %r8, -0x30(%rsp)
movq %r10, (%rsp)
movq %r11, -0x8(%rsp)
movq %r15, -0x10(%rsp)
movq %r12, -0x18(%rsp)
movq %rsi, -0x20(%rsp)
movq %r12, %rax
imulq %rdx, %rax
movzbl (%r10,%rax), %eax
cmpq $0x4, %rax
movq %rdi, -0x60(%rsp)
movq %r9, -0x50(%rsp)
ja 0x714e8
leaq 0x181bb(%rip), %rcx     # 0x89554
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %r9d, %r9d
movb $0x1, %r13b
cmpl $0x8, -0x54(%rsp)
movq -0x68(%rsp), %r14
jb 0x715ad
xorl %eax, %eax
movq -0x60(%rsp), %rdi
movb (%rdi,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq %rax, %rbp
jne 0x713bf
jmp 0x715ad
testq %r14, %r14
je 0x71500
cmpl $0x8, -0x6c(%rsp)
jae 0x7160b
xorl %eax, %eax
jmp 0x71622
xorl %r9d, %r9d
movb $0x1, %r13b
testq %r14, %r14
je 0x71546
cmpl $0x8, -0x54(%rsp)
jb 0x714f1
xorl %eax, %eax
movq -0x60(%rsp), %rdi
movb (%r14,%rax), %cl
addb (%rdi,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq %rax, %rbp
jne 0x7140e
jmp 0x714f1
testq %r14, %r14
je 0x71569
cmpl $0x8, -0x6c(%rsp)
jb 0x7144b
xorl %eax, %eax
movb (%r14,%rax), %cl
shrb %cl
addb (%rdi,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq %rax, %r11
jne 0x71437
xorl %r9d, %r9d
movb $0x1, %r13b
cmpl %ebp, %r11d
jae 0x714f1
movq %rdx, -0x48(%rsp)
addq %r11, %r14
xorl %eax, %eax
movq -0x78(%rsp), %rdi
movq -0x68(%rsp), %rdx
movzbl (%rbx,%rax), %ecx
movzbl (%r14,%rax), %r8d
addl %ecx, %r8d
shrl %r8d
addb (%rdx,%rax), %r8b
movb %r8b, (%rdi,%rax)
incq %rax
cmpq %rax, %rsi
jne 0x7146e
movq -0x30(%rsp), %r8
movq %rdx, %r14
movq -0x48(%rsp), %rdx
jmp 0x715b2
cmpl $0x8, -0x6c(%rsp)
movq -0x68(%rsp), %r14
jb 0x714bb
xorl %eax, %eax
movb (%rdi,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq %rax, %r11
jne 0x714ad
xorl %r9d, %r9d
movb $0x1, %r13b
cmpl %ebp, %r11d
jae 0x715ad
xorl %eax, %eax
movq -0x78(%rsp), %rdi
movb (%rbx,%rax), %cl
addb (%r14,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %rsi
jne 0x714d1
jmp 0x715b2
xorl %r13d, %r13d
movl $0x24, %r9d
movq -0x78(%rsp), %rdi
movq -0x68(%rsp), %r14
jmp 0x715b2
cmpl $0x8, -0x6c(%rsp)
jb 0x71517
xorl %eax, %eax
movb (%rdi,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq %rax, %r11
jne 0x71509
xorl %r9d, %r9d
movb $0x1, %r13b
cmpl %ebp, %r11d
movq -0x68(%rsp), %r14
jae 0x715ad
xorl %eax, %eax
movq -0x78(%rsp), %rdi
movb (%rbx,%rax), %cl
addb (%r14,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %rsi
jne 0x71532
jmp 0x715b2
cmpl $0x8, -0x54(%rsp)
jb 0x714f1
xorl %eax, %eax
movq -0x60(%rsp), %rdi
movq -0x68(%rsp), %r14
movb (%rdi,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq %rax, %rbp
jne 0x71559
jmp 0x715ad
cmpl $0x8, -0x6c(%rsp)
jb 0x71580
xorl %eax, %eax
movb (%rdi,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq %rax, %r11
jne 0x71572
xorl %r9d, %r9d
movb $0x1, %r13b
cmpl %ebp, %r11d
movq -0x68(%rsp), %r14
jae 0x715ad
xorl %eax, %eax
movq -0x78(%rsp), %rdi
movb (%rbx,%rax), %cl
shrb %cl
addb (%r14,%rax), %cl
movb %cl, (%rdi,%rax)
incq %rax
cmpq %rax, %rsi
jne 0x71597
jmp 0x715b2
movq -0x78(%rsp), %rdi
movl -0x7c(%rsp), %eax
testb %r13b, %r13b
cmovel %r9d, %eax
je 0x71bc1
movl %eax, -0x7c(%rsp)
movq %r14, %rcx
movq %rdx, %r14
imulq %rbp, %r14
addq %r15, %r14
incq %rdx
addq %rbp, %rbx
movq %rdi, %rax
movq -0x60(%rsp), %rdi
addq %r12, %rdi
movq -0x50(%rsp), %r9
addq %rbp, %r9
addq %rbp, %rax
movq %rax, -0x78(%rsp)
addq %r12, %rcx
movq %rcx, -0x68(%rsp)
cmpq %r8, %rdx
jne 0x71372
jmp 0x71bbf
xorl %eax, %eax
movb (%r14,%rax), %cl
addb (%rdi,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
cmpq %rax, %r11
jne 0x7160d
movq %r11, %rax
cmpl $0x20, -0x6c(%rsp)
movq %rdx, -0x48(%rsp)
jb 0x7181c
leaq 0x3(%rax), %rsi
cmpq %rbp, %rsi
jae 0x71abe
movq %r9, %r8
movq -0x38(%rsp), %rax
addq %r14, %rax
movq %rax, -0x28(%rsp)
movzbl -0x3(%r8,%rsi), %r11d
movzbl -0x2(%r8,%rsi), %r13d
movzbl -0x3(%r14,%rsi), %eax
movzbl -0x2(%r14,%rsi), %ecx
movq -0x28(%rsp), %rdi
movzbl -0x3(%rdi,%rsi), %edx
movl %eax, %r10d
subl %edx, %r10d
movl %r10d, %ebp
negl %ebp
cmovsl %r10d, %ebp
movl $0xff, %r9d
andl %r9d, %ebp
movl %r11d, %r10d
subl %edx, %r10d
movl %r10d, %r12d
negl %r12d
cmovsl %r10d, %r12d
andl %r9d, %r12d
leal (%rax,%r11), %r10d
subl %edx, %r10d
subl %edx, %r10d
movl %r10d, %r15d
negl %r15d
cmovsl %r10d, %r15d
cmpl %ebp, %r12d
cmovael %ebp, %r12d
cmovbl %eax, %r11d
movzbl -0x2(%rdi,%rsi), %r10d
cmpl %r12d, %r15d
cmovbl %edx, %r11d
movq -0x60(%rsp), %r9
addb -0x3(%r9,%rsi), %r11b
movl %ecx, %eax
subl %r10d, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
movzbl -0x1(%r8,%rsi), %eax
movl $0xff, %r12d
andl %r12d, %ebp
movl %r13d, %edx
subl %r10d, %edx
movl %edx, %r15d
negl %r15d
cmovsl %edx, %r15d
andl %r12d, %r15d
leal (%rcx,%r13), %edx
subl %r10d, %edx
subl %r10d, %edx
movl %edx, %r12d
negl %r12d
cmovsl %edx, %r12d
movzbl (%r8,%rsi), %edx
cmpl %ebp, %r15d
cmovael %ebp, %r15d
movzbl -0x1(%r14,%rsi), %ebp
cmovbl %ecx, %r13d
cmpl %r15d, %r12d
cmovbl %r10d, %r13d
addb -0x2(%r9,%rsi), %r13b
movzbl -0x1(%rdi,%rsi), %r12d
movl %ebp, %ecx
subl %r12d, %ecx
movl %ecx, %r10d
negl %r10d
cmovsl %ecx, %r10d
movl $0xff, %r8d
andl %r8d, %r10d
movl %eax, %ecx
subl %r12d, %ecx
movl %ecx, %r15d
negl %r15d
cmovsl %ecx, %r15d
andl %r8d, %r15d
leal (%rax,%rbp), %ecx
subl %r12d, %ecx
subl %r12d, %ecx
movl %ecx, %r8d
negl %r8d
cmovsl %ecx, %r8d
movzbl (%r14,%rsi), %ecx
cmpl %r10d, %r15d
cmovael %r10d, %r15d
cmovbl %ebp, %eax
movzbl (%rdi,%rsi), %r10d
cmpl %r15d, %r8d
cmovbl %r12d, %eax
addb -0x1(%r9,%rsi), %al
movl %ecx, %r8d
subl %r10d, %r8d
movl %r8d, %ebp
negl %ebp
cmovsl %r8d, %ebp
movl $0xff, %edi
andl %edi, %ebp
movl %edx, %r8d
subl %r10d, %r8d
movl %r8d, %r15d
negl %r15d
cmovsl %r8d, %r15d
andl %edi, %r15d
leal (%rcx,%rdx), %r8d
subl %r10d, %r8d
subl %r10d, %r8d
movl %r8d, %r12d
negl %r12d
cmovsl %r8d, %r12d
movq -0x50(%rsp), %r8
cmpl %ebp, %r15d
cmovael %ebp, %r15d
cmovbl %ecx, %edx
cmpl %r15d, %r12d
movq -0x40(%rsp), %rbp
cmovbl %r10d, %edx
addb (%r9,%rsi), %dl
movb %r11b, -0x3(%rbx,%rsi)
movb %r13b, -0x2(%rbx,%rsi)
movb %al, -0x1(%rbx,%rsi)
movb %dl, (%rbx,%rsi)
addq $0x4, %rsi
cmpq %rbp, %rsi
jb 0x7164f
addq $-0x3, %rsi
jmp 0x71abb
cmpl $0x3, %r11d
jne 0x719a9
leal 0x2(%rax), %ecx
cmpl %ebp, %ecx
jae 0x71abe
movq %r9, %rdx
movq 0x8(%rsp), %rcx
addq %r14, %rcx
movq %rcx, -0x28(%rsp)
movq %rax, %r9
movq %rdx, %r8
movzbl (%r8,%r9), %r11d
movzbl 0x1(%r8,%r9), %r13d
movzbl (%r14,%r9), %r12d
movzbl 0x1(%r14,%r9), %ecx
movq -0x28(%rsp), %rdi
movzbl -0x2(%rdi,%r9), %r10d
movl %r12d, %eax
subl %r10d, %eax
movl %eax, %r8d
negl %r8d
cmovsl %eax, %r8d
movl $0xff, %esi
andl %esi, %r8d
movl %r11d, %eax
subl %r10d, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
andl %esi, %ebp
leal (%r12,%r11), %eax
subl %r10d, %eax
subl %r10d, %eax
movl %eax, %r15d
negl %r15d
cmovsl %eax, %r15d
movzbl 0x2(%r14,%r9), %eax
cmpl %r8d, %ebp
cmovael %r8d, %ebp
cmovbl %r12d, %r11d
movzbl -0x1(%rdi,%r9), %r12d
cmpl %ebp, %r15d
cmovbl %r10d, %r11d
movq -0x60(%rsp), %rdx
addb (%rdx,%r9), %r11b
movl %ecx, %r8d
subl %r12d, %r8d
movl %r8d, %r10d
negl %r10d
cmovsl %r8d, %r10d
andl %esi, %r10d
movl %r13d, %r8d
subl %r12d, %r8d
movl %r8d, %ebp
negl %ebp
cmovsl %r8d, %ebp
andl %esi, %ebp
leal (%rcx,%r13), %r8d
subl %r12d, %r8d
subl %r12d, %r8d
movl %r8d, %r15d
negl %r15d
cmovsl %r8d, %r15d
cmpl %r10d, %ebp
cmovael %r10d, %ebp
cmovbl %ecx, %r13d
movzbl (%rdi,%r9), %ecx
cmpl %ebp, %r15d
cmovbl %r12d, %r13d
addb 0x1(%rdx,%r9), %r13b
movl %eax, %r10d
subl %ecx, %r10d
movl %r10d, %r8d
negl %r8d
cmovsl %r10d, %r8d
movq -0x50(%rsp), %rdi
movzbl 0x2(%rdi,%r9), %r12d
andl %esi, %r8d
movl %r12d, %r10d
subl %ecx, %r10d
movl %r10d, %ebp
negl %ebp
cmovsl %r10d, %ebp
andl %esi, %ebp
leal (%rax,%r12), %r10d
subl %ecx, %r10d
subl %ecx, %r10d
movl %r10d, %r15d
negl %r15d
cmovsl %r10d, %r15d
cmpl %r8d, %ebp
cmovael %r8d, %ebp
movq -0x50(%rsp), %r8
cmovbl %eax, %r12d
cmpl %ebp, %r15d
movq -0x40(%rsp), %rbp
cmovbl %ecx, %r12d
addb 0x2(%rdx,%r9), %r12b
movb %r11b, (%rbx,%r9)
movb %r13b, 0x1(%rbx,%r9)
movb %r12b, 0x2(%rbx,%r9)
leaq 0x3(%r9), %rax
addq $0x5, %r9
cmpq %rbp, %r9
movq %rax, %r9
jb 0x71847
jmp 0x71abe
cmpl $0x10, -0x6c(%rsp)
jb 0x71abe
leaq 0x1(%rax), %rsi
cmpl %ebp, %esi
movq -0x60(%rsp), %rdi
jae 0x71abe
movq %r9, %r8
movq -0x38(%rsp), %rax
leaq (%r14,%rax), %rdx
movl $0xff, %r13d
movzbl -0x1(%r8,%rsi), %r12d
movzbl -0x1(%r14,%rsi), %r9d
movzbl (%r14,%rsi), %ecx
movzbl -0x1(%rdx,%rsi), %r10d
movq %r8, %rax
movl %r9d, %r8d
subl %r10d, %r8d
movl %r8d, %r11d
negl %r11d
cmovsl %r8d, %r11d
andl %r13d, %r11d
movl %r12d, %r8d
subl %r10d, %r8d
movl %r8d, %ebp
negl %ebp
cmovsl %r8d, %ebp
andl %r13d, %ebp
leal (%r9,%r12), %r8d
subl %r10d, %r8d
subl %r10d, %r8d
movl %r8d, %r15d
negl %r15d
cmovsl %r8d, %r15d
cmpl %r11d, %ebp
cmovael %r11d, %ebp
cmovbl %r9d, %r12d
movzbl (%rdx,%rsi), %r9d
cmpl %ebp, %r15d
cmovbl %r10d, %r12d
addb -0x1(%rdi,%rsi), %r12b
movl %ecx, %r8d
subl %r9d, %r8d
movl %r8d, %r11d
negl %r11d
cmovsl %r8d, %r11d
movzbl (%rax,%rsi), %r10d
andl %r13d, %r11d
movl %r10d, %r8d
subl %r9d, %r8d
movl %r8d, %ebp
negl %ebp
cmovsl %r8d, %ebp
andl %r13d, %ebp
leal (%rcx,%r10), %r8d
subl %r9d, %r8d
subl %r9d, %r8d
movl %r8d, %r15d
negl %r15d
cmovsl %r8d, %r15d
movq %rax, %r8
cmpl %r11d, %ebp
cmovael %r11d, %ebp
cmovbl %ecx, %r10d
cmpl %ebp, %r15d
movq -0x40(%rsp), %rbp
cmovbl %r9d, %r10d
addb (%rdi,%rsi), %r10b
movb %r12b, -0x1(%rbx,%rsi)
movb %r10b, (%rbx,%rsi)
addq $0x2, %rsi
cmpq %rbp, %rsi
jb 0x719d7
decq %rsi
movq %rsi, %rax
xorl %r9d, %r9d
movb $0x1, %r13b
cmpq %rbp, %rax
jne 0x71afe
movq (%rsp), %r10
movq -0x10(%rsp), %r15
movq -0x8(%rsp), %r11
movq -0x18(%rsp), %r12
movq -0x30(%rsp), %r8
movq -0x20(%rsp), %rsi
movq -0x78(%rsp), %rdi
movq -0x68(%rsp), %r14
movl -0x7c(%rsp), %eax
movq -0x48(%rsp), %rdx
jmp 0x715b6
movq -0x38(%rsp), %rcx
addq %r14, %rcx
movq -0x60(%rsp), %rdi
movq -0x50(%rsp), %rsi
movl $0xff, %r9d
movzbl (%r14,%rax), %r10d
movzbl (%rcx,%rax), %edx
movl %r10d, %r8d
subl %edx, %r8d
movl %r8d, %ebp
negl %ebp
cmovsl %r8d, %ebp
movzbl (%rsi,%rax), %r11d
andl %r9d, %ebp
movl %r11d, %r8d
subl %edx, %r8d
movl %r8d, %r15d
negl %r15d
cmovsl %r8d, %r15d
andl %r9d, %r15d
leal (%r10,%r11), %r8d
subl %edx, %r8d
subl %edx, %r8d
movl %r8d, %r12d
negl %r12d
cmovsl %r8d, %r12d
cmpl %ebp, %r15d
cmovael %ebp, %r15d
cmovbl %r10d, %r11d
cmpl %r15d, %r12d
movq -0x40(%rsp), %rbp
cmovbl %edx, %r11d
addb (%rdi,%rax), %r11b
movb %r11b, (%rbx,%rax)
incq %rax
cmpq %rax, %rbp
jne 0x71b16
movq (%rsp), %r10
movq -0x10(%rsp), %r15
movq -0x8(%rsp), %r11
movq -0x18(%rsp), %r12
movq -0x30(%rsp), %r8
movq -0x20(%rsp), %rsi
movq -0x78(%rsp), %rdi
movq -0x68(%rsp), %r14
movq -0x48(%rsp), %rdx
movl -0x7c(%rsp), %eax
xorl %r9d, %r9d
jmp 0x715b6
xorl %eax, %eax
retq
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq