// File: /workspace/github_cpp_makefile_star2_O2/phillip-h[P]fractal-gen/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 + 7) / 8;
  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];

    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 $0x48, %rsp
movl %edx, %r13d
imull %r8d, %r13d
leal 0x7(%r8), %r15d
leaq 0x1(%rsi), %r8
movq %rsi, 0x18(%rsp)
movl %ecx, %ecx
movq %rdi, %r12
movq %rcx, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
xorl %edx, %edx
xorl %ebx, %ebx
shrl $0x3, %r15d
leaq 0x1(%rsi,%r15), %rsi
leaq (%rdi,%r15), %rbp
addl $0x7, %r13d
shrl $0x3, %r13d
leaq 0x1(%r13), %rax
movq %rax, 0x8(%rsp)
cmpq 0x20(%rsp), %rdx
je 0xc1bf
movq 0x18(%rsp), %rcx
imulq %rdx, %rax
movzbl (%rcx,%rax), %eax
cmpq $0x4, %rax
ja 0xc1d0
leaq 0x244b(%rip), %rcx      # 0xe434
movq %rdx, 0x28(%rsp)
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpq %rax, %r13
je 0xc086
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0xbff9
xorl %eax, %eax
testq %rbx, %rbx
je 0xc03a
cmpq %rax, %r15
je 0xc132
movb (%rbx,%rax), %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0xc016
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r15
jne 0xc02f
xorl %eax, %eax
leaq (%r15,%rax), %rcx
cmpq %r13, %rcx
jae 0xc086
movb (%r12,%rax), %cl
addb (%rsi,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
jmp 0xc041
xorl %eax, %eax
testq %rbx, %rbx
je 0xc081
cmpq %rax, %r13
je 0xc086
movb (%rbx,%rax), %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0xc061
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r13
jne 0xc076
movq 0x28(%rsp), %rdx
movq 0x8(%rsp), %rax
addq %r13, %r12
addq %r13, %rbp
movq %rdx, %rbx
imulq %r13, %rbx
addq 0x10(%rsp), %rbx
incq %rdx
addq %rax, %r8
addq %rax, %rsi
jmp 0xbfc0
xorl %eax, %eax
testq %rbx, %rbx
je 0xc0dd
cmpq %rax, %r15
je 0xc194
movb (%rbx,%rax), %cl
shrb %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0xc0b7
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r15
jne 0xc0d2
xorl %eax, %eax
leaq (%r15,%rax), %rcx
cmpq %r13, %rcx
jae 0xc086
movb (%r12,%rax), %cl
shrb %cl
addb (%rsi,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
jmp 0xc0e4
xorl %eax, %eax
cmpq %rax, %r15
je 0xc113
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0xc101
xorl %eax, %eax
leaq (%r15,%rax), %rcx
cmpq %r13, %rcx
jae 0xc086
movb (%r12,%rax), %cl
addb (%rsi,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
jmp 0xc115
leaq (%rbx,%r15), %rax
xorl %r14d, %r14d
movq %rsi, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
movq %rax, 0x30(%rsp)
leaq (%r15,%r14), %rax
cmpq %r13, %rax
jae 0xc086
movb (%rsi,%r14), %al
movzbl (%rbx,%r14), %edx
movzbl (%r12,%r14), %edi
movq %r8, %rbx
movb %al, 0x7(%rsp)
movq 0x30(%rsp), %rax
movzbl (%rax,%r14), %esi
callq 0xc37a
addb 0x7(%rsp), %al
movq %rbx, %r8
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rbx
movb %al, (%rbp,%r14)
incq %r14
jmp 0xc148
addq %r15, %rbx
xorl %eax, %eax
leaq (%r15,%rax), %rcx
cmpq %r13, %rcx
jae 0xc086
movzbl (%r12,%rax), %ecx
movzbl (%rbx,%rax), %edx
addl %ecx, %edx
shrl %edx
addb (%rsi,%rax), %dl
movb %dl, (%rbp,%rax)
incq %rax
jmp 0xc199
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x24
popq %rax
jmp 0xc1c1