// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r13d
movq %rdi, %r12
leal 0x7(%r8), %r15d
shrl $0x3, %r15d
imull %r8d, %r13d
addl $0x7, %r13d
shrl $0x3, %r13d
leaq 0x1(%r13), %rax
movl %ecx, %ecx
movq %rcx, 0x20(%rsp)
leaq 0x1(%rsi), %r8
leaq (%rdi,%r15), %rbp
movq %rsi, 0x18(%rsp)
addq %r15, %rsi
incq %rsi
movq %rdi, 0x10(%rsp)
xorl %edx, %edx
xorl %ebx, %ebx
movq %rax, 0x8(%rsp)
cmpq 0x20(%rsp), %rdx
je 0x91e8
imulq %rdx, %rax
movq 0x18(%rsp), %rcx
movzbl (%rcx,%rax), %eax
cmpq $0x4, %rax
ja 0x91f9
leaq 0x211e(%rip), %rcx      # 0xb130
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %rdx, 0x28(%rsp)
jmpq *%rax
xorl %eax, %eax
cmpq %rax, %r13
je 0x90af
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x9022
xorl %eax, %eax
testq %rbx, %rbx
je 0x9063
cmpq %rax, %r15
je 0x915b
movb (%rbx,%rax), %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x903f
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r15
jne 0x9058
xorl %eax, %eax
leaq (%r15,%rax), %rcx
cmpq %r13, %rcx
jae 0x90af
movb (%r12,%rax), %cl
addb (%rsi,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
jmp 0x906a
xorl %eax, %eax
testq %rbx, %rbx
je 0x90aa
cmpq %rax, %r13
je 0x90af
movb (%rbx,%rax), %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x908a
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r13
jne 0x909f
movq 0x28(%rsp), %rdx
movq %rdx, %rbx
imulq %r13, %rbx
addq 0x10(%rsp), %rbx
incq %rdx
addq %r13, %r12
movq 0x8(%rsp), %rax
addq %rax, %r8
addq %r13, %rbp
addq %rax, %rsi
jmp 0x8fe9
xorl %eax, %eax
testq %rbx, %rbx
je 0x9106
cmpq %rax, %r15
je 0x91bd
movb (%rbx,%rax), %cl
shrb %cl
addb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x90e0
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %r15
jne 0x90fb
xorl %eax, %eax
leaq (%r15,%rax), %rcx
cmpq %r13, %rcx
jae 0x90af
movb (%r12,%rax), %cl
shrb %cl
addb (%rsi,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
jmp 0x910d
xorl %eax, %eax
cmpq %rax, %r15
je 0x913c
movb (%r8,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x912a
xorl %eax, %eax
leaq (%r15,%rax), %rcx
cmpq %r13, %rcx
jae 0x90af
movb (%r12,%rax), %cl
addb (%rsi,%rax), %cl
movb %cl, (%rbp,%rax)
incq %rax
jmp 0x913e
leaq (%rbx,%r15), %rax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
movq %rsi, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
leaq (%r15,%r14), %rax
cmpq %r13, %rax
jae 0x90af
movb (%rsi,%r14), %al
movb %al, 0x7(%rsp)
movzbl (%r12,%r14), %edi
movq 0x30(%rsp), %rax
movzbl (%rax,%r14), %esi
movzbl (%rbx,%r14), %edx
movq %r8, %rbx
callq 0x93a4
movq 0x40(%rsp), %rsi
movq %rbx, %r8
movq 0x38(%rsp), %rbx
addb 0x7(%rsp), %al
movb %al, (%rbp,%r14)
incq %r14
jmp 0x9171
addq %r15, %rbx
xorl %eax, %eax
leaq (%r15,%rax), %rcx
cmpq %r13, %rcx
jae 0x90af
movzbl (%r12,%rax), %ecx
movzbl (%rbx,%rax), %edx
addl %ecx, %edx
shrl %edx
addb (%rsi,%rax), %dl
movb %dl, (%rbp,%rax)
incq %rax
jmp 0x91c2
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x24
popq %rax
jmp 0x91ea