// File: /workspace/github_cpp_makefile_star2_O2/drummyfish[P]flowchart/src/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*)mymalloc(*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)
      {
        ucvector padded;
        ucvector_init(&padded);
        if(!ucvector_resize(&padded, h * ((w * bpp + 7) / 8))) error = 83; /*alloc fail*/
        if(!error)
        {
          addPaddingBits(padded.data, in, ((w * bpp + 7) / 8) * 8, w * bpp, h);
          error = filter(*out, padded.data, w, h, &info_png->color, settings);
        }
        ucvector_cleanup(&padded);
      }
      else
      {
        /*we can immediatly 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 char* adam7 = (unsigned char*)mymalloc((h * w * bpp + 7) / 8);
    if(!adam7 && ((h * w * bpp + 7) / 8)) error = 83; /*alloc fail*/

    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*)mymalloc(*outsize);
      if(!(*out) && (*outsize)) ERROR_BREAK(83 /*alloc fail*/);

      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 = 83; /*alloc fail*/
          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], &info_png->color, settings);
          }

          ucvector_cleanup(&padded);
        }
        else
        {
          error = filter(&(*out)[filter_passstart[i]], &adam7[padded_passstart[i]],
                         passw[i], passh[i], &info_png->color, settings);
        }
      }

      break;
    }

    myfree(adam7);
  }

  return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %r9, %r14
movl %r8d, %r13d
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x2b0(%rsp), %r12
leaq 0x10(%r9), %rbp
movq %rbp, %rdi
callq 0x45e2
movq %rax, 0x20(%rsp)
movl %ebx, 0xc(%rsp)
imull %ebx, %eax
cmpl $0x0, 0x8(%r14)
movq %rbp, 0x48(%rsp)
movq %rax, 0x30(%rsp)
je 0x83c1
movq %r12, %r14
movl %eax, %ebx
imull %r13d, %ebx
addl $0x7, %ebx
movl %ebx, %edi
shrl $0x3, %edi
callq 0x2260
movq %rax, %rbp
testq %rax, %rax
setne %al
cmpl $0x8, %ebx
setb %cl
xorl %edx, %edx
orb %al, %cl
pushq $0x53
popq %rax
cmovel %eax, %edx
movl %edx, 0x3c(%rsp)
je 0x868d
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x170(%rsp), %r12
leaq 0x130(%rsp), %rcx
leaq 0x1f0(%rsp), %r8
movq %r12, %rdx
movl 0xc(%rsp), %ebx
movl %ebx, %r9d
pushq 0x20(%rsp)
pushq %r13
callq 0xa2c4
popq %rax
popq %rcx
movq %r14, 0x28(%rsp)
movq 0x38(%r12), %r12
movq 0x10(%rsp), %rax
movq %r12, (%rax)
movq %r12, %rdi
callq 0x2260
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
sete %al
testq %r12, %r12
setne %cl
testb %al, %cl
jne 0x868d
leaq 0x110(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x230(%rsp), %rcx
leaq 0x1b0(%rsp), %r8
movl %ebx, %r9d
movq 0x20(%rsp), %r14
pushq %r14
movq %r13, 0x48(%rsp)
pushq %r13
callq 0xa2c4
popq %rax
popq %rcx
cmpl $0x7, %r14d
jbe 0x844a
movl %r14d, %eax
shrl $0x3, %eax
xorl %ecx, %ecx
leaq 0x6121(%rip), %rsi      # 0xe430
leaq 0x60fa(%rip), %rdi      # 0xe410
leaq 0x60d3(%rip), %r8       # 0xe3f0
cmpq $0x7, %rcx
je 0x8556
movl 0xf0(%rsp,%rcx,4), %edx
movl %edx, 0x10(%rsp)
xorl %r10d, %r10d
cmpl 0x10(%rsp), %r10d
je 0x83b9
movl 0x110(%rsp,%rcx,4), %r11d
movl %r11d, %ebx
imull %r10d, %ebx
xorl %r14d, %r14d
cmpq %r11, %r14
je 0x83b1
movl %ebx, %r12d
imulq %rax, %r12
addq 0x1b0(%rsp,%rcx,8), %r12
addq %rbp, %r12
movl (%r8,%rcx,4), %r9d
imull %r14d, %r9d
addl (%rdi,%rcx,4), %r9d
movl (%rsi,%rcx,4), %r13d
imull %r10d, %r13d
leaq 0x60d0(%rip), %rdx      # 0xe450
addl (%rdx,%rcx,4), %r13d
imull 0xc(%rsp), %r13d
addl %r9d, %r13d
imulq %rax, %r13
addq %r15, %r13
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x83aa
movb (%r13,%r9), %dl
movb %dl, (%r12,%r9)
incq %r9
jmp 0x8397
incq %r14
incl %ebx
jmp 0x834e
incl %r10d
jmp 0x8335
incq %rcx
jmp 0x831d
movq %r12, 0x28(%rsp)
leal 0x7(%rax), %ebp
movl %ebp, %ebx
shrl $0x3, %ebx
imull %r13d, %ebx
movq %r13, 0x40(%rsp)
leal (%rbx,%r13), %r14d
movq 0x10(%rsp), %rax
movq %r14, (%rax)
movq %r14, %rdi
callq 0x2260
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
sete %cl
testl %r14d, %r14d
setne %dl
testb %cl, %dl
jne 0x8709
cmpl $0x7, 0x20(%rsp)
ja 0x841b
andl $-0x8, %ebp
cmpl %ebp, 0x30(%rsp)
jne 0x86a6
movq %rax, %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x28(%rsp), %r9
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa5df
xorl %eax, %eax
leaq 0x68(%rsp), %r12
cmpq $0x7, %rax
je 0x8556
movl 0x110(%rsp,%rax,4), %ecx
movq %rcx, 0x10(%rsp)
movl 0xf0(%rsp,%rax,4), %ecx
movl %ecx, 0x50(%rsp)
xorl %ecx, %ecx
movq %rax, 0x58(%rsp)
cmpl 0x50(%rsp), %ecx
je 0x854e
movl %ecx, %eax
imull 0x10(%rsp), %eax
movq %rax, 0x60(%rsp)
xorl %r13d, %r13d
movl %ecx, 0x54(%rsp)
cmpq 0x10(%rsp), %r13
je 0x8542
movq 0x58(%rsp), %rdx
leaq 0x5f83(%rip), %rax      # 0xe430
movl (%rax,%rdx,4), %eax
imull %ecx, %eax
leaq 0x5f96(%rip), %rcx      # 0xe450
addl (%rcx,%rdx,4), %eax
imull 0xc(%rsp), %eax
leaq 0x5f27(%rip), %rcx      # 0xe3f0
movl (%rcx,%rdx,4), %ebx
imull %r13d, %ebx
leaq 0x5f39(%rip), %rcx      # 0xe410
addl (%rcx,%rdx,4), %ebx
movq 0x60(%rsp), %rcx
addl %r13d, %ecx
addl %eax, %ebx
imull %r14d, %ebx
movq 0x1b0(%rsp,%rdx,8), %rax
imull %r14d, %ecx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x68(%rsp)
subl $0x1, %r14d
jb 0x8531
movq %rbx, %rax
shrq $0x3, %rax
movl %ebx, %ecx
notb %cl
movzbl (%r15,%rax), %eax
movzbl %cl, %ecx
andl $0x7, %ecx
xorl %edx, %edx
btl %ecx, %eax
setb %dl
incq %rbx
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa42d
jmp 0x84fd
incq %r13
movq 0x20(%rsp), %r14
movl 0x54(%rsp), %ecx
jmp 0x8496
incl %ecx
movq 0x58(%rsp), %rax
jmp 0x8479
incq %rax
jmp 0x8451
movq 0x30(%rsp), %rax
addl $0x7, %eax
shrl $0x3, %eax
imull 0x40(%rsp), %eax
movq %rax, 0x30(%rsp)
xorl %ebx, %ebx
leaq 0x70(%rsp), %r15
movq 0x28(%rsp), %r14
movq 0x48(%rsp), %r12
movq 0x18(%rsp), %rax
cmpq $0x1c, %rbx
je 0x868d
cmpl $0x7, 0x20(%rsp)
ja 0x8643
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
movq %r15, %rdi
movq 0x30(%rsp), %rsi
callq 0x925a
testl %eax, %eax
pushq $0x53
popq %rax
movl 0x3c(%rsp), %r13d
cmovel %eax, %r13d
testl %r13d, %r13d
jne 0x8639
movq 0x70(%rsp), %r14
addq 0x130(%rsp,%rbx,2), %r14
movq 0x1f0(%rsp,%rbx,2), %rsi
addq %rbp, %rsi
movl 0xd0(%rsp,%rbx), %r13d
movl %r13d, %ecx
imull 0x20(%rsp), %ecx
leal 0x7(%rcx), %edx
andl $-0x8, %edx
movl 0xb0(%rsp,%rbx), %r12d
movq %r14, %rdi
movl %r12d, %r8d
callq 0xa516
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq 0x170(%rsp,%rbx,2), %rdi
movq %r14, %rsi
movl %r13d, %edx
movl %r12d, %ecx
movq 0x48(%rsp), %r12
movq 0x28(%rsp), %r14
movq %r12, %r8
movq %r14, %r9
callq 0xa5df
movl %eax, %r13d
movq %r15, %rdi
callq 0x9fa4
jmp 0x8675
movq (%rax), %rdi
addq 0x170(%rsp,%rbx,2), %rdi
movq 0x130(%rsp,%rbx,2), %rsi
addq %rbp, %rsi
movl 0xd0(%rsp,%rbx), %edx
movl 0xb0(%rsp,%rbx), %ecx
movq %r12, %r8
movq %r14, %r9
callq 0xa5df
movl %eax, %r13d
movl %r13d, 0x3c(%rsp)
addq $0x4, %rbx
movq 0x18(%rsp), %rax
leaq 0x70(%rsp), %r15
jmp 0x8581
movq %rbp, %rdi
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2200
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movl %ebx, %esi
callq 0x925a
testl %eax, %eax
je 0x86ff
movq 0x70(%rsp), %r14
movl %ebp, %edx
movl 0x30(%rsp), %ecx
movq %r14, %rdi
movq %r15, %rsi
movq 0x40(%rsp), %rbx
movl %ebx, %r8d
callq 0xa516
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movq %r14, %rsi
movl 0xc(%rsp), %edx
movl %ebx, %ecx
movq 0x48(%rsp), %r8
movq 0x28(%rsp), %r9
callq 0xa5df
leaq 0x70(%rsp), %rdi
callq 0x9fa4
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq