// File: /workspace/github_cpp_makefile_star2_O3/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
movl 0x18(%rcx), %r15d
movq %rcx, -0x80(%rbp)
movl 0x1c(%rcx), %edx
xorl %r14d, %r14d
cmpq $0x6, %r15
ja 0x1f751
leaq 0x1143f(%rip), %rax     # 0x30b8c
movl (%rax,%r15,4), %r14d
movq %rdi, -0x58(%rbp)
imull %edx, %r14d
movq -0x80(%rbp), %rax
movl (%rax), %ecx
movl 0x4(%rax), %r13d
cmpl $0x0, 0x10(%rax)
movl %ecx, -0x30(%rbp)
je 0x1f97b
movq %rsi, -0x38(%rbp)
movl %r14d, %eax
imull %ecx, %eax
movq %rax, -0x78(%rbp)
movl %eax, %ebx
imull %r13d, %ebx
addl $0x7, %ebx
movl %ebx, %edi
shrl $0x3, %edi
callq 0x4410
movq %rax, %r15
testq %rax, %rax
setne %al
cmpl $0x8, %ebx
setb %cl
xorl %edx, %edx
orb %al, %cl
movl $0x26e0, %eax           # imm = 0x26E0
cmovnel %edx, %eax
movl %eax, -0x3c(%rbp)
je 0x1fc6c
leaq -0xe0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x1a0(%rbp), %rbx
leaq -0x160(%rbp), %rcx
leaq -0x220(%rbp), %r8
movq %rbx, %rdx
movl -0x30(%rbp), %r9d
pushq %r14
pushq %r13
callq 0x23b82
addq $0x10, %rsp
movq 0x38(%rbx), %rbx
movq -0x38(%rbp), %rax
movq %rbx, (%rax)
movq %rbx, %rdi
callq 0x4410
movq -0x58(%rbp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
sete %al
testq %rbx, %rbx
setne %cl
testb %al, %cl
jne 0x1fc6c
movq %r15, -0x70(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x2a0(%rbp), %rdx
leaq -0x260(%rbp), %rcx
leaq -0x1e0(%rbp), %r8
movl -0x30(%rbp), %r9d
pushq %r14
movq %r13, -0x68(%rbp)
pushq %r13
callq 0x23b82
addq $0x10, %rsp
cmpl $0x7, %r14d
movq %r14, -0x38(%rbp)
jbe 0x1fa18
movl %r14d, %r15d
shrl $0x3, %r15d
xorl %eax, %eax
movq %rax, -0x88(%rbp)
movl -0x100(%rbp,%rax,4), %eax
movq %rax, -0x98(%rbp)
testq %rax, %rax
je 0x1f95e
movq -0x88(%rbp), %rax
movl -0x120(%rbp,%rax,4), %eax
movq $0x0, -0x90(%rbp)
movq $0x0, -0x60(%rbp)
movq %rax, -0x50(%rbp)
testq %rax, %rax
je 0x1f93b
movq -0x88(%rbp), %rax
leaq 0x11249(%rip), %rcx     # 0x30b10
movl (%rcx,%rax,4), %ecx
movl %ecx, -0x2c(%rbp)
movq -0x1e0(%rbp,%rax,8), %rcx
addq -0x70(%rbp), %rcx
movq %rcx, -0x48(%rbp)
leaq 0x1126c(%rip), %rcx     # 0x30b50
movl (%rcx,%rax,4), %r13d
imull -0x60(%rbp), %r13d
leaq 0x1127c(%rip), %rcx     # 0x30b70
addl (%rcx,%rax,4), %r13d
imull -0x30(%rbp), %r13d
leaq 0x1122c(%rip), %rcx     # 0x30b30
addl (%rcx,%rax,4), %r13d
movq -0x50(%rbp), %r14
movq -0x90(%rbp), %rbx
movl %ebx, %edi
imulq %r15, %rdi
addq -0x48(%rbp), %rdi
movl %r13d, %esi
imulq %r15, %rsi
addq %r12, %rsi
movq %r15, %rdx
callq 0x4260
addl -0x2c(%rbp), %r13d
incq %rbx
decq %r14
jne 0x1f913
movq -0x60(%rbp), %rdx
incq %rdx
movq -0x50(%rbp), %rax
addq %rax, -0x90(%rbp)
movq %rdx, -0x60(%rbp)
cmpq -0x98(%rbp), %rdx
jne 0x1f8b0
movq -0x88(%rbp), %rax
incq %rax
cmpq $0x7, %rax
movq -0x38(%rbp), %r14
jne 0x1f86d
jmp 0x1fb47
movl %edx, -0x48(%rbp)
movq %r13, %rax
movl %ecx, %r13d
imull %r14d, %r13d
leal 0x7(%r13), %ecx
movq %r14, -0x38(%rbp)
movl %ecx, -0x2c(%rbp)
movl %ecx, %r14d
shrl $0x3, %r14d
imull %eax, %r14d
movq %rax, -0x68(%rbp)
leal (%r14,%rax), %ebx
movq %rbx, (%rsi)
movq %rbx, %rdi
callq 0x4410
movq %rax, %rdi
movq -0x58(%rbp), %rax
movq %rdi, (%rax)
testq %rdi, %rdi
sete %al
testl %ebx, %ebx
setne %cl
testb %al, %cl
jne 0x1fa06
cmpl $0x7, -0x38(%rbp)
movl -0x2c(%rbp), %ebx
ja 0x1f9df
andl $-0x8, %ebx
cmpl %ebx, %r13d
jne 0x1fc85
movq %r12, %rsi
movl -0x30(%rbp), %edx
movq -0x68(%rbp), %rcx
movl %r15d, %r8d
movl -0x48(%rbp), %r9d
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x23d6a
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movq -0x70(%rbp), %r15
movq %rax, -0x50(%rbp)
movl -0x100(%rbp,%rax,4), %eax
movl %eax, -0x60(%rbp)
testl %eax, %eax
je 0x1fb36
movq -0x50(%rbp), %rax
movl -0x120(%rbp,%rax,4), %r10d
movl $0x0, -0x48(%rbp)
testq %r10, %r10
je 0x1fb25
movq -0x50(%rbp), %rax
leaq 0x110f5(%rip), %rcx     # 0x30b50
movl (%rcx,%rax,4), %ebx
movl -0x48(%rbp), %edi
imull %edi, %ebx
leaq 0x11105(%rip), %rcx     # 0x30b70
addl (%rcx,%rax,4), %ebx
imull -0x30(%rbp), %ebx
leaq 0x11097(%rip), %rcx     # 0x30b10
movl (%rcx,%rax,4), %ecx
movl %ecx, -0x2c(%rbp)
movq -0x1e0(%rbp,%rax,8), %rdx
shlq $0x3, %rdx
movl %r10d, %esi
imull %edi, %esi
leaq 0x11098(%rip), %rcx     # 0x30b30
addl (%rcx,%rax,4), %ebx
xorl %edi, %edi
testl %r14d, %r14d
je 0x1fb15
leal (%rsi,%rdi), %r8d
movq -0x38(%rbp), %rax
imull %eax, %r8d
addq %rdx, %r8
movl -0x2c(%rbp), %ecx
movl %ecx, %r11d
imull %edi, %r11d
addl %ebx, %r11d
imull %eax, %r11d
movl %r11d, %r14d
notb %r14b
movl %r8d, %ecx
notb %cl
movq %r11, %r9
shrq $0x3, %r9
movzbl (%r12,%r9), %r9d
movzbl %r14b, %r13d
andl $0x7, %r13d
andb $0x7, %cl
movb $0x1, %r14b
shlb %cl, %r14b
btl %r13d, %r9d
jae 0x1fafd
movq %r8, %rcx
shrq $0x3, %rcx
orb %r14b, (%r15,%rcx)
jmp 0x1fb0b
notb %r14b
movq %r8, %rcx
shrq $0x3, %rcx
andb %r14b, (%r15,%rcx)
incq %r8
incq %r11
decl %eax
jne 0x1fac2
incq %rdi
cmpq %r10, %rdi
movq -0x38(%rbp), %r14
jne 0x1fa9d
movl -0x48(%rbp), %eax
incl %eax
movl %eax, -0x48(%rbp)
cmpl -0x60(%rbp), %eax
jne 0x1fa47
movq -0x50(%rbp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x1fa1e
movq -0x78(%rbp), %rax
addl $0x7, %eax
shrl $0x3, %eax
imull -0x68(%rbp), %eax
movq %rax, -0x78(%rbp)
leaq (,%rax,8), %rax
movq %rax, -0x38(%rbp)
xorl %r12d, %r12d
movq -0x58(%rbp), %r13
movq -0x70(%rbp), %r15
cmpl $0x7, %r14d
ja 0x1fb9b
cmpl $0x0, -0x78(%rbp)
je 0x1fbdb
movq -0x38(%rbp), %rdi
callq 0x4410
movq %rax, %rbx
testq %rax, %rax
jne 0x1fbdd
movl $0x26e2, -0x3c(%rbp)    # imm = 0x26E2
xorl %ebx, %ebx
jmp 0x1fc56
movq (%r13), %rdi
addq -0x1a0(%rbp,%r12,2), %rdi
movq -0x160(%rbp,%r12,2), %rsi
addq %r15, %rsi
movl -0xe0(%rbp,%r12), %edx
movl -0xc0(%rbp,%r12), %ecx
movq -0x80(%rbp), %rax
movl 0x18(%rax), %r8d
movl 0x1c(%rax), %r9d
callq 0x23d6a
movl %eax, -0x3c(%rbp)
jmp 0x1fc5e
xorl %ebx, %ebx
cmpl $0x0, -0x3c(%rbp)
jne 0x1fc56
movq -0x160(%rbp,%r12,2), %r13
addq %rbx, %r13
movq -0x220(%rbp,%r12,2), %rsi
addq %r15, %rsi
movl -0xe0(%rbp,%r12), %r15d
movl %r15d, %ecx
imull %r14d, %ecx
leal 0x7(%rcx), %edx
andl $-0x8, %edx
movl -0xc0(%rbp,%r12), %r8d
movl %r8d, -0x2c(%rbp)
movq %r13, %rdi
callq 0x23c8a
movq -0x58(%rbp), %rax
movq (%rax), %rdi
addq -0x1a0(%rbp,%r12,2), %rdi
movq -0x80(%rbp), %rax
movl 0x18(%rax), %r8d
movl 0x1c(%rax), %r9d
movq %r13, %rsi
movq -0x58(%rbp), %r13
movl %r15d, %edx
movq -0x70(%rbp), %r15
movl -0x2c(%rbp), %ecx
callq 0x23d6a
movl %eax, -0x3c(%rbp)
movq %rbx, %rdi
callq 0x4380
addq $0x4, %r12
cmpq $0x1c, %r12
jne 0x1fb70
movq %r15, %rdi
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4380
movq %rdi, -0x38(%rbp)
testl %r14d, %r14d
je 0x1fca7
movl %r14d, %edi
shlq $0x3, %rdi
callq 0x4410
movq %rax, %r14
testq %rax, %rax
jne 0x1fcaa
xorl %r14d, %r14d
jmp 0x1fcd9
xorl %r14d, %r14d
movl %ebx, %edx
movl %r13d, %ecx
movq %r14, %rdi
movq %r12, %rsi
movq -0x68(%rbp), %rbx
movl %ebx, %r8d
callq 0x23c8a
movq -0x38(%rbp), %rdi
movq %r14, %rsi
movl -0x30(%rbp), %edx
movl %ebx, %ecx
movl %r15d, %r8d
movl -0x48(%rbp), %r9d
callq 0x23d6a
movq %r14, %rdi
jmp 0x1fc6f