// File: /workspace/github_cpp_makefile_star2_O3/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 $0x278, %rsp            # imm = 0x278
movq %rdx, %r15
movl 0x10(%r9), %r13d
movl 0x14(%r9), %edx
movl %ecx, 0x20(%rsp)
movq %rdi, 0x40(%rsp)
movl %r8d, %ebp
movq %rsi, %r12
movq %r9, 0x48(%rsp)
xorl %eax, %eax
cmpq $0x6, %r13
ja 0xb39a
leaq 0x6e2e(%rip), %rax      # 0x121c4
movl (%rax,%r13,4), %eax
movq 0x48(%rsp), %rcx
imull %edx, %eax
movq 0x2b0(%rsp), %r14
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x8(%rcx)
je 0xb584
movl %eax, 0x8(%rsp)
movl %ebp, (%rsp)
leaq 0x130(%rsp), %r13
leaq 0x1b0(%rsp), %rbx
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0xf0(%rsp), %rcx
movl 0x20(%rsp), %r9d
movq %r13, %rdx
movq %rbx, %r8
callq 0xf45a
movq 0x38(%r13), %rdi
movq %rdi, (%r12)
callq 0x21e0
movq 0x40(%rsp), %rcx
movq %rax, %r13
movq %r13, (%rcx)
movq 0x38(%rbx), %rbx
movq %rbx, %rdi
callq 0x21e0
testq %rax, %rax
movq %rax, %r12
setne %al
testq %rbx, %rbx
movl 0x24(%rsp), %ebx
sete %cl
testq %r13, %r13
je 0xb841
orb %al, %cl
je 0xb841
movq %r14, 0x38(%rsp)
movl %ebx, 0x8(%rsp)
movl %ebp, (%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x230(%rsp), %rdx
leaq 0x1f0(%rsp), %rcx
leaq 0x170(%rsp), %r8
movl 0x20(%rsp), %r9d
callq 0xf45a
cmpl $0x7, %ebx
jbe 0xb620
movl %ebx, %r13d
shrl $0x3, %r13d
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movl 0xb0(%rsp,%rax,4), %eax
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0xb56d
movq 0x50(%rsp), %rax
movq $0x0, 0x58(%rsp)
movq $0x0, 0x28(%rsp)
movl 0xd0(%rsp,%rax,4), %eax
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0xb54b
movq 0x50(%rsp), %rax
leaq 0x6ad6(%rip), %rcx      # 0x11fb0
leaq 0x6b0f(%rip), %rdx      # 0x11ff0
movq 0x170(%rsp,%rax,8), %rsi
movl (%rcx,%rax,4), %ecx
movl (%rdx,%rax,4), %ebx
addq %r12, %rsi
movl %ecx, 0x1c(%rsp)
leaq 0x6b13(%rip), %rcx      # 0x12010
movq %rsi, 0x30(%rsp)
imull 0x28(%rsp), %ebx
movq 0x60(%rsp), %r14
movq 0x58(%rsp), %rbp
addl (%rcx,%rax,4), %ebx
leaq 0x6ab5(%rip), %rcx      # 0x11fd0
imull 0x20(%rsp), %ebx
addl (%rcx,%rax,4), %ebx
movl %ebp, %edi
imulq %r13, %rdi
addq 0x30(%rsp), %rdi
movl %ebx, %esi
imulq %r13, %rsi
movq %r13, %rdx
addq %r15, %rsi
callq 0x2100
addl 0x1c(%rsp), %ebx
incq %rbp
decq %r14
jne 0xb523
movq 0x60(%rsp), %rax
movq 0x28(%rsp), %rdx
addq %rax, 0x58(%rsp)
incq %rdx
movq %rdx, 0x28(%rsp)
cmpq 0x68(%rsp), %rdx
jne 0xb4c9
movq 0x50(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0xb48c
jmp 0xb749
movl %edx, 0x28(%rsp)
movq %r14, 0x38(%rsp)
movq %rbp, %rcx
movl %eax, %ebp
imull 0x20(%rsp), %ebp
leal 0x7(%rbp), %edx
movl %edx, %r14d
shrl $0x3, %r14d
movl %edx, 0x1c(%rsp)
movq %rcx, 0x30(%rsp)
imull %ecx, %r14d
leal (%r14,%rcx), %ebx
movq %rbx, %rdi
movq %rbx, (%r12)
callq 0x21e0
movq 0x40(%rsp), %rsi
movq %rax, %r12
testq %r12, %r12
sete %dl
testl %ebx, %ebx
setne %cl
movq %r12, (%rsi)
testb %dl, %cl
jne 0xb849
cmpl $0x7, 0x24(%rsp)
ja 0xb5f6
movl 0x1c(%rsp), %eax
andl $-0x8, %eax
movl %eax, 0x1c(%rsp)
cmpl %eax, %ebp
jne 0xb85b
movq 0x38(%rsp), %rax
movq %r12, %rdi
movq %r15, %rsi
movl %r13d, %r8d
movq %rax, (%rsp)
movl 0x20(%rsp), %edx
movl 0x28(%rsp), %r9d
movq 0x30(%rsp), %rcx
callq 0xf636
jmp 0xb849
xorl %eax, %eax
movq %rax, 0x28(%rsp)
movl 0xb0(%rsp,%rax,4), %eax
movl %eax, 0x30(%rsp)
testl %eax, %eax
je 0xb737
movq 0x28(%rsp), %rax
movl $0x0, 0x1c(%rsp)
movl 0xd0(%rsp,%rax,4), %r10d
testq %r10, %r10
je 0xb723
movq 0x28(%rsp), %rax
leaq 0x698c(%rip), %rcx      # 0x11ff0
movl 0x1c(%rsp), %edi
movl %r10d, %esi
movl (%rcx,%rax,4), %ebx
leaq 0x699b(%rip), %rcx      # 0x12010
movq 0x170(%rsp,%rax,8), %rdx
imull %edi, %esi
imull %edi, %ebx
addl (%rcx,%rax,4), %ebx
leaq 0x6923(%rip), %rcx      # 0x11fb0
shlq $0x3, %rdx
xorl %edi, %edi
imull 0x20(%rsp), %ebx
movl (%rcx,%rax,4), %r13d
leaq 0x692d(%rip), %rcx      # 0x11fd0
addl (%rcx,%rax,4), %ebx
cmpl $0x0, 0x24(%rsp)
je 0xb71b
movl 0x24(%rsp), %r14d
movl %r13d, %eax
imull %edi, %eax
leal (%rsi,%rdi), %ebp
addl %ebx, %eax
imull %r14d, %ebp
imull %r14d, %eax
addq %rdx, %rbp
movq %rax, %r8
shrq $0x3, %r8
movl %eax, %r9d
movl %ebp, %ecx
movzbl (%r15,%r8), %r8d
notb %r9b
notb %cl
movzbl %r9b, %r11d
andb $0x7, %cl
movb $0x1, %r9b
andl $0x7, %r11d
shlb %cl, %r9b
btl %r11d, %r8d
jae 0xb702
movq %rbp, %rcx
shrq $0x3, %rcx
orb %r9b, (%r12,%rcx)
jmp 0xb710
movq %rbp, %rcx
notb %r9b
shrq $0x3, %rcx
andb %r9b, (%r12,%rcx)
incq %rbp
incq %rax
decl %r14d
jne 0xb6c8
incq %rdi
cmpq %r10, %rdi
jne 0xb6a6
movl 0x1c(%rsp), %eax
incl %eax
movl %eax, 0x1c(%rsp)
cmpl 0x30(%rsp), %eax
jne 0xb64f
movq 0x28(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0xb622
movq 0x38(%rsp), %r14
movl 0x24(%rsp), %ebx
xorl %r13d, %r13d
cmpl $0x7, %ebx
ja 0xb7ec
movq 0xf8(%rsp,%r13,2), %rdi
subq 0xf0(%rsp,%r13,2), %rdi
callq 0x21e0
testq %rax, %rax
je 0xb841
movl 0x90(%rsp,%r13), %ebx
movq 0x1b0(%rsp,%r13,2), %rsi
movl 0x70(%rsp,%r13), %ebp
movq %rax, %r15
movq %rax, %rdi
movl %ebx, %ecx
imull 0x24(%rsp), %ecx
addq %r12, %rsi
movl %ebp, %r8d
leal 0x7(%rcx), %edx
andl $-0x8, %edx
callq 0xf55e
movq 0x40(%rsp), %rax
movl %ebx, %edx
movq %r15, %rsi
movl %ebp, %ecx
movq (%rax), %rdi
movq 0x48(%rsp), %rax
addq 0x130(%rsp,%r13,2), %rdi
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
movq %r14, (%rsp)
movl 0x24(%rsp), %ebx
callq 0xf636
movq %r15, %rdi
movl %eax, %ebp
callq 0x21b0
jmp 0xb82c
movq 0x40(%rsp), %rax
movq 0xf0(%rsp,%r13,2), %rsi
movl 0x90(%rsp,%r13), %edx
movl 0x70(%rsp,%r13), %ecx
movq (%rax), %rdi
movq 0x48(%rsp), %rax
addq %r12, %rsi
addq 0x130(%rsp,%r13,2), %rdi
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
movq %r14, (%rsp)
callq 0xf636
movl %eax, %ebp
testl %ebp, %ebp
jne 0xb841
leaq 0x4(%r13), %rax
cmpq $0x18, %r13
movq %rax, %r13
jne 0xb755
movq %r12, %rdi
callq 0x21b0
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %edi
callq 0x21e0
movq %rax, %rbx
testq %rax, %rax
je 0xb8a7
movq 0x30(%rsp), %r14
movl 0x1c(%rsp), %edx
movl %ebp, %ecx
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %r8d
callq 0xf55e
movq 0x38(%rsp), %rax
movq %r12, %rdi
movq %rbx, %rsi
movl %r14d, %ecx
movl %r13d, %r8d
movq %rax, (%rsp)
movl 0x20(%rsp), %edx
movl 0x28(%rsp), %r9d
callq 0xf636
movq %rbx, %rdi
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21b0