// File: /workspace/github_cpp_makefile_star2_O1/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 0xf7dd
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leal 0x7(%r8), %eax
movl %eax, -0x40(%rsp)
movl %eax, %r10d
shrl $0x3, %r10d
imull %r8d, %edx
addl $0x7, %edx
movl %edx, -0x3c(%rsp)
movl %edx, %r11d
shrl $0x3, %r11d
leaq 0x1(%r11), %r14
movl %ecx, %eax
movq %rax, -0x8(%rsp)
leaq 0x1(%rsi), %rbx
movq %rsi, %rdx
movq %r11, %r9
subq %r10, %r9
leaq 0x1(%rsi,%r10), %r15
leaq (%rdi,%r10), %r12
movq %rdi, %rsi
xorl %edi, %edi
movq %rsi, %rbp
xorl %r13d, %r13d
movq %r14, %rcx
imulq %rdi, %rcx
movzbl (%rdx,%rcx), %ecx
cmpq $0x4, %rcx
ja 0xf6c3
movq %rdx, %r8
leaq 0x235b(%rip), %rdx      # 0x1181c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
movb $0x1, %r13b
cmpl $0x8, -0x3c(%rsp)
jae 0xf6d9
movq %r8, %rdx
jmp 0xf764
movl %eax, -0x44(%rsp)
testq %r13, %r13
je 0xf6f7
cmpl $0x8, -0x40(%rsp)
movq %r8, %rdx
jb 0xf50f
xorl %eax, %eax
movb (%r13,%rax), %cl
addb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xf4fb
xorl %ecx, %ecx
cmpl %r11d, %r10d
jae 0xf6d0
movq %rdi, -0x38(%rsp)
movq %r9, %rdi
movq %r14, -0x28(%rsp)
movq %r11, -0x20(%rsp)
movq %rsi, -0x30(%rsp)
movq %rdx, -0x10(%rsp)
movq %r10, -0x18(%rsp)
leaq (%r13,%r10), %r9
xorl %esi, %esi
movzbl (%rbp,%rsi), %r14d
movzbl (%r9,%rsi), %edx
movzbl (%r13,%rsi), %r11d
movl %edx, %eax
subl %r11d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl $0xff, %r8d
andl %r8d, %ecx
movl %r14d, %r10d
subl %r11d, %r10d
movl %r10d, %eax
negl %eax
cmovsl %r10d, %eax
andl %r8d, %eax
leal (%rdx,%r14), %r8d
subl %r11d, %r8d
subl %r11d, %r8d
movl %r8d, %r10d
negl %r10d
cmovsl %r8d, %r10d
cmpl %ecx, %eax
jb 0xf595
movl %r14d, %edx
movzwl %r10w, %r8d
cmpl %eax, %r8d
cmovael %edx, %r11d
cmpl %ecx, %r8d
cmovael %edx, %r11d
addb (%r15,%rsi), %r11b
movb %r11b, (%r12,%rsi)
incq %rsi
cmpq %rsi, %rdi
jne 0xf542
movq -0x10(%rsp), %rdx
movq -0x30(%rsp), %rsi
movq -0x18(%rsp), %r10
movq -0x20(%rsp), %r11
movq -0x28(%rsp), %r14
jmp 0xf672
xorl %ecx, %ecx
testq %r13, %r13
je 0xf73b
cmpl $0x8, -0x3c(%rsp)
movq %r8, %rdx
jb 0xf761
movl %eax, -0x44(%rsp)
xorl %eax, %eax
movb (%r13,%rax), %cl
addb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r11
jne 0xf5f4
jmp 0xf67a
movl %eax, -0x44(%rsp)
testq %r13, %r13
je 0xf792
cmpl $0x8, -0x40(%rsp)
movq %r8, %rdx
jb 0xf639
xorl %eax, %eax
movb (%r13,%rax), %cl
shrb %cl
addb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xf623
xorl %ecx, %ecx
cmpl %r11d, %r10d
jae 0xf6d0
movq %rdi, -0x38(%rsp)
movq %r9, %rdi
addq %r10, %r13
xorl %eax, %eax
movzbl (%rbp,%rax), %ecx
movzbl (%r13,%rax), %r8d
addl %ecx, %r8d
shrl %r8d
addb (%r15,%rax), %r8b
movb %r8b, (%r12,%rax)
incq %rax
cmpq %rax, %rdi
jne 0xf651
movq %rdi, %r9
movq -0x38(%rsp), %rdi
movl -0x44(%rsp), %eax
jmp 0xf75f
movl %eax, %r13d
cmpl $0x8, -0x40(%rsp)
jb 0xf69e
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xf68f
xorl %ecx, %ecx
cmpl %r11d, %r10d
movq %r8, %rdx
jae 0xf6f2
xorl %eax, %eax
movb (%rbp,%rax), %cl
addb (%r15,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r9
jne 0xf6aa
jmp 0xf75c
xorl %r13d, %r13d
movl $0x24, %ecx
jmp 0xf764
movl -0x44(%rsp), %eax
jmp 0xf761
movl %eax, %r13d
xorl %eax, %eax
movq %r8, %rdx
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r11
jne 0xf6e1
jmp 0xf75c
movl %r13d, %eax
jmp 0xf761
cmpl $0x8, -0x40(%rsp)
movq %r8, %rdx
jb 0xf712
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xf703
xorl %ecx, %ecx
movb $0x1, %r13b
cmpl %r11d, %r10d
jae 0xf7d7
xorl %eax, %eax
movb (%rbp,%rax), %cl
addb (%r15,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r9
jne 0xf722
jmp 0xf7cf
movb $0x1, %r13b
cmpl $0x8, -0x3c(%rsp)
movq %r8, %rdx
jb 0xf764
movl %eax, %r13d
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r11
jne 0xf74d
movl %r13d, %eax
xorl %ecx, %ecx
movb $0x1, %r13b
testb %r13b, %r13b
cmovel %ecx, %eax
je 0xf7e2
movq %rdi, %r13
imulq %r11, %r13
addq %rsi, %r13
incq %rdi
addq %r11, %rbp
addq %r14, %rbx
addq %r11, %r12
addq %r14, %r15
cmpq -0x8(%rsp), %rdi
jne 0xf4a2
jmp 0xf7e0
cmpl $0x8, -0x40(%rsp)
movq %r8, %rdx
jb 0xf7ad
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xf79e
xorl %ecx, %ecx
movb $0x1, %r13b
cmpl %r11d, %r10d
jae 0xf7d7
xorl %eax, %eax
movb (%rbp,%rax), %cl
shrb %cl
addb (%r15,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r9
jne 0xf7b9
movl -0x44(%rsp), %eax
xorl %ecx, %ecx
jmp 0xf764
movl -0x44(%rsp), %eax
jmp 0xf764
xorl %eax, %eax
retq
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq