// File: /workspace/github_c_makefile_star2_O3/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: unfilter
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 0xc0e8
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leal 0x7(%r8), %eax
movl %eax, -0x44(%rsp)
movl %eax, %r9d
shrl $0x3, %r9d
imull %r8d, %edx
addl $0x7, %edx
movl %edx, -0x34(%rsp)
movl %edx, %r10d
shrl $0x3, %r10d
leaq 0x1(%r10), %rax
movl %ecx, %ecx
movq %rcx, -0x30(%rsp)
leaq 0x1(%rsi), %r11
movq %r10, %rbx
subq %r9, %rbx
leaq (%rdi,%r9), %r14
movq %r9, -0x40(%rsp)
leaq (%rsi,%r9), %r15
incq %r15
xorl %ecx, %ecx
movq %rdi, %r8
xorl %r12d, %r12d
movq %rsi, -0x18(%rsp)
movq %rdi, -0x20(%rsp)
movq %rax, -0x28(%rsp)
imulq %rcx, %rax
movzbl (%rsi,%rax), %eax
cmpq $0x4, %rax
ja 0xc0eb
leaq 0x23b5(%rip), %rdx      # 0xe210
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
movq %rcx, -0x10(%rsp)
jmpq *%rax
cmpl $0x8, -0x34(%rsp)
jb 0xc0a6
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %r10
jne 0xbe76
jmp 0xc0a6
testq %r12, %r12
je 0xc015
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xbeb6
xorl %eax, %eax
movb (%r12,%rax), %cl
addb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xbea2
cmpl %r10d, %edx
jae 0xc0a6
movq -0x40(%rsp), %rax
addq %r12, %rax
movq %rax, -0x8(%rsp)
xorl %r13d, %r13d
movq %rbx, %r9
movq %r10, %rdi
movzbl (%r8,%r13), %r10d
movq -0x8(%rsp), %rax
movzbl (%rax,%r13), %ebp
movzbl (%r12,%r13), %eax
movl %ebp, %ecx
subl %eax, %ecx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
movl $0xff, %ebx
andl %ebx, %esi
movl %r10d, %ecx
subl %eax, %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
andl %ebx, %edx
leal (%r10,%rbp), %ebx
subl %eax, %ebx
subl %eax, %ebx
movl %ebx, %ecx
negl %ecx
cmovsl %ebx, %ecx
cmpl %esi, %edx
jb 0xbf1f
movl %r10d, %ebp
cmpl %edx, %ecx
cmovael %ebp, %eax
cmpl %esi, %ecx
cmovael %ebp, %eax
addb (%r15,%r13), %al
movb %al, (%r14,%r13)
incq %r13
movq %r9, %rbx
cmpq %r13, %r9
movq %rdi, %r10
jne 0xbecf
jmp 0xc0a6
testq %r12, %r12
je 0xc050
cmpl $0x8, -0x34(%rsp)
jb 0xc0a6
xorl %eax, %eax
movb (%r12,%rax), %cl
addb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %r10
jne 0xbf5a
jmp 0xc0a6
testq %r12, %r12
je 0xc06b
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xbfa0
xorl %eax, %eax
movb (%r12,%rax), %cl
shrb %cl
addb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xbf8a
cmpl %r10d, %edx
jae 0xc0a6
addq -0x40(%rsp), %r12
xorl %eax, %eax
movzbl (%r8,%rax), %ecx
movzbl (%r12,%rax), %edx
addl %ecx, %edx
shrl %edx
addb (%r15,%rax), %dl
movb %dl, (%r14,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xbfb0
jmp 0xc0a6
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xbff1
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xbfe1
cmpl %r10d, %edx
jae 0xc0a6
xorl %eax, %eax
movb (%r8,%rax), %cl
addb (%r15,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xbffc
jmp 0xc0a6
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xc033
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xc023
cmpl %r10d, %edx
jae 0xc0a6
xorl %eax, %eax
movb (%r8,%rax), %cl
addb (%r15,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xc03a
jmp 0xc0a6
cmpl $0x8, -0x34(%rsp)
jb 0xc0a6
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %r10
jne 0xc059
jmp 0xc0a6
cmpl $0x8, -0x44(%rsp)
movq -0x40(%rsp), %rdx
jb 0xc089
xorl %eax, %eax
movb (%r11,%rax), %cl
movb %cl, (%r8,%rax)
incq %rax
cmpq %rax, %rdx
jne 0xc079
cmpl %r10d, %edx
jae 0xc0a6
xorl %eax, %eax
movb (%r8,%rax), %cl
shrb %cl
addb (%r15,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rbx
jne 0xc090
movq -0x10(%rsp), %rcx
movq %rcx, %r12
imulq %r10, %r12
addq -0x20(%rsp), %r12
incq %rcx
addq %r10, %r8
movq -0x28(%rsp), %rax
addq %rax, %r11
addq %r10, %r14
addq %rax, %r15
cmpq -0x30(%rsp), %rcx
movq -0x18(%rsp), %rsi
jne 0xbe42
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq
movl $0x24, %eax
jmp 0xc0dd