// File: /workspace/github_cpp_makefile_star2_O2/phillip-h[P]fractal-gen/lodepng.cpp
// Function: preProcessScanlines(unsigned char**, unsigned long*, unsigned char const*, unsigned int, unsigned int, LodePNGInfo const*, LodePNGEncoderSettings const*)
static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in,
                                    unsigned w, unsigned h,
                                    const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings)
{
  /*
  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_get_bpp(&info_png->color);
  unsigned error = 0;

  if(info_png->interlace_method == 0)
  {
    *outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/
    *out = (unsigned char*)lodepng_malloc(*outsize);
    if(!(*out) && (*outsize)) error = 83; /*alloc fail*/

    if(!error)
    {
      /*non multiple of 8 bits per scanline, padding bits needed per scanline*/
      if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
      {
        unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7) / 8));
        if(!padded) error = 83; /*alloc fail*/
        if(!error)
        {
          addPaddingBits(padded, in, ((w * bpp + 7) / 8) * 8, w * bpp, h);
          error = filter(*out, padded, w, h, &info_png->color, settings);
        }
        lodepng_free(padded);
      }
      else
      {
        /*we can immediately filter into the out buffer, no other steps needed*/
        error = filter(*out, in, w, h, &info_png->color, settings);
      }
    }
  }
  else /*interlace_method is 1 (Adam7)*/
  {
    unsigned passw[7], passh[7];
    size_t filter_passstart[8], padded_passstart[8], passstart[8];
    unsigned char* adam7;

    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*)lodepng_malloc(*outsize);
    if(!(*out)) error = 83; /*alloc fail*/

    adam7 = (unsigned char*)lodepng_malloc(passstart[7]);
    if(!adam7 && passstart[7]) error = 83; /*alloc fail*/

    if(!error)
    {
      unsigned i;

      Adam7_interlace(adam7, in, w, h, bpp);
      for(i = 0; i != 7; ++i)
      {
        if(bpp < 8)
        {
          unsigned char* padded = (unsigned char*)lodepng_malloc(padded_passstart[i + 1] - padded_passstart[i]);
          if(!padded) ERROR_BREAK(83); /*alloc fail*/
          addPaddingBits(padded, &adam7[passstart[i]],
                         ((passw[i] * bpp + 7) / 8) * 8, passw[i] * bpp, passh[i]);
          error = filter(&(*out)[filter_passstart[i]], padded,
                         passw[i], passh[i], &info_png->color, settings);
          lodepng_free(padded);
        }
        else
        {
          error = filter(&(*out)[filter_passstart[i]], &adam7[padded_passstart[i]],
                         passw[i], passh[i], &info_png->color, settings);
        }

        if(error) break;
      }
    }

    lodepng_free(adam7);
  }

  return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq 0x2a0(%rsp), %rax
movq %rdi, %r15
leaq 0x10(%r9), %rdi
movq %r9, %r12
movl %r8d, %r14d
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %rbx
movq %rax, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
callq 0x5f6e
cmpl $0x0, 0x8(%r12)
movl %ebp, 0xc(%rsp)
movq %rax, 0x20(%rsp)
je 0xa360
leaq 0x160(%rsp), %r12
leaq 0xe0(%rsp), %rcx
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x120(%rsp), %r8
movl %ebp, %r9d
movq %r12, %rdx
pushq %rax
movq %r14, %rbp
pushq %r14
callq 0xc272
popq %rax
popq %rcx
movq 0x38(%r12), %rdi
movq %rdi, (%rbx)
callq 0x21c0
movq %rax, (%r15)
leaq 0x120(%rsp), %rcx
movq %rax, %r12
movq %r15, 0x48(%rsp)
movq 0x38(%rcx), %r14
movq %r14, %rdi
callq 0x21c0
testq %rax, %rax
movq %rax, %rbx
setne %al
testq %r14, %r14
sete %cl
testq %r12, %r12
je 0xa5ea
orb %al, %cl
je 0xa5ea
movq 0x20(%rsp), %r14
movl 0xc(%rsp), %r9d
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x220(%rsp), %rdx
leaq 0x1e0(%rsp), %rcx
leaq 0x1a0(%rsp), %r8
pushq %r14
pushq %rbp
callq 0xc272
popq %rax
popq %rcx
cmpl $0x7, %r14d
jbe 0xa3f3
movl %r14d, %eax
shrl $0x3, %eax
leaq 0x48c0(%rip), %rsi      # 0xeb70
leaq 0x4899(%rip), %rdi      # 0xeb50
leaq 0x4872(%rip), %r8       # 0xeb30
xorl %ecx, %ecx
cmpq $0x7, %rcx
je 0xa503
movl 0xa0(%rsp,%rcx,4), %edx
xorl %r10d, %r10d
movl %edx, 0x10(%rsp)
cmpl 0x10(%rsp), %r10d
je 0xa358
movl 0xc0(%rsp,%rcx,4), %r11d
xorl %r14d, %r14d
movl %r11d, %ebp
imull %r10d, %ebp
cmpq %r11, %r14
je 0xa353
movl (%rsi,%rcx,4), %r12d
movl (%r8,%rcx,4), %r9d
leaq 0x488b(%rip), %rdx      # 0xeb90
movl %ebp, %r15d
imulq %rax, %r15
addq 0x1a0(%rsp,%rcx,8), %r15
imull %r10d, %r12d
addl (%rdx,%rcx,4), %r12d
imull %r14d, %r9d
addl (%rdi,%rcx,4), %r9d
addq %rbx, %r15
imull 0xc(%rsp), %r12d
addl %r9d, %r12d
xorl %r9d, %r9d
imulq %rax, %r12
addq %r13, %r12
cmpq %r9, %rax
je 0xa34c
movb (%r12,%r9), %dl
movb %dl, (%r15,%r9)
incq %r9
jmp 0xa33a
incq %r14
incl %ebp
jmp 0xa2f1
incl %r10d
jmp 0xa2d8
incq %rcx
jmp 0xa2c0
imull %ebp, %eax
movq %r15, %rbp
movq %rax, 0x38(%rsp)
addl $0x7, %eax
movl %eax, %r15d
shrl $0x3, %r15d
movl %eax, 0x1c(%rsp)
movq %r14, 0x10(%rsp)
imull %r14d, %r15d
leal (%r15,%r14), %r12d
movq %r12, %rdi
movq %r12, (%rbx)
callq 0x21c0
testq %rax, %rax
movq %rax, %rbx
movq %rax, (%rbp)
sete %al
testl %r12d, %r12d
setne %cl
testb %al, %cl
jne 0xa5f2
cmpl $0x7, 0x20(%rsp)
movl 0x1c(%rsp), %ebp
ja 0xa3c4
andl $-0x8, %ebp
cmpl %ebp, 0x38(%rsp)
jne 0xa604
movl 0xc(%rsp), %edx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
movq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r13, %rsi
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc4d2
leaq 0x58(%rsp), %r14
xorl %esi, %esi
cmpq $0x7, %rsi
je 0xa503
movl 0xc0(%rsp,%rsi,4), %eax
movl 0xa0(%rsp,%rsi,4), %ecx
xorl %edx, %edx
movq %rax, 0x10(%rsp)
movl %ecx, 0x44(%rsp)
movl 0xc(%rsp), %ecx
movq %rsi, 0x50(%rsp)
cmpl 0x44(%rsp), %edx
je 0xa4fb
movl %edx, %eax
imull 0x10(%rsp), %eax
xorl %r15d, %r15d
movq %rax, 0x38(%rsp)
movl %edx, 0x1c(%rsp)
cmpq 0x10(%rsp), %r15
je 0xa4f4
leaq 0x471b(%rip), %rax      # 0xeb70
leaq 0x46d4(%rip), %rdi      # 0xeb30
leaq 0x472d(%rip), %r8       # 0xeb90
movl (%rax,%rsi,4), %eax
movl (%rdi,%rsi,4), %ebp
imull %edx, %eax
addl (%r8,%rsi,4), %eax
leaq 0x46d9(%rip), %rdx      # 0xeb50
imull %r15d, %ebp
addl (%rdx,%rsi,4), %ebp
movq 0x20(%rsp), %rdx
imull %ecx, %eax
movq 0x38(%rsp), %rcx
movl %edx, %r12d
addl %eax, %ebp
movq 0x1a0(%rsp,%rsi,8), %rax
imull %edx, %ebp
addl %r15d, %ecx
imull %edx, %ecx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x58(%rsp)
subl $0x1, %r12d
jb 0xa4df
movq %rbp, %rax
shrq $0x3, %rax
movl %ebp, %ecx
xorl %edx, %edx
movq %r14, %rdi
movq %rbx, %rsi
movzbl (%r13,%rax), %eax
notb %cl
movzbl %cl, %ecx
andl $0x7, %ecx
btl %ecx, %eax
setb %dl
incq %rbp
callq 0xc3dc
jmp 0xa4aa
movl 0xc(%rsp), %ecx
movq 0x50(%rsp), %rsi
movl 0x1c(%rsp), %edx
incq %r15
jmp 0xa443
incl %edx
jmp 0xa426
incq %rsi
jmp 0xa3fa
xorl %r15d, %r15d
cmpq $0x7, %r15
je 0xa5ea
cmpl $0x7, 0x20(%rsp)
ja 0xa5a6
movq 0xe8(%rsp,%r15,8), %rdi
subq 0xe0(%rsp,%r15,8), %rdi
callq 0x21c0
testq %rax, %rax
je 0xa5ea
movl 0x80(%rsp,%r15,4), %ebp
movq 0x120(%rsp,%r15,8), %rsi
movl 0x60(%rsp,%r15,4), %r12d
movq %rax, %r14
leaq 0x1(%r15), %r13
movq %rax, %rdi
movl %ebp, %ecx
imull 0x20(%rsp), %ecx
addq %rbx, %rsi
movl %r12d, %r8d
leal 0x7(%rcx), %edx
andl $-0x8, %edx
callq 0xc409
movq 0x48(%rsp), %rax
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
movq %r14, %rsi
movl %ebp, %edx
movl %r12d, %ecx
movq (%rax), %rdi
addq 0x160(%rsp,%r15,8), %rdi
callq 0xc4d2
movq %r14, %rdi
movl %eax, %ebp
callq 0x2180
movq %r13, %r15
jmp 0xa5e2
movq 0x48(%rsp), %rax
movq 0xe0(%rsp,%r15,8), %rsi
movl 0x80(%rsp,%r15,4), %edx
movl 0x60(%rsp,%r15,4), %ecx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
movq (%rax), %rdi
addq %rbx, %rsi
addq 0x160(%rsp,%r15,8), %rdi
callq 0xc4d2
incq %r15
movl %eax, %ebp
testl %ebp, %ebp
je 0xa506
movq %rbx, %rdi
callq 0x2180
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %edi
callq 0x21c0
movq 0x10(%rsp), %r12
movq %rax, %r15
testq %rax, %rax
je 0xa649
movl 0x38(%rsp), %ecx
movl %ebp, %edx
movq %r15, %rdi
movq %r13, %rsi
movl %r12d, %r8d
callq 0xc409
movl 0xc(%rsp), %edx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %ecx
callq 0xc4d2
movq %r15, %rdi
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2180