// File: /workspace/github_cpp_makefile_star2_O3/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:
testl %ecx, %ecx
je 0xf3af
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
imull %r8d, %edx
leal 0x7(%r8), %eax
leaq 0x1(%rsi), %r11
movl %ecx, %ecx
movq %rcx, -0x30(%rsp)
xorl %ecx, %ecx
movq %rdi, %r8
xorl %r12d, %r12d
movq %rsi, -0x18(%rsp)
movq %rdi, -0x20(%rsp)
movl %eax, %r9d
shrl $0x3, %r9d
movl %eax, -0x44(%rsp)
leaq 0x1(%rsi,%r9), %r14
leaq (%rdi,%r9), %r15
movq %r9, -0x40(%rsp)
addl $0x7, %edx
movl %edx, %r10d
shrl $0x3, %r10d
movl %edx, -0x34(%rsp)
movq %r10, %rbx
leaq 0x1(%r10), %rax
subq %r9, %rbx
movq %rax, -0x28(%rsp)
imulq %rcx, %rax
movzbl (%rsi,%rax), %eax
cmpq $0x4, %rax
ja 0xf3b2
leaq 0x273b(%rip), %rdx      # 0x1185c
movq %rcx, -0x10(%rsp)
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpl $0x8, -0x34(%rsp)
jb 0xf36d
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %r10
jne 0xf13c
jmp 0xf36d
testq %r12, %r12
je 0xf2dc
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xf17c
xorl %eax, %eax
movb (%r12,%rax), %cl
addb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xf168
cmpl %r10d, %edx
jae 0xf36d
movq -0x40(%rsp), %rax
xorl %r13d, %r13d
addq %r12, %rax
movq %rax, -0x8(%rsp)
movq -0x8(%rsp), %rax
movq %r10, %rdi
movzbl (%r8,%r13), %r10d
movq %rbx, %r9
movl $0xff, %ebx
movzbl (%rax,%r13), %ebp
movzbl (%r12,%r13), %eax
movl %ebp, %ecx
subl %eax, %ecx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
movl %r10d, %ecx
subl %eax, %ecx
andl %ebx, %esi
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
andl %ebx, %edx
leal (%rbp,%r10), %ebx
subl %eax, %ebx
subl %eax, %ebx
movl %ebx, %ecx
negl %ecx
cmovsl %ebx, %ecx
cmpl %esi, %edx
jb 0xf1e6
movl %r10d, %ebp
cmpl %edx, %ecx
movq %r9, %rbx
movq %rdi, %r10
cmovael %ebp, %eax
cmpl %esi, %ecx
cmovael %ebp, %eax
addb (%r14,%r13), %al
movb %al, (%r15,%r13)
incq %r13
cmpq %r13, %r9
jne 0xf195
jmp 0xf36d
testq %r12, %r12
je 0xf317
cmpl $0x8, -0x34(%rsp)
jb 0xf36d
xorl %eax, %eax
movb (%r12,%rax), %cl
addb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %r10
jne 0xf221
jmp 0xf36d
testq %r12, %r12
je 0xf332
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xf267
xorl %eax, %eax
movb (%r12,%rax), %cl
shrb %cl
addb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xf251
cmpl %r10d, %edx
jae 0xf36d
addq -0x40(%rsp), %r12
xorl %eax, %eax
movzbl (%r8,%rax), %ecx
movzbl (%r12,%rax), %edx
addl %ecx, %edx
shrl %edx
addb (%r14,%rax), %dl
movb %dl, (%r15,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xf277
jmp 0xf36d
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xf2b8
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xf2a8
cmpl %r10d, %edx
jae 0xf36d
xorl %eax, %eax
movb (%r8,%rax), %cl
addb (%r14,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xf2c3
jmp 0xf36d
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xf2fa
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xf2ea
cmpl %r10d, %edx
jae 0xf36d
xorl %eax, %eax
movb (%r8,%rax), %cl
addb (%r14,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xf301
jmp 0xf36d
cmpl $0x8, -0x34(%rsp)
jb 0xf36d
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %r10
jne 0xf320
jmp 0xf36d
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xf350
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xf340
cmpl %r10d, %edx
jae 0xf36d
xorl %eax, %eax
movb (%r8,%rax), %cl
shrb %cl
addb (%r14,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xf357
movq -0x10(%rsp), %rcx
movq -0x28(%rsp), %rax
movq -0x18(%rsp), %rsi
addq %r10, %r8
addq %r10, %r15
movq %rcx, %r12
imulq %r10, %r12
addq -0x20(%rsp), %r12
incq %rcx
addq %rax, %r11
addq %rax, %r14
cmpq -0x30(%rsp), %rcx
jne 0xf108
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq
movl $0x24, %eax
jmp 0xf3a4