// File: /workspace/github_cpp_makefile_star2_O1/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
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdx, %r13
movq %rdi, 0x40(%rsp)
movl 0x10(%r9), %ecx
movl 0x14(%r9), %eax
xorl %r15d, %r15d
cmpq $0x6, %rcx
ja 0x98c6
leaq 0x8cea(%rip), %rdx      # 0x125ac
movl (%rdx,%rcx,4), %r15d
imull %eax, %r15d
movq 0x2b0(%rsp), %r12
leaq 0x10(%r9), %rax
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x8(%r9)
je 0x9af7
movq %rsi, (%rsp)
movl %ebp, %ebx
imull %r14d, %ebx
imull %r15d, %ebx
addl $0x7, %ebx
movl %ebx, %edi
shrl $0x3, %edi
callq 0x2270
movq %rbp, %r10
movq %rax, %rbp
testq %rax, %rax
setne %al
cmpl $0x8, %ebx
setb %cl
xorl %edx, %edx
orb %al, %cl
movl $0x53, %eax
cmovnel %edx, %eax
movl %eax, 0xc(%rsp)
je 0x9df5
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x130(%rsp), %rbx
leaq 0xf0(%rsp), %rcx
leaq 0x1b0(%rsp), %r8
movq %rbx, %rdx
movl %r14d, %r9d
pushq %r15
movq %r10, 0x30(%rsp)
pushq %r10
callq 0xd4df
addq $0x10, %rsp
movq %r15, 0x18(%rsp)
movq 0x38(%rbx), %r15
movq (%rsp), %rax
movq %r15, (%rax)
movq %r15, %rdi
callq 0x2270
movq 0x40(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
sete %al
testq %r15, %r15
movq 0x18(%rsp), %r15
setne %cl
testb %al, %cl
jne 0x9df5
movq %r12, 0x30(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x230(%rsp), %rdx
leaq 0x1f0(%rsp), %rcx
leaq 0x170(%rsp), %r8
movq %r14, 0x10(%rsp)
movl %r14d, %r9d
pushq %r15
movq 0x30(%rsp), %rax
pushq %rax
callq 0xd4df
addq $0x10, %rsp
cmpl $0x7, %r15d
jbe 0x9b9f
shrl $0x3, %r15d
xorl %eax, %eax
movq %rax, 0x48(%rsp)
movl 0xb0(%rsp,%rax,4), %eax
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x9ae0
movq 0x48(%rsp), %rax
movl 0xd0(%rsp,%rax,4), %eax
movq $0x0, 0x58(%rsp)
movq $0x0, 0x20(%rsp)
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x9abe
movq 0x48(%rsp), %rax
leaq 0x8989(%rip), %rcx      # 0x123d0
movl (%rcx,%rax,4), %ecx
movl %ecx, (%rsp)
movq 0x170(%rsp,%rax,8), %rcx
addq %rbp, %rcx
movq %rcx, 0x50(%rsp)
leaq 0x89ac(%rip), %rcx      # 0x12410
movl (%rcx,%rax,4), %r12d
imull 0x20(%rsp), %r12d
leaq 0x89bb(%rip), %rcx      # 0x12430
addl (%rcx,%rax,4), %r12d
imull 0x10(%rsp), %r12d
leaq 0x896a(%rip), %rcx      # 0x123f0
addl (%rcx,%rax,4), %r12d
movq 0x60(%rsp), %rbx
movq 0x58(%rsp), %r14
movl %r14d, %edi
imulq %r15, %rdi
addq 0x50(%rsp), %rdi
movl %r12d, %esi
imulq %r15, %rsi
addq %r13, %rsi
movq %r15, %rdx
callq 0x2150
addl (%rsp), %r12d
incq %r14
decq %rbx
jne 0x9a94
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x60(%rsp), %rax
addq %rax, 0x58(%rsp)
movq %rdx, 0x20(%rsp)
cmpq 0x68(%rsp), %rdx
jne 0x9a32
movq 0x48(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x99f5
jmp 0x9cd0
movq %r12, 0x30(%rsp)
movl %r15d, %ebx
movq %r14, 0x10(%rsp)
imull %r14d, %ebx
movq %r15, 0x18(%rsp)
leal 0x7(%rbx), %r15d
movl %r15d, %r12d
shrl $0x3, %r12d
imull %ebp, %r12d
movq %rbp, 0x28(%rsp)
addl %r12d, %ebp
movq %rbp, (%rsi)
movq %rbp, %rdi
callq 0x2270
movq %rax, %r14
movq 0x40(%rsp), %rax
movq %r14, (%rax)
testq %r14, %r14
sete %al
testl %ebp, %ebp
setne %cl
testb %al, %cl
jne 0x9b8d
cmpl $0x7, 0x18(%rsp)
ja 0x9b5d
andl $-0x8, %r15d
cmpl %r15d, %ebx
jne 0x9e0e
movq %r14, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq 0x38(%rsp), %r8
movq 0x30(%rsp), %r9
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd7c0
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl 0xb0(%rsp,%rax,4), %eax
movl %eax, 0x50(%rsp)
testl %eax, %eax
je 0x9cbe
movq 0x20(%rsp), %rax
movl 0xd0(%rsp,%rax,4), %r10d
movl $0x0, (%rsp)
testq %r10, %r10
je 0x9cac
movq 0x20(%rsp), %rax
leaq 0x882e(%rip), %rcx      # 0x12410
movl (%rcx,%rax,4), %r15d
movl (%rsp), %esi
imull %esi, %r15d
leaq 0x883c(%rip), %rcx      # 0x12430
addl (%rcx,%rax,4), %r15d
imull 0x10(%rsp), %r15d
leaq 0x87cb(%rip), %rcx      # 0x123d0
movl (%rcx,%rax,4), %ebx
movq 0x170(%rsp,%rax,8), %r14
shlq $0x3, %r14
movl %r10d, %edx
imull %esi, %edx
leaq 0x87cf(%rip), %rcx      # 0x123f0
addl (%rcx,%rax,4), %r15d
xorl %esi, %esi
cmpl $0x0, 0x18(%rsp)
je 0x9ca0
leal (%rdx,%rsi), %edi
movq 0x18(%rsp), %rcx
imull %ecx, %edi
addq %r14, %rdi
movl %ebx, %eax
imull %esi, %eax
addl %r15d, %eax
imull %ecx, %eax
movl %ecx, %r9d
movl %eax, %r12d
notb %r12b
movl %edi, %ecx
notb %cl
movq %rax, %r8
shrq $0x3, %r8
movzbl (%r13,%r8), %r8d
movzbl %r12b, %r11d
andl $0x7, %r11d
andb $0x7, %cl
movb $0x1, %r12b
shlb %cl, %r12b
btl %r11d, %r8d
jae 0x9c86
movq %rdi, %rcx
shrq $0x3, %rcx
orb %r12b, (%rbp,%rcx)
jmp 0x9c95
notb %r12b
movq %rdi, %rcx
shrq $0x3, %rcx
andb %r12b, (%rbp,%rcx)
incq %rdi
incq %rax
decl %r9d
jne 0x9c4a
incq %rsi
cmpq %r10, %rsi
jne 0x9c27
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl 0x50(%rsp), %eax
jne 0x9bcd
movq 0x20(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x9ba1
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %r14
imull %r14d, %eax
addl $0x7, %eax
shrl $0x3, %eax
imull 0x28(%rsp), %eax
movq %rax, 0x10(%rsp)
addq %rax, %rax
movq %rax, (%rsp)
xorl %r13d, %r13d
movq 0x30(%rsp), %r12
cmpl $0x7, %r14d
ja 0x9d27
cmpl $0x0, 0x10(%rsp)
je 0x9d65
movq (%rsp), %rdi
callq 0x2270
movq %rax, %r15
testq %rax, %rax
movl 0xc(%rsp), %eax
movl $0x53, %ecx
cmovel %ecx, %eax
jmp 0x9d6c
movq 0x40(%rsp), %rax
movq (%rax), %rdi
addq 0x130(%rsp,%r13,2), %rdi
movq 0xf0(%rsp,%r13,2), %rsi
addq %rbp, %rsi
movl 0x90(%rsp,%r13), %edx
movl 0x70(%rsp,%r13), %ecx
movq 0x38(%rsp), %r8
movq %r12, %r9
callq 0xd7c0
movl %eax, 0xc(%rsp)
jmp 0x9de7
xorl %r15d, %r15d
movl 0xc(%rsp), %eax
testl %eax, %eax
jne 0x9dd6
movq 0xf0(%rsp,%r13,2), %r14
addq %r15, %r14
movq 0x1b0(%rsp,%r13,2), %rsi
addq %rbp, %rsi
movl 0x90(%rsp,%r13), %r12d
movl %r12d, %ecx
imull 0x18(%rsp), %ecx
leal 0x7(%rcx), %edx
andl $-0x8, %edx
movl 0x70(%rsp,%r13), %ebx
movq %r14, %rdi
movl %ebx, %r8d
callq 0xd6ff
movq 0x40(%rsp), %rax
movq (%rax), %rdi
addq 0x130(%rsp,%r13,2), %rdi
movq %r14, %rsi
movl %r12d, %edx
movq 0x30(%rsp), %r12
movl %ebx, %ecx
movq 0x38(%rsp), %r8
movq %r12, %r9
callq 0xd7c0
movl %eax, 0xc(%rsp)
movq %r15, %rdi
callq 0x2220
movq 0x18(%rsp), %r14
addq $0x4, %r13
cmpq $0x1c, %r13
jne 0x9cfd
movq %rbp, %rdi
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220
testl %r12d, %r12d
movq 0x28(%rsp), %rbp
je 0x9e2e
movl %r12d, %edi
addq %rdi, %rdi
callq 0x2270
movq %rax, %r12
testq %rax, %rax
sete %al
jmp 0x9e33
xorl %r12d, %r12d
xorl %eax, %eax
testb %al, %al
jne 0x9e66
movl %r15d, %edx
movl %ebx, %ecx
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %r8d
callq 0xd6ff
movq %r14, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
movq 0x38(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0xd7c0
movq %r12, %rdi
jmp 0x9df8