// File: /workspace/github_cpp_makefile_star2_O3/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 0x71104
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leal 0x7(%r8), %eax
movl %eax, -0x78(%rsp)
movl %eax, %r10d
shrl $0x3, %r10d
imull %r8d, %edx
addl $0x7, %edx
movl %edx, -0x74(%rsp)
movl %edx, %r14d
shrl $0x3, %r14d
leaq 0x1(%r14), %r9
cmpl $0x1, %r10d
setne %al
leaq 0x1(%r10), %rdx
cmpq %r14, %rdx
setb %dl
andb %al, %dl
movb %dl, -0x79(%rsp)
leaq 0x2(%r10), %rax
movq %rax, -0x8(%rsp)
leaq 0x3(%r10), %rax
movq %rax, -0x50(%rsp)
movl %ecx, %eax
movq %rax, 0x10(%rsp)
leaq 0x1(%rsi), %r15
leaq 0x3(%rsi), %rax
movq %rax, -0x38(%rsp)
movq %r10, %rax
negq %rax
movq %rax, -0x48(%rsp)
movq %rdi, %rax
subq %r10, %rax
movq %rax, -0x58(%rsp)
leaq 0x4(%rsi), %r13
leaq (%rdi,%r10), %rax
addq $0x3, %rax
movq %r14, %rbx
subq %r10, %rbx
movq %rsi, %rcx
movq %rdi, %rdx
leaq (%rsi,%r10), %r11
addq $0x4, %r11
leaq (%rdi,%r10), %r12
leaq (%rsi,%r10), %rbp
incq %rbp
xorl %edi, %edi
movq %rdx, %r8
xorl %esi, %esi
movq %rcx, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq %r13, %rdx
movq %r10, -0x70(%rsp)
movq %r14, -0x68(%rsp)
movq %r9, 0x18(%rsp)
movq %rbx, -0x28(%rsp)
movq %r9, %rcx
imulq %rdi, %rcx
movq 0x28(%rsp), %r9
movzbl (%r9,%rcx), %ecx
cmpq $0x4, %rcx
ja 0x71107
movq %rdi, %r9
imulq %r14, %r9
addq 0x20(%rsp), %r9
movq %r9, -0x30(%rsp)
leaq 0x17bb1(%rip), %r9      # 0x88574
movslq (%r9,%rcx,4), %rcx
addq %r9, %rcx
movq %rax, -0x10(%rsp)
movq %r11, -0x60(%rsp)
movq %rdi, 0x30(%rsp)
jmpq *%rcx
cmpl $0x8, -0x74(%rsp)
jb 0x70c18
xorl %ecx, %ecx
movb (%r15,%rcx), %al
movb %al, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r14
jne 0x709e8
jmp 0x70c18
testq %rsi, %rsi
je 0x70b93
cmpl $0x8, -0x78(%rsp)
movq %r12, -0x18(%rsp)
movq %rbp, -0x20(%rsp)
jae 0x70c68
xorl %r9d, %r9d
movl $0xff, %r13d
cmpq %r14, %r9
movq -0x28(%rsp), %rbx
movq -0x18(%rsp), %r12
movq -0x20(%rsp), %rbp
je 0x70c18
movq -0x48(%rsp), %rax
leaq (%rsi,%rax), %r11
movzbl (%rsi,%r9), %ebx
movzbl (%r11,%r9), %ecx
movl %ebx, %eax
subl %ecx, %eax
movl %eax, %r12d
negl %r12d
cmovsl %eax, %r12d
movq -0x58(%rsp), %rax
movzbl (%rax,%r9), %r14d
andl %r13d, %r12d
movl %r14d, %eax
subl %ecx, %eax
movl %eax, %r10d
negl %r10d
cmovsl %eax, %r10d
andl %r13d, %r10d
leal (%rbx,%r14), %eax
subl %ecx, %eax
subl %ecx, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
cmpl %r12d, %r10d
cmovael %r12d, %r10d
movq -0x18(%rsp), %r12
cmovbl %ebx, %r14d
movq -0x28(%rsp), %rbx
cmpl %r10d, %ebp
movq -0x20(%rsp), %rbp
cmovbl %ecx, %r14d
addb (%r15,%r9), %r14b
movb %r14b, (%r8,%r9)
movq -0x68(%rsp), %r14
incq %r9
cmpq %r9, %r14
jne 0x70a45
jmp 0x70c18
testq %rsi, %rsi
movl -0x74(%rsp), %eax
je 0x70bc9
cmpl $0x8, %eax
jb 0x70c18
xorl %ecx, %ecx
movb (%rsi,%rcx), %r9b
addb (%r15,%rcx), %r9b
movb %r9b, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r14
jne 0x70ade
jmp 0x70c18
testq %rsi, %rsi
je 0x70be2
cmpl $0x8, -0x78(%rsp)
jb 0x70b20
xorl %ecx, %ecx
movb (%rsi,%rcx), %r9b
shrb %r9b
addb (%r15,%rcx), %r9b
movb %r9b, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r10
jne 0x70b09
cmpl %r14d, %r10d
jae 0x70c18
addq -0x70(%rsp), %rsi
xorl %ecx, %ecx
movzbl (%r8,%rcx), %r9d
movzbl (%rsi,%rcx), %r11d
addl %r9d, %r11d
shrl %r11d
addb (%rbp,%rcx), %r11b
movb %r11b, (%r12,%rcx)
incq %rcx
cmpq %rcx, %rbx
jne 0x70b30
jmp 0x70c18
cmpl $0x8, -0x78(%rsp)
jb 0x70b6f
xorl %ecx, %ecx
movb (%r15,%rcx), %al
movb %al, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r10
jne 0x70b5f
cmpl %r14d, %r10d
jae 0x70c18
xorl %ecx, %ecx
movb (%r8,%rcx), %al
addb (%rbp,%rcx), %al
movb %al, (%r12,%rcx)
incq %rcx
cmpq %rcx, %rbx
jne 0x70b7a
jmp 0x70c18
cmpl $0x8, -0x78(%rsp)
jb 0x70bac
xorl %ecx, %ecx
movb (%r15,%rcx), %al
movb %al, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r10
jne 0x70b9c
cmpl %r14d, %r10d
jae 0x70c18
xorl %ecx, %ecx
movb (%r8,%rcx), %al
addb (%rbp,%rcx), %al
movb %al, (%r12,%rcx)
incq %rcx
cmpq %rcx, %rbx
jne 0x70bb3
jmp 0x70c18
cmpl $0x8, %eax
jb 0x70c18
xorl %ecx, %ecx
movb (%r15,%rcx), %al
movb %al, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r14
jne 0x70bd0
jmp 0x70c18
cmpl $0x8, -0x78(%rsp)
jb 0x70bfb
xorl %ecx, %ecx
movb (%r15,%rcx), %al
movb %al, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r10
jne 0x70beb
cmpl %r14d, %r10d
jae 0x70c18
xorl %ecx, %ecx
movb (%r8,%rcx), %al
shrb %al
addb (%rbp,%rcx), %al
movb %al, (%r12,%rcx)
incq %rcx
cmpq %rcx, %rbx
jne 0x70c02
movq 0x30(%rsp), %rdi
incq %rdi
addq %r14, %r8
movq 0x18(%rsp), %r9
addq %r9, %r15
addq %r9, -0x38(%rsp)
addq %r14, -0x58(%rsp)
addq %r9, %rdx
movq -0x10(%rsp), %rax
addq %r14, %rax
movq -0x60(%rsp), %r11
addq %r9, %r11
addq %r14, %r12
addq %r9, %rbp
cmpq 0x10(%rsp), %rdi
movq -0x70(%rsp), %r10
movq -0x30(%rsp), %rsi
jne 0x70990
jmp 0x710f3
xorl %ecx, %ecx
movb (%rsi,%rcx), %r9b
addb (%r15,%rcx), %r9b
movb %r9b, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r10
jne 0x70c6a
cmpl $0x20, -0x78(%rsp)
movq %rdx, -0x40(%rsp)
movl $0xff, %r13d
jb 0x70e7e
movq %r10, %r9
cmpl %r14d, -0x50(%rsp)
jae 0x70a24
movq -0x50(%rsp), %rax
addq %rsi, %rax
movq %rax, (%rsp)
xorl %r9d, %r9d
movzbl (%r8,%r9), %ebx
movzbl 0x1(%r8,%r9), %r11d
movl $0xff, %edx
movq (%rsp), %rdi
movzbl -0x3(%rdi,%r9), %r13d
movzbl (%rsi,%r9), %ecx
movl %r13d, %ebp
subl %ecx, %ebp
movl %ebp, %r12d
negl %r12d
cmovsl %ebp, %r12d
movzbl 0x2(%r8,%r9), %r14d
andl %edx, %r12d
movl %ebx, %r10d
subl %ecx, %r10d
movl %r10d, %ebp
negl %ebp
cmovsl %r10d, %ebp
andl %edx, %ebp
leal (%rbx,%r13), %r10d
subl %ecx, %r10d
subl %ecx, %r10d
movl %r10d, %eax
negl %eax
cmovsl %r10d, %eax
movzbl -0x2(%rdi,%r9), %r10d
cmpl %r12d, %ebp
cmovael %r12d, %ebp
movzbl -0x1(%rdi,%r9), %r12d
cmovbl %r13d, %ebx
cmpl %ebp, %eax
cmovbl %ecx, %ebx
movq -0x60(%rsp), %rax
addb -0x3(%rax,%r9), %bl
movzbl 0x1(%rsi,%r9), %ecx
movl %r10d, %eax
subl %ecx, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
andl %edx, %ebp
movl %r11d, %r13d
subl %ecx, %r13d
movl %r13d, %eax
negl %eax
cmovsl %r13d, %eax
andl %edx, %eax
leal (%r10,%r11), %r13d
subl %ecx, %r13d
subl %ecx, %r13d
movl %r13d, %edx
negl %edx
cmovsl %r13d, %edx
movzbl (%rdi,%r9), %edi
movq %rdi, 0x8(%rsp)
movl $0xff, %r13d
cmpl %ebp, %eax
cmovael %ebp, %eax
cmovbl %r10d, %r11d
movzbl 0x2(%rsi,%r9), %ebp
cmpl %eax, %edx
cmovbl %ecx, %r11d
movq -0x60(%rsp), %rdi
addb -0x2(%rdi,%r9), %r11b
movl %r12d, %eax
subl %ebp, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
andl %r13d, %ecx
movl %r14d, %eax
subl %ebp, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
andl %r13d, %edx
leal (%r12,%r14), %eax
subl %ebp, %eax
subl %ebp, %eax
movl %eax, %r10d
negl %r10d
cmovsl %eax, %r10d
cmpl %ecx, %edx
cmovael %ecx, %edx
cmovbl %r12d, %r14d
movzbl 0x3(%rsi,%r9), %r12d
cmpl %edx, %r10d
cmovbl %ebp, %r14d
addb -0x1(%rdi,%r9), %r14b
movq 0x8(%rsp), %rbp
movl %ebp, %eax
subl %r12d, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
movzbl 0x3(%r8,%r9), %ecx
andl %r13d, %edx
movl %ecx, %eax
subl %r12d, %eax
movl %eax, %r10d
negl %r10d
cmovsl %eax, %r10d
andl %r13d, %r10d
leal (%rcx,%rbp), %eax
movq %rbp, %r13
subl %r12d, %eax
subl %r12d, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
cmpl %edx, %r10d
cmovael %edx, %r10d
cmovbl %r13d, %ecx
cmpl %r10d, %ebp
cmovbl %r12d, %ecx
addb (%rdi,%r9), %cl
movq -0x10(%rsp), %rax
movb %bl, -0x3(%rax,%r9)
movb %r11b, -0x2(%rax,%r9)
movb %r14b, -0x1(%rax,%r9)
movq -0x68(%rsp), %r14
movb %cl, (%rax,%r9)
movq -0x70(%rsp), %rax
addq %r9, %rax
addq $0x7, %rax
addq $0x4, %r9
cmpq %r14, %rax
jb 0x70cb1
addq -0x70(%rsp), %r9
movq -0x40(%rsp), %rdx
jmp 0x70a1e
cmpl $0x3, %r10d
jne 0x70fea
movl $0x3, %r9d
cmpl %r14d, -0x8(%rsp)
jae 0x70a24
movq -0x30(%rsp), %rax
movb (%rax), %bpl
movl $0x3, %r11d
movq %rdx, %rdi
movzbl (%rsi,%r11), %ebx
movzbl -0x3(%rsi,%r11), %r9d
movl %ebx, %eax
subl %r9d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
andl %r13d, %ecx
movzbl %bpl, %r14d
movl %r14d, %eax
subl %r9d, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
andl %r13d, %ebp
leal (%rbx,%r14), %eax
subl %r9d, %eax
subl %r9d, %eax
movl %eax, %r12d
negl %r12d
cmovsl %eax, %r12d
cmpl %ecx, %ebp
jb 0x70ef5
movl %ecx, %ebp
movl %r14d, %ebx
cmpl %ebp, %r12d
movq %rdi, %rax
jb 0x70f00
movl %ebx, %r9d
movzbl -0x2(%r8,%r11), %ebx
movzbl 0x1(%rsi,%r11), %r12d
movzbl 0x2(%rsi,%r11), %r14d
movzbl -0x2(%rsi,%r11), %ecx
addb -0x3(%rax,%r11), %r9b
movl %r12d, %eax
subl %ecx, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
andl %r13d, %edx
movl %ebx, %eax
subl %ecx, %eax
movl %eax, %r10d
negl %r10d
cmovsl %eax, %r10d
andl %r13d, %r10d
leal (%r12,%rbx), %eax
subl %ecx, %eax
subl %ecx, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
cmpl %edx, %r10d
cmovael %edx, %r10d
cmovbl %r12d, %ebx
movzbl -0x1(%rsi,%r11), %r12d
cmpl %r10d, %ebp
cmovbl %ecx, %ebx
addb -0x2(%rdi,%r11), %bl
movl %r14d, %eax
subl %r12d, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
movzbl -0x1(%r8,%r11), %ecx
andl %r13d, %edx
movl %ecx, %eax
subl %r12d, %eax
movl %eax, %r10d
negl %r10d
cmovsl %eax, %r10d
andl %r13d, %r10d
leal (%r14,%rcx), %eax
subl %r12d, %eax
subl %r12d, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
cmpl %edx, %r10d
cmovael %edx, %r10d
movq %rdi, %rdx
cmovbl %r14d, %ecx
cmpl %r10d, %ebp
cmovbl %r12d, %ecx
addb -0x1(%rdi,%r11), %cl
movb %r9b, (%r8,%r11)
movb %bl, 0x1(%r8,%r11)
movb %cl, 0x2(%r8,%r11)
movl %r9d, %ebp
leaq 0x3(%r11), %r9
addq $0x5, %r11
movq -0x68(%rsp), %r14
cmpq %r14, %r11
movq %r9, %r11
jb 0x70ea7
jmp 0x70a24
movq %r10, %r9
cmpb $0x0, -0x79(%rsp)
je 0x70a24
movq -0x48(%rsp), %rax
leaq (%rsi,%rax), %r11
movl $0x2, %ebx
movq -0x58(%rsp), %rax
movzbl (%rax,%rbx), %r9d
movzbl 0x1(%rax,%rbx), %r14d
movzbl (%rsi,%rbx), %ecx
movzbl (%r11,%rbx), %edi
movl %ecx, %eax
subl %edi, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
andl %r13d, %edx
movl %r9d, %eax
subl %edi, %eax
movl %eax, %r10d
negl %r10d
cmovsl %eax, %r10d
andl %r13d, %r10d
leal (%rcx,%r9), %eax
subl %edi, %eax
subl %edi, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
movzbl 0x1(%rsi,%rbx), %r12d
cmpl %edx, %r10d
cmovael %edx, %r10d
cmovbl %ecx, %r9d
movzbl 0x1(%r11,%rbx), %ecx
cmpl %r10d, %ebp
cmovbl %edi, %r9d
movl $0xff, %ebp
movq -0x38(%rsp), %rdi
addb -0x2(%rdi,%rbx), %r9b
movl %r12d, %eax
subl %ecx, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
andl %ebp, %edx
movl %r14d, %eax
subl %ecx, %eax
movl %eax, %r10d
negl %r10d
cmovsl %eax, %r10d
andl %ebp, %r10d
leal (%r12,%r14), %eax
subl %ecx, %eax
subl %ecx, %eax
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
cmpl %edx, %r10d
cmovael %edx, %r10d
cmovbl %r12d, %r14d
cmpl %r10d, %ebp
cmovbl %ecx, %r14d
addb -0x1(%rdi,%rbx), %r14b
movl $0xff, %r13d
movq -0x40(%rsp), %rdx
movb %r9b, (%r8,%rbx)
movb %r14b, 0x1(%r8,%rbx)
movq -0x68(%rsp), %r14
leaq 0x2(%rbx), %r9
addq $0x3, %rbx
cmpq %r14, %rbx
movq %r9, %rbx
jb 0x71006
jmp 0x70a24
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq
movl $0x24, %eax
jmp 0x710f5