// File: /workspace/github_cpp_makefile_star2_O3/mhe[P]raytracerframework_cpp/lodepng.cpp
// Function: postProcessScanlines(unsigned char*, unsigned char*, LodePNG_InfoPng const*)
static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, const LodePNG_InfoPng* infoPng) /*return value is error*/
{
  /*
  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_InfoColor_getBpp(&infoPng->color);
  unsigned w = infoPng->width;
  unsigned h = infoPng->height;
  unsigned error = 0;
  if(bpp == 0) return 31; /*error: invalid colortype*/
  
  if(infoPng->interlaceMethod == 0)
  {
    if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
    {
      error = unfilter(in, in, w, h, bpp);
      if(error) return error;
      removePaddingBits(out, in, w * bpp, ((w * bpp + 7) / 8) * 8, h);
    }
    else error = unfilter(out, in, w, h, bpp); /*we can immediatly filter into the out buffer, no other steps needed*/
  }
  else /*interlaceMethod 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++)
    {
      error = unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp);
      if(error) return error;
      if(bpp < 8) /*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*/
      {
        /*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 error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rsi, %rbx
movq %rdi, %r14
movl 0x18(%rdx), %ecx
movl 0x1c(%rdx), %eax
xorl %r15d, %r15d
cmpq $0x6, %rcx
ja 0x2344c
leaq 0xd744(%rip), %rsi      # 0x30b8c
movl (%rsi,%rcx,4), %r15d
imull %eax, %r15d
testl %r15d, %r15d
je 0x2363b
movl (%rdx), %eax
movl 0x4(%rdx), %r10d
cmpl $0x0, 0x10(%rdx)
je 0x23645
leaq -0xd0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x1d0(%rbp), %rdx
leaq -0x190(%rbp), %rcx
leaq -0x150(%rbp), %r8
movl %eax, -0x3c(%rbp)
movl %eax, %r9d
pushq %r15
movq %r10, -0x30(%rbp)
pushq %r10
callq 0x23b82
addq $0x10, %rsp
xorl %r12d, %r12d
movq -0x190(%rbp,%r12,2), %r13
addq %rbx, %r13
movq -0x1d0(%rbp,%r12,2), %rsi
addq %rbx, %rsi
movl -0xd0(%rbp,%r12), %edx
movl -0xb0(%rbp,%r12), %ecx
movq %r13, %rdi
movq %rdx, -0x48(%rbp)
movl %ecx, -0x38(%rbp)
movl %r15d, %r8d
callq 0x237ce
testl %eax, %eax
jne 0x2378c
cmpl $0x7, %r15d
ja 0x23513
movq -0x150(%rbp,%r12,2), %rdi
addq %rbx, %rdi
movq -0x48(%rbp), %rdx
imull %r15d, %edx
movl %edx, %ecx
addl $0x7, %ecx
andl $-0x8, %ecx
movq %r13, %rsi
movl -0x38(%rbp), %r8d
callq 0x23adc
addq $0x4, %r12
cmpq $0x1c, %r12
jne 0x234a6
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x250(%rbp), %rdx
leaq -0x210(%rbp), %rcx
leaq -0x110(%rbp), %r8
movl -0x3c(%rbp), %r9d
pushq %r15
pushq -0x30(%rbp)
callq 0x23b82
addq $0x10, %rsp
cmpl $0x7, %r15d
jbe 0x23688
shrl $0x3, %r15d
xorl %eax, %eax
movq %rax, -0x30(%rbp)
movl -0x70(%rbp,%rax,4), %eax
movl %eax, -0x48(%rbp)
testl %eax, %eax
je 0x23625
movq -0x30(%rbp), %rax
movl -0x90(%rbp,%rax,4), %r9d
movq $0x0, -0x38(%rbp)
xorl %r11d, %r11d
testq %r9, %r9
je 0x2360d
movq -0x30(%rbp), %rax
leaq 0xd5b7(%rip), %rcx      # 0x30b50
movl (%rcx,%rax,4), %r12d
imull %r11d, %r12d
leaq 0xd5c8(%rip), %rcx      # 0x30b70
addl (%rcx,%rax,4), %r12d
leaq 0xd55d(%rip), %rcx      # 0x30b10
movl (%rcx,%rax,4), %r13d
imull -0x3c(%rbp), %r12d
leaq 0xd56d(%rip), %rcx      # 0x30b30
addl (%rcx,%rax,4), %r12d
movq -0x110(%rbp,%rax,8), %rcx
addq %rbx, %rcx
movq -0x38(%rbp), %rax
movl %eax, %edx
xorl %esi, %esi
movl %r12d, %edi
imulq %r15, %rdi
addq %r14, %rdi
movl %edx, %r8d
imulq %r15, %r8
addq %rcx, %r8
xorl %eax, %eax
movb (%r8,%rax), %r10b
movb %r10b, (%rdi,%rax)
incq %rax
cmpq %rax, %r15
jne 0x235f0
incq %rsi
addl %r13d, %r12d
incl %edx
cmpq %r9, %rsi
jne 0x235da
incl %r11d
movq -0x38(%rbp), %rax
addl %r9d, %eax
movq %rax, -0x38(%rbp)
cmpl -0x48(%rbp), %r11d
jne 0x23589
movq -0x30(%rbp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x2355f
jmp 0x2378a
movl $0x1f, %eax
jmp 0x2378c
cmpl $0x7, %r15d
ja 0x23664
movl %eax, %r12d
imull %r15d, %r12d
leal 0x7(%r12), %r13d
andl $-0x8, %r13d
cmpl %r13d, %r12d
jne 0x2379e
movq %r14, %rdi
movq %rbx, %rsi
movl %eax, %edx
movl %r10d, %ecx
movl %r15d, %r8d
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x237ce
xorl %eax, %eax
movq %rax, -0x30(%rbp)
movl -0x70(%rbp,%rax,4), %eax
movl %eax, -0x48(%rbp)
testl %eax, %eax
je 0x23779
movq -0x30(%rbp), %rax
movl -0x90(%rbp,%rax,4), %r10d
movl $0x0, -0x38(%rbp)
testq %r10, %r10
je 0x23768
movq -0x30(%rbp), %rax
movq -0x110(%rbp,%rax,8), %r12
shlq $0x3, %r12
movl -0x38(%rbp), %esi
movl %esi, %r13d
imull %r10d, %r13d
leaq 0xd476(%rip), %rcx      # 0x30b50
movl (%rcx,%rax,4), %edx
imull %esi, %edx
leaq 0xd489(%rip), %rcx      # 0x30b70
addl (%rcx,%rax,4), %edx
imull -0x3c(%rbp), %edx
leaq 0xd41b(%rip), %rcx      # 0x30b10
movl (%rcx,%rax,4), %esi
leaq 0xd431(%rip), %rcx      # 0x30b30
addl (%rcx,%rax,4), %edx
xorl %edi, %edi
movl %esi, %r8d
imull %edi, %r8d
addl %edx, %r8d
imull %r15d, %r8d
leal (%rdi,%r13), %r11d
imull %r15d, %r11d
addq %r12, %r11
movl %r15d, %eax
movl %r11d, %ecx
notb %cl
movq %r11, %r9
shrq $0x3, %r9
movzbl (%rbx,%r9), %r9d
movzbl %cl, %ecx
andl $0x7, %ecx
btl %ecx, %r9d
jae 0x23756
movl %r8d, %ecx
notb %cl
andb $0x7, %cl
movb $0x1, %r9b
shlb %cl, %r9b
movq %r8, %rcx
shrq $0x3, %rcx
orb %r9b, (%r14,%rcx)
incq %r8
incq %r11
decl %eax
jne 0x23720
incq %rdi
cmpq %r10, %rdi
jne 0x23704
movl -0x38(%rbp), %eax
incl %eax
movl %eax, -0x38(%rbp)
cmpl -0x48(%rbp), %eax
jne 0x236b0
movq -0x30(%rbp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x2368a
xorl %eax, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %rbx, %rsi
movl %eax, %edx
movl %r10d, %ecx
movl %r15d, %r8d
movq %r10, %r15
callq 0x237ce
testl %eax, %eax
jne 0x2378c
movl %r12d, %edx
movl %r13d, %ecx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %r8d
callq 0x23adc
jmp 0x2378a