// File: /workspace/github_cpp_makefile_star2_O1/mhe[P]raytracerframework_cpp/lodepng.cpp
// Function: preProcessScanlines(unsigned char**, unsigned long*, unsigned char const*, LodePNG_InfoPng const*)
static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in, const LodePNG_InfoPng* infoPng) /*return value is error*/
{
  /*
  This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps:
  *) if no Adam7: 1) add padding bits (= posible extra bits per scanline if bpp < 8) 2) filter
  *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter
  */
  unsigned bpp = LodePNG_InfoColor_getBpp(&infoPng->color);
  unsigned w = infoPng->width;
  unsigned h = infoPng->height;
  unsigned error = 0;
  
  if(infoPng->interlaceMethod == 0)
  {
    *outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/
    *out = (unsigned char*)malloc(*outsize);
    if(!(*out) && (*outsize)) error = 9950;

    if(!error)
    {
      if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8) /*non multiple of 8 bits per scanline, padding bits needed per scanline*/
      {
        ucvector padded;
        ucvector_init(&padded);
        if(!ucvector_resize(&padded, h * ((w * bpp + 7) / 8))) error = 9951;
        if(!error)
        {
          addPaddingBits(padded.data, in, ((w * bpp + 7) / 8) * 8, w * bpp, h);
          error = filter(*out, padded.data, w, h, &infoPng->color);
        }
        ucvector_cleanup(&padded);
      }
      else error = filter(*out, in, w, h, &infoPng->color); /*we can immediatly filter into the out buffer, no other steps needed*/
    }
  }
  else /*interlaceMethod is 1 (Adam7)*/
  {
    unsigned char* adam7 = (unsigned char*)malloc((h * w * bpp + 7) / 8);
    if(!adam7 && ((h * w * bpp + 7) / 8)) error = 9952; /*malloc failed*/
    
    while(!error) /*not a real while loop, used to break out to cleanup to avoid a goto*/
    {
      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);
      
      *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/
      *out = (unsigned char*)malloc(*outsize);
      if(!(*out) && (*outsize)) { error = 9953; break; }
      
      Adam7_interlace(adam7, in, w, h, bpp);
      
      for(i = 0; i < 7; i++)
      {
        if(bpp < 8)
        {
          ucvector padded;
          ucvector_init(&padded);
          if(!ucvector_resize(&padded, h * ((w * bpp + 7) / 8))) error = 9954;
          if(!error)
          {
            addPaddingBits(&padded.data[padded_passstart[i]], &adam7[passstart[i]], ((passw[i] * bpp + 7) / 8) * 8, passw[i] * bpp, passh[i]);
            error = filter(&(*out)[filter_passstart[i]], &padded.data[padded_passstart[i]], passw[i], passh[i], &infoPng->color);
          }
          
          ucvector_cleanup(&padded);
        }
        else
        {
          error = filter(&(*out)[filter_passstart[i]], &adam7[padded_passstart[i]], passw[i], passh[i], &infoPng->color);
        }
      }
      
      break;
    }

    free(adam7);
  }
  
  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdx, %r12
