// File: /workspace/github_cpp_makefile_star2_O1/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
movl %r8d, %ebp
movl %ecx, 0x4(%rsp)
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, 0x30(%rsp)
movl 0x10(%r9), %ecx
movl 0x14(%r9), %eax
xorl %edx, %edx
cmpq $0x6, %rcx
ja 0xb405
leaq 0x6d82(%rip), %rdx      # 0x12184
movl (%rdx,%rcx,4), %edx
imull %eax, %edx
movq 0x2a0(%rsp), %r15
leaq 0x10(%r9), %rax
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x8(%r9)
movq %rdx, 0x18(%rsp)
je 0xb5ff
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x120(%rsp), %r14
leaq 0xe0(%rsp), %rcx
leaq 0x1a0(%rsp), %rbx
movq %r14, %rdx
movq %rbx, %r8
movl 0x4(%rsp), %r9d
pushq 0x18(%rsp)
pushq %rbp
callq 0xf883
addq $0x10, %rsp
movq 0x38(%r14), %rdi
movq %rdi, (%r13)
callq 0x21e0
movq %rax, %r14
movq 0x30(%rsp), %rax
movq %r14, (%rax)
movq 0x38(%rbx), %rbx
movq %rbx, %rdi
callq 0x21e0
movq %rax, %r13
testq %rax, %rax
setne %al
testq %rbx, %rbx
sete %cl
testq %r14, %r14
movq 0x18(%rsp), %rbx
je 0xb8b3
orb %al, %cl
je 0xb8b3
movq %r15, 0x20(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x220(%rsp), %rdx
leaq 0x1e0(%rsp), %rcx
leaq 0x160(%rsp), %r8
movl 0x4(%rsp), %r9d
pushq %rbx
pushq %rbp
callq 0xf883
addq $0x10, %rsp
cmpl $0x7, %ebx
jbe 0xb691
shrl $0x3, %ebx
xorl %eax, %eax
movq %rax, 0x38(%rsp)
movl 0xa0(%rsp,%rax,4), %eax
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0xb5e8
movq 0x38(%rsp), %rax
movl 0xc0(%rsp,%rax,4), %eax
movq $0x0, 0x48(%rsp)
movq $0x0, 0x10(%rsp)
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0xb5c6
movq 0x38(%rsp), %rax
leaq 0x6a23(%rip), %rcx      # 0x11f70
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x8(%rsp)
movq 0x160(%rsp,%rax,8), %rcx
addq %r13, %rcx
movq %rcx, 0x40(%rsp)
leaq 0x6a45(%rip), %rcx      # 0x11fb0
movl (%rcx,%rax,4), %r15d
imull 0x10(%rsp), %r15d
leaq 0x6a54(%rip), %rcx      # 0x11fd0
addl (%rcx,%rax,4), %r15d
imull 0x4(%rsp), %r15d
leaq 0x6a03(%rip), %rcx      # 0x11f90
addl (%rcx,%rax,4), %r15d
movq 0x50(%rsp), %rbp
movq 0x48(%rsp), %r14
movl %r14d, %edi
imulq %rbx, %rdi
addq 0x40(%rsp), %rdi
movl %r15d, %esi
imulq %rbx, %rsi
addq %r12, %rsi
movq %rbx, %rdx
callq 0x2100
addl 0x8(%rsp), %r15d
incq %r14
decq %rbp
jne 0xb59b
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x50(%rsp), %rax
addq %rax, 0x48(%rsp)
movq %rdx, 0x10(%rsp)
cmpq 0x58(%rsp), %rdx
jne 0xb538
movq 0x38(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0xb4fb
jmp 0xb7bd
movq %r15, 0x20(%rsp)
movl %edx, %ebx
imull 0x4(%rsp), %ebx
movq %rbp, %rax
leal 0x7(%rbx), %ebp
movl %ebp, %r15d
shrl $0x3, %r15d
imull %eax, %r15d
movq %rax, 0x8(%rsp)
leal (%r15,%rax), %r14d
movq %r14, (%r13)
movq %r14, %rdi
callq 0x21e0
movq %rax, %r13
movq 0x30(%rsp), %rax
movq %r13, (%rax)
testq %r13, %r13
sete %al
testl %r14d, %r14d
setne %cl
testb %al, %cl
jne 0xb8bb
cmpl $0x7, 0x18(%rsp)
ja 0xb662
andl $-0x8, %ebp
cmpl %ebp, %ebx
jne 0xb8cd
movq %r13, %rdi
movq %r12, %rsi
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xfa4f
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movl 0xa0(%rsp,%rax,4), %eax
movl %eax, 0x40(%rsp)
testl %eax, %eax
je 0xb7ab
movq 0x10(%rsp), %rax
movl 0xc0(%rsp,%rax,4), %r10d
movl $0x0, 0x8(%rsp)
testq %r10, %r10
je 0xb797
movq 0x10(%rsp), %rax
leaq 0x68db(%rip), %rcx      # 0x11fb0
movl (%rcx,%rax,4), %ebx
movl 0x8(%rsp), %edi
imull %edi, %ebx
leaq 0x68ea(%rip), %rcx      # 0x11fd0
addl (%rcx,%rax,4), %ebx
imull 0x4(%rsp), %ebx
leaq 0x687b(%rip), %rcx      # 0x11f70
movl (%rcx,%rax,4), %r14d
movq 0x160(%rsp,%rax,8), %rdx
shlq $0x3, %rdx
movl %r10d, %esi
imull %edi, %esi
leaq 0x687e(%rip), %rcx      # 0x11f90
addl (%rcx,%rax,4), %ebx
xorl %edi, %edi
cmpl $0x0, 0x18(%rsp)
je 0xb78f
leal (%rsi,%rdi), %ebp
movq 0x18(%rsp), %rcx
imull %ecx, %ebp
addq %rdx, %rbp
movl %r14d, %eax
imull %edi, %eax
addl %ebx, %eax
imull %ecx, %eax
movl %ecx, %r9d
movl %eax, %r15d
notb %r15b
movl %ebp, %ecx
notb %cl
movq %rax, %r8
shrq $0x3, %r8
movzbl (%r12,%r8), %r8d
movzbl %r15b, %r11d
andl $0x7, %r11d
andb $0x7, %cl
movb $0x1, %r15b
shlb %cl, %r15b
btl %r11d, %r8d
jae 0xb775
movq %rbp, %rcx
shrq $0x3, %rcx
orb %r15b, (%r13,%rcx)
jmp 0xb784
notb %r15b
movq %rbp, %rcx
shrq $0x3, %rcx
andb %r15b, (%r13,%rcx)
incq %rbp
incq %rax
decl %r9d
jne 0xb73a
incq %rdi
cmpq %r10, %rdi
jne 0xb717
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
cmpl 0x40(%rsp), %eax
jne 0xb6c0
movq 0x10(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0xb693
xorl %r12d, %r12d
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %r14
cmpl $0x7, %r14d
ja 0xb85a
movq 0xe8(%rsp,%r12,2), %rdi
subq 0xe0(%rsp,%r12,2), %rdi
callq 0x21e0
movq %rax, %rbx
testq %rax, %rax
je 0xb893
movq 0x1a0(%rsp,%r12,2), %rsi
addq %r13, %rsi
movl 0x80(%rsp,%r12), %ebp
movl %ebp, %ecx
imull %r14d, %ecx
leal 0x7(%rcx), %edx
andl $-0x8, %edx
movl 0x60(%rsp,%r12), %r14d
movq %rbx, %rdi
movl %r14d, %r8d
callq 0xf98e
movq 0x30(%rsp), %rax
movq (%rax), %rdi
addq 0x120(%rsp,%r12,2), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
movq 0x18(%rsp), %r14
movq 0x28(%rsp), %r8
movq %r15, %r9
callq 0xfa4f
movl %eax, %ebp
movq %rbx, %rdi
callq 0x21b0
jmp 0xb898
movq 0x30(%rsp), %rax
movq (%rax), %rdi
addq 0x120(%rsp,%r12,2), %rdi
movq 0xe0(%rsp,%r12,2), %rsi
addq %r13, %rsi
movl 0x80(%rsp,%r12), %edx
movl 0x60(%rsp,%r12), %ecx
movq 0x28(%rsp), %r8
movq %r15, %r9
callq 0xfa4f
movl %eax, %ebp
jmp 0xb89d
movl $0x53, %ebp
testq %rbx, %rbx
je 0xb8b3
testl %ebp, %ebp
jne 0xb8b3
leaq 0x4(%r12), %rax
cmpq $0x18, %r12
movq %rax, %r12
jne 0xb7ca
movq %r13, %rdi
callq 0x21b0
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %edi
callq 0x21e0
movq %rax, %r15
testq %rax, %rax
je 0xb90f
movl %ebp, %edx
movl %ebx, %ecx
movq %r15, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rbx
movl %ebx, %r8d
callq 0xf98e
movq %r13, %rdi
movq %r15, %rsi
movl 0x4(%rsp), %edx
movl %ebx, %ecx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
callq 0xfa4f
movq %r15, %rdi
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21b0