// File: /workspace/github_c_makefile_star2_O1/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 0xbd47
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 (%rdi,%r10), %r15
leaq (%rsi,%r10), %r12
incq %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 0xbc2d
movq %rdx, %r8
leaq 0x2704(%rip), %rdx      # 0xe130
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
movb $0x1, %r13b
cmpl $0x8, -0x3c(%rsp)
jae 0xbc43
movq %r8, %rdx
jmp 0xbcce
movl %eax, -0x44(%rsp)
testq %r13, %r13
je 0xbc61
cmpl $0x8, -0x40(%rsp)
movq %r8, %rdx
jb 0xba7a
xorl %eax, %eax
movb (%r13,%rax), %cl
addb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xba66
xorl %ecx, %ecx
cmpl %r11d, %r10d
jae 0xbc3a
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 (%r10,%r13), %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 0xbaff
movl %r14d, %edx
movzwl %r10w, %r8d
cmpl %eax, %r8d
cmovael %edx, %r11d
cmpl %ecx, %r8d
cmovael %edx, %r11d
addb (%r12,%rsi), %r11b
movb %r11b, (%r15,%rsi)
incq %rsi
cmpq %rsi, %rdi
jne 0xbaac
movq -0x10(%rsp), %rdx
movq -0x30(%rsp), %rsi
movq -0x18(%rsp), %r10
movq -0x20(%rsp), %r11
movq -0x28(%rsp), %r14
jmp 0xbbdc
xorl %ecx, %ecx
testq %r13, %r13
je 0xbca5
cmpl $0x8, -0x3c(%rsp)
movq %r8, %rdx
jb 0xbccb
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 0xbb5e
jmp 0xbbe4
movl %eax, -0x44(%rsp)
testq %r13, %r13
je 0xbcfc
cmpl $0x8, -0x40(%rsp)
movq %r8, %rdx
jb 0xbba3
xorl %eax, %eax
movb (%r13,%rax), %cl
shrb %cl
addb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xbb8d
xorl %ecx, %ecx
cmpl %r11d, %r10d
jae 0xbc3a
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 (%r12,%rax), %r8b
movb %r8b, (%r15,%rax)
incq %rax
cmpq %rax, %rdi
jne 0xbbbb
movq %rdi, %r9
movq -0x38(%rsp), %rdi
movl -0x44(%rsp), %eax
jmp 0xbcc9
movl %eax, %r13d
cmpl $0x8, -0x40(%rsp)
jb 0xbc08
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xbbf9
xorl %ecx, %ecx
cmpl %r11d, %r10d
movq %r8, %rdx
jae 0xbc5c
xorl %eax, %eax
movb (%rbp,%rax), %cl
addb (%r12,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r9
jne 0xbc14
jmp 0xbcc6
xorl %r13d, %r13d
movl $0x24, %ecx
jmp 0xbcce
movl -0x44(%rsp), %eax
jmp 0xbccb
movl %eax, %r13d
xorl %eax, %eax
movq %r8, %rdx
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r11
jne 0xbc4b
jmp 0xbcc6
movl %r13d, %eax
jmp 0xbccb
cmpl $0x8, -0x40(%rsp)
movq %r8, %rdx
jb 0xbc7c
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xbc6d
xorl %ecx, %ecx
movb $0x1, %r13b
cmpl %r11d, %r10d
jae 0xbd41
xorl %eax, %eax
movb (%rbp,%rax), %cl
addb (%r12,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r9
jne 0xbc8c
jmp 0xbd39
movb $0x1, %r13b
cmpl $0x8, -0x3c(%rsp)
movq %r8, %rdx
jb 0xbcce
movl %eax, %r13d
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r11
jne 0xbcb7
movl %r13d, %eax
xorl %ecx, %ecx
movb $0x1, %r13b
testb %r13b, %r13b
cmovel %ecx, %eax
je 0xbd4c
movq %rdi, %r13
imulq %r11, %r13
addq %rsi, %r13
incq %rdi
addq %r11, %rbp
addq %r14, %rbx
addq %r11, %r15
addq %r14, %r12
cmpq -0x8(%rsp), %rdi
jne 0xba0d
jmp 0xbd4a
cmpl $0x8, -0x40(%rsp)
movq %r8, %rdx
jb 0xbd17
xorl %eax, %eax
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
cmpq %rax, %r10
jne 0xbd08
xorl %ecx, %ecx
movb $0x1, %r13b
cmpl %r11d, %r10d
jae 0xbd41
xorl %eax, %eax
movb (%rbp,%rax), %cl
shrb %cl
addb (%r12,%rax), %cl
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r9
jne 0xbd23
movl -0x44(%rsp), %eax
xorl %ecx, %ecx
jmp 0xbcce
movl -0x44(%rsp), %eax
jmp 0xbcce
xorl %eax, %eax
retq
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq