// File: /workspace/github_cpp_makefile_star2_O3/drummyfish[P]flowchart/src/lodepng.cpp
// Function: postProcessScanlines(unsigned char*, unsigned char*, unsigned int, unsigned int, LodePNGInfo const*)
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 immediatly 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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movl %ecx, %r13d
movl %edx, (%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movl 0x10(%r8), %ecx
movl 0x14(%r8), %eax
xorl %r15d, %r15d
cmpq $0x6, %rcx
ja 0xcabd
leaq 0x5bc3(%rip), %rdx      # 0x1267c
movl (%rdx,%rcx,4), %r15d
imull %eax, %r15d
testl %r15d, %r15d
je 0xcc92
cmpl $0x0, 0x8(%r8)
je 0xcc9c
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x150(%rsp), %rdx
leaq 0x110(%rsp), %rcx
leaq 0xd0(%rsp), %r8
movl (%rsp), %r9d
pushq %r15
movq %r13, 0x10(%rsp)
pushq %r13
callq 0xd1d4
addq $0x10, %rsp
movq $-0x1, %r12
movq 0x118(%rsp,%r12,8), %r13
addq %rbx, %r13
movq 0x158(%rsp,%r12,8), %rsi
addq %rbx, %rsi
movl 0x74(%rsp,%r12,4), %ebp
movl 0x54(%rsp,%r12,4), %ecx
movq %r13, %rdi
movl %ebp, %edx
movl %ecx, 0x4(%rsp)
movl %r15d, %r8d
callq 0xce14
testl %eax, %eax
jne 0xcdd5
cmpl $0x7, %r15d
ja 0xcb7a
movq 0xd8(%rsp,%r12,8), %rdi
addq %rbx, %rdi
imull %r15d, %ebp
movl %ebp, %ecx
addl $0x7, %ecx
andl $-0x8, %ecx
movq %r13, %rsi
movq %rbp, %rdx
movl 0x4(%rsp), %r8d
callq 0xd133
incq %r12
cmpq $0x6, %r12
jne 0xcb14
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x1d0(%rsp), %rdx
leaq 0x190(%rsp), %rcx
leaq 0x90(%rsp), %r8
movl (%rsp), %r9d
pushq %r15
pushq 0x10(%rsp)
callq 0xd1d4
addq $0x10, %rsp
cmpl $0x7, %r15d
jbe 0xccdc
shrl $0x3, %r15d
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movl 0x10(%rsp,%rax,4), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0xcc7b
movq 0x8(%rsp), %rax
movl 0x30(%rsp,%rax,4), %r9d
xorl %r10d, %r10d
xorl %r11d, %r11d
testq %r9, %r9
je 0xcc6a
movq 0x8(%rsp), %rax
leaq 0x58e2(%rip), %rcx      # 0x124e0
movl (%rcx,%rax,4), %ebp
imull %r11d, %ebp
leaq 0x58f4(%rip), %rcx      # 0x12500
addl (%rcx,%rax,4), %ebp
leaq 0x588a(%rip), %rcx      # 0x124a0
movl (%rcx,%rax,4), %r12d
imull (%rsp), %ebp
leaq 0x589b(%rip), %rcx      # 0x124c0
addl (%rcx,%rax,4), %ebp
movq 0x90(%rsp,%rax,8), %r13
addq %rbx, %r13
movl %r10d, %ecx
xorl %edx, %edx
movl %ebp, %esi
imulq %r15, %rsi
addq %r14, %rsi
movl %ecx, %edi
imulq %r15, %rdi
addq %r13, %rdi
xorl %r8d, %r8d
movb (%rdi,%r8), %al
movb %al, (%rsi,%r8)
incq %r8
cmpq %r8, %r15
jne 0xcc4d
incq %rdx
addl %r12d, %ebp
incl %ecx
cmpq %r9, %rdx
jne 0xcc38
incl %r11d
addl %r9d, %r10d
cmpl 0x4(%rsp), %r11d
jne 0xcbed
movq 0x8(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0xcbc8
jmp 0xcdd3
movl $0x1f, %eax
jmp 0xcdd5
cmpl $0x7, %r15d
ja 0xccbb
movl %r15d, %r12d
imull (%rsp), %r12d
leal 0x7(%r12), %ebp
andl $-0x8, %ebp
cmpl %ebp, %r12d
jne 0xcde7
movq %r14, %rdi
movq %rbx, %rsi
movl (%rsp), %edx
movl %r13d, %ecx
movl %r15d, %r8d
callq 0xce14
testl %eax, %eax
jne 0xcdd5
jmp 0xcdd3
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movl 0x10(%rsp,%rax,4), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0xcdc1
movq 0x8(%rsp), %rax
movl 0x30(%rsp,%rax,4), %r10d
xorl %r11d, %r11d
testq %r10, %r10
je 0xcdb3
movq 0x8(%rsp), %rax
movq 0x90(%rsp,%rax,8), %r12
shlq $0x3, %r12
movl %r11d, %r13d
imull %r10d, %r13d
leaq 0x57b8(%rip), %rcx      # 0x124e0
movl (%rcx,%rax,4), %ebp
imull %r11d, %ebp
leaq 0x57ca(%rip), %rcx      # 0x12500
addl (%rcx,%rax,4), %ebp
imull (%rsp), %ebp
leaq 0x575c(%rip), %rcx      # 0x124a0
movl (%rcx,%rax,4), %edx
leaq 0x5772(%rip), %rcx      # 0x124c0
addl (%rcx,%rax,4), %ebp
xorl %esi, %esi
movl %edx, %edi
imull %esi, %edi
addl %ebp, %edi
imull %r15d, %edi
leal (%rsi,%r13), %eax
imull %r15d, %eax
addq %r12, %rax
movl %r15d, %r9d
movl %eax, %ecx
notb %cl
movq %rax, %r8
shrq $0x3, %r8
movzbl (%rbx,%r8), %r8d
movzbl %cl, %ecx
andl $0x7, %ecx
btl %ecx, %r8d
jae 0xcda0
movl %edi, %ecx
notb %cl
andb $0x7, %cl
movb $0x1, %r8b
shlb %cl, %r8b
movq %rdi, %rcx
shrq $0x3, %rcx
orb %r8b, (%r14,%rcx)
incq %rdi
incq %rax
decl %r9d
jne 0xcd6c
incq %rsi
cmpq %r10, %rsi
jne 0xcd53
incl %r11d
cmpl 0x4(%rsp), %r11d
jne 0xcd00
movq 0x8(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0xccde
xorl %eax, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %rbx, %rsi
movl (%rsp), %edx
movl %r13d, %ecx
movl %r15d, %r8d
callq 0xce14
testl %eax, %eax
jne 0xcdd5
movl %r12d, %edx
movl %ebp, %ecx
movq %r14, %rdi
movq %rbx, %rsi
movl %r13d, %r8d
callq 0xd133
jmp 0xcdd3