movq %rdi, -0x78(%rbp)
movl 0x18(%rcx), %edx
movl 0x1c(%rcx), %eax
xorl %r14d, %r14d
cmpq $0x6, %rdx
ja 0x20a04
leaq 0x1117c(%rip), %rdi     # 0x31b7c
movl (%rdi,%rdx,4), %r14d
imull %eax, %r14d
leaq 0x18(%rcx), %rax
movq %rax, -0x70(%rbp)
movl (%rcx), %edx
movl 0x4(%rcx), %eax
cmpl $0x0, 0x10(%rcx)
movq %rax, -0x58(%rbp)
movl %edx, -0x2c(%rbp)
je 0x20c25
movq %rsi, -0x48(%rbp)
movl %r14d, %r13d
imull %edx, %r13d
movl %r13d, %ebx
imull %eax, %ebx
addl $0x7, %ebx
movl %ebx, %edi
shrl $0x3, %edi
callq 0x5420
movq %rax, -0x60(%rbp)
testq %rax, %rax
setne %al
cmpl $0x8, %ebx
setb %cl
xorl %edx, %edx
orb %al, %cl
movl $0x26e0, %eax           # imm = 0x26E0
cmovnel %edx, %eax
je 0x20efe
movl %eax, -0x30(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x1a0(%rbp), %rbx
leaq -0x160(%rbp), %rcx
leaq -0x220(%rbp), %r8
movq %rbx, %rdx
movl -0x2c(%rbp), %r9d
pushq %r14
pushq -0x58(%rbp)
callq 0x25072
addq $0x10, %rsp
movq %r14, -0x38(%rbp)
movq 0x38(%rbx), %r14
movq -0x48(%rbp), %rax
movq %r14, (%rax)
movq %r14, %rdi
callq 0x5420
movq -0x78(%rbp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
sete %al
testq %r14, %r14
movq -0x38(%rbp), %rbx
setne %cl
testb %al, %cl
jne 0x20efe
movq %r13, -0x90(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x2a0(%rbp), %rdx
leaq -0x260(%rbp), %rcx
leaq -0x1e0(%rbp), %r8
movl -0x2c(%rbp), %r9d
pushq %rbx
movq -0x58(%rbp), %rax
pushq %rax
callq 0x25072
addq $0x10, %rsp
cmpl $0x7, %ebx
jbe 0x20cb6
movl %ebx, %r15d
shrl $0x3, %r15d
xorl %eax, %eax
movq %rax, -0x80(%rbp)
movl -0x100(%rbp,%rax,4), %eax
movq %rax, -0x98(%rbp)
testq %rax, %rax
je 0x20c0f
movq -0x80(%rbp), %rax
movl -0x120(%rbp,%rax,4), %eax
movq $0x0, -0x88(%rbp)
movq $0x0, -0x68(%rbp)
movq %rax, -0x50(%rbp)
testq %rax, %rax
je 0x20bec
movq -0x80(%rbp), %rax
leaq 0x10f89(%rip), %rcx     # 0x31b00
movl (%rcx,%rax,4), %ecx
movl %ecx, -0x48(%rbp)
movq -0x1e0(%rbp,%rax,8), %rcx
addq -0x60(%rbp), %rcx
movq %rcx, -0x40(%rbp)
leaq 0x10fac(%rip), %rcx     # 0x31b40
movl (%rcx,%rax,4), %r13d
imull -0x68(%rbp), %r13d
leaq 0x10fbc(%rip), %rcx     # 0x31b60
addl (%rcx,%rax,4), %r13d
imull -0x2c(%rbp), %r13d
leaq 0x10f6c(%rip), %rcx     # 0x31b20
addl (%rcx,%rax,4), %r13d
movq -0x50(%rbp), %rbx
movq -0x88(%rbp), %r14
movl %r14d, %edi
imulq %r15, %rdi
addq -0x40(%rbp), %rdi
movl %r13d, %esi
imulq %r15, %rsi
addq %r12, %rsi
movq %r15, %rdx
callq 0x5270
addl -0x48(%rbp), %r13d
incq %r14
decq %rbx
jne 0x20bc3
movq -0x68(%rbp), %rdx
incq %rdx
movq -0x50(%rbp), %rax
addq %rax, -0x88(%rbp)
movq %rdx, -0x68(%rbp)
cmpq -0x98(%rbp), %rdx
jne 0x20b63
movq -0x80(%rbp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x20b26
jmp 0x20ddf
movl %edx, %r13d
imull %r14d, %r13d
leal 0x7(%r13), %ecx
movl %ecx, -0x38(%rbp)
movl %ecx, %ebx
shrl $0x3, %ebx
imull %eax, %ebx
leal (%rbx,%rax), %r15d
movq %r15, (%rsi)
movq %r15, %rdi
callq 0x5420
movq %r14, %rdx
movq %rax, %r14
movq -0x78(%rbp), %rax
movq %r14, (%rax)
testq %r14, %r14
sete %al
testl %r15d, %r15d
setne %cl
testb %al, %cl
jne 0x20ca4
cmpl $0x7, %edx
movl -0x38(%rbp), %r15d
ja 0x20c7d
andl $-0x8, %r15d
cmpl %r15d, %r13d
jne 0x20f18
movq %r14, %rdi
movq %r12, %rsi
movl -0x2c(%rbp), %edx
movq -0x58(%rbp), %rcx
movq -0x70(%rbp), %r8
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x25245
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movq -0x60(%rbp), %r15
movq %rax, -0x50(%rbp)
movl -0x100(%rbp,%rax,4), %eax
movl %eax, -0x68(%rbp)
testl %eax, %eax
je 0x20dce
movq -0x50(%rbp), %rax
movl -0x120(%rbp,%rax,4), %r10d
movl $0x0, -0x40(%rbp)
testq %r10, %r10
je 0x20dbd
movq -0x50(%rbp), %rax
leaq 0x10e47(%rip), %rcx     # 0x31b40
movl (%rcx,%rax,4), %r14d
movl -0x40(%rbp), %edi
imull %edi, %r14d
leaq 0x10e55(%rip), %rcx     # 0x31b60
addl (%rcx,%rax,4), %r14d
imull -0x2c(%rbp), %r14d
leaq 0x10de5(%rip), %rcx     # 0x31b00
movl (%rcx,%rax,4), %ecx
movl %ecx, -0x48(%rbp)
movq -0x1e0(%rbp,%rax,8), %rdx
shlq $0x3, %rdx
movl %r10d, %esi
imull %edi, %esi
leaq 0x10de6(%rip), %rcx     # 0x31b20
addl (%rcx,%rax,4), %r14d
xorl %edi, %edi
cmpl $0x0, -0x38(%rbp)
je 0x20db5
leal (%rsi,%rdi), %r8d
movq -0x38(%rbp), %rax
imull %eax, %r8d
addq %rdx, %r8
movl -0x48(%rbp), %ecx
movl %ecx, %r11d
imull %edi, %r11d
addl %r14d, %r11d
imull %eax, %r11d
movl %r11d, %ebx
notb %bl
movl %r8d, %ecx
notb %cl
movq %r11, %r9
shrq $0x3, %r9
movzbl (%r12,%r9), %r9d
movzbl %bl, %r13d
andl $0x7, %r13d
andb $0x7, %cl
movb $0x1, %bl
shlb %cl, %bl
btl %r13d, %r9d
jae 0x20d9e
movq %r8, %rcx
shrq $0x3, %rcx
orb %bl, (%r15,%rcx)
jmp 0x20dab
notb %bl
movq %r8, %rcx
shrq $0x3, %rcx
andb %bl, (%r15,%rcx)
incq %r8
incq %r11
decl %eax
jne 0x20d66
incq %rdi
cmpq %r10, %rdi
jne 0x20d40
movl -0x40(%rbp), %eax
incl %eax
movl %eax, -0x40(%rbp)
cmpl -0x68(%rbp), %eax
jne 0x20ce5
movq -0x50(%rbp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x20cbc
movq -0x90(%rbp), %r13
addl $0x7, %r13d
shrl $0x3, %r13d
imull -0x58(%rbp), %r13d
leaq (,%r13,8), %rax
movq %rax, -0x40(%rbp)
xorl %r12d, %r12d
movq -0x70(%rbp), %rbx
movq -0x38(%rbp), %r14
cmpl $0x7, %r14d
ja 0x20e31
testl %r13d, %r13d
je 0x20e6c
movq -0x40(%rbp), %rdi
callq 0x5420
movq %rax, %r14
testq %rax, %rax
movl -0x30(%rbp), %eax
movl $0x26e2, %ecx           # imm = 0x26E2
cmovel %ecx, %eax
jmp 0x20e72
movq -0x78(%rbp), %rax
movq (%rax), %rdi
addq -0x1a0(%rbp,%r12,2), %rdi
movq -0x160(%rbp,%r12,2), %rsi
addq -0x60(%rbp), %rsi
movl -0xe0(%rbp,%r12), %edx
movl -0xc0(%rbp,%r12), %ecx
movq %rbx, %r8
callq 0x25245
movl %eax, -0x30(%rbp)
jmp 0x20ef0
xorl %r14d, %r14d
movl -0x30(%rbp), %eax
testl %eax, %eax
jne 0x20ee1
movq %r13, %rbx
movq -0x160(%rbp,%r12,2), %r13
addq %r14, %r13
movq -0x220(%rbp,%r12,2), %rsi
addq -0x60(%rbp), %rsi
movl -0xe0(%rbp,%r12), %eax
movl %eax, -0x48(%rbp)
movl %eax, %ecx
imull -0x38(%rbp), %ecx
leal 0x7(%rcx), %edx
andl $-0x8, %edx
movl -0xc0(%rbp,%r12), %r15d
movq %r13, %rdi
movl %r15d, %r8d
callq 0x2517b
movq -0x78(%rbp), %rax
movq (%rax), %rdi
addq -0x1a0(%rbp,%r12,2), %rdi
movq %r13, %rsi
movq %rbx, %r13
movq -0x70(%rbp), %rbx
movl -0x48(%rbp), %edx
movl %r15d, %ecx
movq %rbx, %r8
callq 0x25245
movl %eax, -0x30(%rbp)
movq %r14, %rdi
callq 0x5390
movq -0x38(%rbp), %r14
addq $0x4, %r12
cmpq $0x1c, %r12
jne 0x20e0a
movq -0x60(%rbp), %rdi
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5390
testl %ebx, %ebx
je 0x20f32
movl %ebx, %edi
shlq $0x3, %rdi
callq 0x5420
movq %rax, %rbx
testq %rax, %rax
sete %al
jmp 0x20f36
xorl %ebx, %ebx
xorl %eax, %eax
testb %al, %al
jne 0x20f67
movl %r15d, %edx
movl %r13d, %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq -0x58(%rbp), %r15
movl %r15d, %r8d
callq 0x2517b
movq %r14, %rdi
movq %rbx, %rsi
movl -0x2c(%rbp), %edx
movl %r15d, %ecx
movq -0x70(%rbp), %r8
callq 0x25245
movq %rbx, %rdi
jmp 0x20f02