// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %edx, %r15d
movq %rdi, %r12
leal 0x7(%r8), %eax
movl %eax, 0x3c(%rsp)
movl %eax, %r9d
shrl $0x3, %r9d
imull %r8d, %r15d
addl $0x7, %r15d
shrl $0x3, %r15d
leaq 0x1(%r15), %rax
movl %ecx, %ecx
movq %rcx, 0xa0(%rsp)
leaq 0x1(%rsi), %r8
leaq 0x3(%rsi), %rcx
movq %rcx, 0x70(%rsp)
movq %r9, %rcx
negq %rcx
movq %rcx, 0x68(%rsp)
movq %rdi, %rcx
subq %r9, %rcx
movq %rcx, 0x58(%rsp)
leaq 0x4(%rsi), %rcx
movq %rcx, 0x78(%rsp)
leaq (%rdi,%r9), %r10
leaq 0x3(%r9), %rcx
movq %rcx, 0x80(%rsp)
movq %rsi, 0x98(%rsp)
addq %r9, %rsi
incq %rsi
movq %rdi, 0x90(%rsp)
xorl %edx, %edx
xorl %r14d, %r14d
movq %r15, 0x50(%rsp)
movq %r9, 0x48(%rsp)
movq %rax, 0x88(%rsp)
cmpq 0xa0(%rsp), %rdx
je 0x7d70b
imulq %rdx, %rax
movq 0x98(%rsp), %rcx
movzbl (%rcx,%rax), %eax
cmpq $0x4, %rax
ja 0x7d71f
leaq 0x133b1(%rip), %rcx     # 0x90614
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rdx, 0xb0(%rsp)
jmpq *%rax
xorl %eax, %eax
cmpq %rax, %r15
je 0x7d305
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x7d276
xorl %eax, %eax
testq %r14, %r14
je 0x7d2b8
cmpq %rax, %r9
je 0x7d3ca
movb (%r14,%rax), %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x7d293
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r9
jne 0x7d2ad
xorl %eax, %eax
leaq (%r9,%rax), %rcx
cmpq %r15, %rcx
jae 0x7d305
movb (%r12,%rax), %cl
addb (%rsi,%rax), %cl
movb %cl, (%r10,%rax)
incq %rax
jmp 0x7d2bf
xorl %eax, %eax
testq %r14, %r14
je 0x7d300
cmpq %rax, %r15
je 0x7d305
movb (%r14,%rax), %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x7d2df
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r15
jne 0x7d2f5
movq 0xb0(%rsp), %rdx
movq %rdx, %r14
imulq %r15, %r14
addq 0x90(%rsp), %r14
incq %rdx
addq %r15, %r12
movq 0x88(%rsp), %rax
addq %rax, %r8
addq %rax, 0x70(%rsp)
addq %r15, 0x58(%rsp)
addq %rax, 0x78(%rsp)
addq %r15, %r10
addq %rax, %rsi
jmp 0x7d234
xorl %eax, %eax
testq %r14, %r14
je 0x7d375
cmpq %rax, %r9
je 0x7d4fa
movb (%r14,%rax), %cl
shrb %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x7d34e
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r9
jne 0x7d36a
xorl %eax, %eax
leaq (%r9,%rax), %rcx
cmpq %r15, %rcx
jae 0x7d305
movb (%r12,%rax), %cl
shrb %cl
addb (%rsi,%rax), %cl
movb %cl, (%r10,%rax)
incq %rax
jmp 0x7d37c
xorl %eax, %eax
cmpq %rax, %r9
je 0x7d3ab
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x7d399
xorl %eax, %eax
leaq (%r9,%rax), %rcx
cmpq %r15, %rcx
jae 0x7d305
movb (%r12,%rax), %cl
addb (%rsi,%rax), %cl
movb %cl, (%r10,%rax)
incq %rax
jmp 0x7d3ad
cmpl $0x20, 0x3c(%rsp)
movq %r8, 0x40(%rsp)
movq %r10, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
jb 0x7d526
movq 0x80(%rsp), %rax
addq %r14, %rax
movq %rax, 0xa8(%rsp)
xorl %r13d, %r13d
leaq (%r9,%r13), %rax
addq $0x3, %rax
cmpq %r15, %rax
jae 0x7d600
movzbl (%r12,%r13), %edi
movzbl 0x1(%r12,%r13), %eax
movl %eax, 0x64(%rsp)
movzbl 0x2(%r12,%r13), %eax
movl %eax, 0x20(%rsp)
movzbl 0x3(%r12,%r13), %eax
movl %eax, 0x10(%rsp)
movq 0xa8(%rsp), %rax
movzbl -0x3(%rax,%r13), %esi
movzbl -0x2(%rax,%r13), %r15d
movzbl -0x1(%rax,%r13), %ecx
movl %ecx, 0x14(%rsp)
movzbl (%rax,%r13), %eax
movl %eax, 0xc(%rsp)
movzbl (%r14,%r13), %edx
movzbl 0x1(%r14,%r13), %ebp
movzbl 0x2(%r14,%r13), %ebx
movzbl 0x3(%r14,%r13), %eax
movl %eax, 0x1c(%rsp)
callq 0x7d8ca
movb %al, 0x18(%rsp)
movl 0x64(%rsp), %edi
movl %r15d, %esi
movq 0x50(%rsp), %r15
movl %ebp, %edx
callq 0x7d8ca
movl %eax, %ebp
movl 0x20(%rsp), %edi
movl 0x14(%rsp), %esi
movl %ebx, %edx
callq 0x7d8ca
movl %eax, %ebx
movl 0x10(%rsp), %edi
movl 0xc(%rsp), %esi
movl 0x1c(%rsp), %edx
callq 0x7d8ca
movq 0x48(%rsp), %r9
movq 0x28(%rsp), %rcx
movd (%rcx,%r13), %xmm0
movzbl 0x18(%rsp), %ecx
movzbl %bpl, %edx
shll $0x8, %edx
orl %ecx, %edx
movzbl %bl, %ecx
shll $0x10, %ecx
orl %edx, %ecx
movzbl %al, %eax
shll $0x18, %eax
orl %ecx, %eax
movd %eax, %xmm1
paddb %xmm0, %xmm1
movq 0x30(%rsp), %rax
movd %xmm1, (%rax,%r13)
addq $0x4, %r13
jmp 0x7d3fa
addq %r9, %r14
xorl %eax, %eax
leaq (%r9,%rax), %rcx
cmpq %r15, %rcx
jae 0x7d305
movzbl (%r12,%rax), %ecx
movzbl (%r14,%rax), %edx
addl %ecx, %edx
shrl %edx
addb (%rsi,%rax), %dl
movb %dl, (%r10,%rax)
incq %rax
jmp 0x7d4ff
cmpl $0x3, %r9d
jne 0x7d661
pushq $0x3
popq %r13
leaq 0x2(%r13), %rax
cmpq %r15, %rax
jae 0x7d612
movq 0x78(%rsp), %rax
movb -0x3(%rax,%r13), %cl
movb %cl, 0x14(%rsp)
movb -0x2(%rax,%r13), %cl
movb %cl, 0xc(%rsp)
movb -0x1(%rax,%r13), %al
movb %al, 0x10(%rsp)
movzbl -0x3(%r12,%r13), %edi
movzbl -0x2(%r12,%r13), %ebx
movzbl -0x1(%r12,%r13), %eax
movl %eax, 0x20(%rsp)
movzbl (%r14,%r13), %esi
movzbl 0x1(%r14,%r13), %r15d
movzbl 0x2(%r14,%r13), %eax
movl %eax, 0x1c(%rsp)
movzbl -0x3(%r14,%r13), %edx
movzbl -0x2(%r14,%r13), %ebp
movzbl -0x1(%r14,%r13), %eax
movl %eax, 0x18(%rsp)
callq 0x7d8ca
addb 0x14(%rsp), %al
movb %al, (%r12,%r13)
movl %ebx, %edi
movl %r15d, %esi
movq 0x50(%rsp), %r15
movl %ebp, %edx
callq 0x7d8ca
addb 0xc(%rsp), %al
movb %al, 0x1(%r12,%r13)
movl 0x20(%rsp), %edi
movl 0x1c(%rsp), %esi
movl 0x18(%rsp), %edx
callq 0x7d8ca
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %r10
movq 0x40(%rsp), %r8
movq 0x48(%rsp), %r9
addb 0x10(%rsp), %al
movb %al, 0x2(%r12,%r13)
addq $0x3, %r13
jmp 0x7d534
addq %r9, %r13
movq 0x40(%rsp), %r8
movq 0x30(%rsp), %r10
movq 0x28(%rsp), %rsi
movq 0x68(%rsp), %rax
leaq (%r14,%rax), %rbx
cmpq %r13, %r15
je 0x7d305
movb (%r8,%r13), %bpl
movq 0x58(%rsp), %rax
movzbl (%rax,%r13), %edi
movzbl (%r14,%r13), %esi
movzbl (%rbx,%r13), %edx
callq 0x7d8ca
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %r10
movq 0x40(%rsp), %r8
movq 0x48(%rsp), %r9
addb %bpl, %al
movb %al, (%r12,%r13)
incq %r13
jmp 0x7d61b
movq %r9, %r13
cmpl $0x10, 0x3c(%rsp)
jb 0x7d612
movq 0x68(%rsp), %rax
addq %r14, %rax
movq %rax, 0x20(%rsp)
pushq $0x2
popq %r13
leaq 0x1(%r13), %rax
cmpq %r15, %rax
jae 0x7d612
movq 0x70(%rsp), %rax
movb -0x2(%rax,%r13), %cl
movb %cl, 0xc(%rsp)
movb -0x1(%rax,%r13), %al
movb %al, 0x10(%rsp)
movq 0x58(%rsp), %rax
movzbl (%rax,%r13), %edi
movzbl 0x1(%rax,%r13), %ebx
movzbl (%r14,%r13), %esi
movzbl 0x1(%r14,%r13), %ebp
movq 0x20(%rsp), %rax
movzbl (%rax,%r13), %edx
movzbl 0x1(%rax,%r13), %r15d
callq 0x7d8ca
addb 0xc(%rsp), %al
movb %al, (%r12,%r13)
movl %ebx, %edi
movl %ebp, %esi
movl %r15d, %edx
movq 0x50(%rsp), %r15
callq 0x7d8ca
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %r10
movq 0x40(%rsp), %r8
movq 0x48(%rsp), %r9
addb 0x10(%rsp), %al
movb %al, 0x1(%r12,%r13)
addq $0x2, %r13
jmp 0x7d67c
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x24
popq %rax
jmp 0x7d70d