// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: postProcessScanlines
static unsigned postProcessScanlines(unsigned char* out, unsigned char* in,
                                     unsigned w, unsigned h, const LodePNGInfo* info_png)
{
  /*
  This function converts the filtered-padded-interlaced data into pure 2D image buffer with the PNG's colortype.
  Steps:
  *) if no Adam7: 1) unfilter 2) remove padding bits (= posible extra bits per scanline if bpp < 8)
  *) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace
  NOTE: the in buffer will be overwritten with intermediate data!
  */
  unsigned bpp = lodepng_get_bpp(&info_png->color);
  if(bpp == 0) return 31; /*error: invalid colortype*/

  if(info_png->interlace_method == 0)
  {
    if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
    {
      CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp));
      removePaddingBits(out, in, w * bpp, ((w * bpp + 7) / 8) * 8, h);
    }
    /*we can immediately filter into the out buffer, no other steps needed*/
    else CERROR_TRY_RETURN(unfilter(out, in, w, h, bpp));
  }
  else /*interlace_method is 1 (Adam7)*/
  {
    unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8];
    unsigned i;

    Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);

    for(i = 0; i != 7; ++i)
    {
      CERROR_TRY_RETURN(unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp));
      /*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanline,
      move bytes instead of bits or move not at all*/
      if(bpp < 8)
      {
        /*remove padding bits in scanlines; after this there still may be padding
        bits between the different reduced images: each reduced image still starts nicely at a byte*/
        removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]], passw[i] * bpp,
                          ((passw[i] * bpp + 7) / 8) * 8, passh[i]);
      }
    }

    Adam7_deinterlace(out, in, w, h, bpp);
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x28(%rbp), %rdi
addq $0x10, %rdi
callq 0x30e0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0xf15f
movl $0x1f, -0x4(%rbp)
jmp 0xf362
movq -0x28(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xf21d
cmpl $0x8, -0x2c(%rbp)
jae 0xf1eb
movl -0x1c(%rbp), %eax
imull -0x2c(%rbp), %eax
movl -0x1c(%rbp), %ecx
imull -0x2c(%rbp), %ecx
addl $0x7, %ecx
shrl $0x3, %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
je 0xf1eb
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x2c(%rbp), %r8d
callq 0xf370
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0xf1b9
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xf362
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
imull -0x2c(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
movl -0x1c(%rbp), %eax
imull -0x2c(%rbp), %eax
addl $0x7, %eax
shrl $0x3, %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %ecx
movl -0x20(%rbp), %r8d
callq 0xf470
jmp 0xf218
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x2c(%rbp), %r8d
callq 0xf370
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0xf216
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xf362
jmp 0xf218
jmp 0xf35b
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
leaq -0x130(%rbp), %r8
movl -0x1c(%rbp), %r9d
movl -0x20(%rbp), %r10d
movl -0x2c(%rbp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xf520
movl $0x0, -0x134(%rbp)
cmpl $0x7, -0x134(%rbp)
je 0xf344
movq -0x18(%rbp), %rdi
movl -0x134(%rbp), %eax
addq -0xf0(%rbp,%rax,8), %rdi
movq -0x18(%rbp), %rsi
movl -0x134(%rbp), %eax
addq -0xb0(%rbp,%rax,8), %rsi
movl -0x134(%rbp), %eax
movl -0x50(%rbp,%rax,4), %edx
movl -0x134(%rbp), %eax
movl -0x70(%rbp,%rax,4), %ecx
movl -0x2c(%rbp), %r8d
callq 0xf370
movl %eax, -0x138(%rbp)
cmpl $0x0, -0x138(%rbp)
je 0xf2c7
movl -0x138(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xf362
cmpl $0x8, -0x2c(%rbp)
jae 0xf32e
movq -0x18(%rbp), %rdi
movl -0x134(%rbp), %eax
addq -0x130(%rbp,%rax,8), %rdi
movq -0x18(%rbp), %rsi
movl -0x134(%rbp), %eax
addq -0xf0(%rbp,%rax,8), %rsi
movl -0x134(%rbp), %eax
movl -0x50(%rbp,%rax,4), %eax
imull -0x2c(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
movl -0x134(%rbp), %eax
movl -0x50(%rbp,%rax,4), %eax
imull -0x2c(%rbp), %eax
addl $0x7, %eax
shrl $0x3, %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %ecx
movl -0x134(%rbp), %eax
movl -0x70(%rbp,%rax,4), %r8d
callq 0xf470
jmp 0xf330
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0xf25c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x2c(%rbp), %r8d
callq 0xf760
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nop