// File: /workspace/github_cpp_makefile_star2_O3/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 $0x288, %rsp            # imm = 0x288
movl %ecx, %r15d
movq %rdx, %rbp
movq %rdi, 0x38(%rsp)
movl 0x10(%r9), %r13d
movq %r9, 0x50(%rsp)
movl 0x14(%r9), %r12d
xorl %r14d, %r14d
cmpq $0x6, %r13
ja 0x97ea
leaq 0x8e96(%rip), %rax      # 0x1267c
movl (%rax,%r13,4), %r14d
movq 0x2c0(%rsp), %rax
movq %rax, 0x48(%rsp)
imull %r12d, %r14d
movq 0x50(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0x9a1b
movq %rsi, 0x10(%rsp)
movl %r8d, %ebx
imull %r15d, %ebx
imull %r14d, %ebx
addl $0x7, %ebx
movl %ebx, %edi
shrl $0x3, %edi
movq %r8, %r13
callq 0x2270
movq %rax, %r12
testq %rax, %rax
setne %al
cmpl $0x8, %ebx
setb %cl
xorl %edx, %edx
orb %al, %cl
movl $0x53, %eax
cmovnel %edx, %eax
movl %eax, 0x24(%rsp)
je 0x9d2a
movl %r14d, 0x8(%rsp)
movl %r13d, (%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x140(%rsp), %rbx
leaq 0x100(%rsp), %rcx
leaq 0x1c0(%rsp), %r8
movq %rbx, %rdx
movl %r15d, %r9d
callq 0xd1d4
movl %r14d, 0x18(%rsp)
movq 0x38(%rbx), %r14
movq 0x10(%rsp), %rax
movq %r14, (%rax)
movq %r14, %rdi
callq 0x2270
movq 0x38(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
sete %al
testq %r14, %r14
movl 0x18(%rsp), %ebx
setne %cl
testb %al, %cl
jne 0x9d2a
movl %ebx, 0x8(%rsp)
movq %r13, 0x40(%rsp)
movl %r13d, (%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x240(%rsp), %rdx
leaq 0x200(%rsp), %rcx
leaq 0x180(%rsp), %r8
movq %r15, 0x28(%rsp)
movl %r15d, %r9d
callq 0xd1d4
cmpl $0x7, %ebx
jbe 0x9ab6
movl %ebx, %r14d
shrl $0x3, %r14d
xorl %eax, %eax
movq %rax, 0x58(%rsp)
movl 0xc0(%rsp,%rax,4), %eax
movq %rax, 0x78(%rsp)
testq %rax, %rax
je 0x9a04
movq 0x58(%rsp), %rax
movl 0xe0(%rsp,%rax,4), %eax
movq $0x0, 0x68(%rsp)
movq $0x0, 0x30(%rsp)
movq %rax, 0x70(%rsp)
testq %rax, %rax
je 0x99e2
movq 0x58(%rsp), %rax
leaq 0x8b36(%rip), %rcx      # 0x124a0
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x10(%rsp)
movq 0x180(%rsp,%rax,8), %rcx
addq %r12, %rcx
movq %rcx, 0x60(%rsp)
leaq 0x8b58(%rip), %rcx      # 0x124e0
movl (%rcx,%rax,4), %r13d
imull 0x30(%rsp), %r13d
leaq 0x8b67(%rip), %rcx      # 0x12500
addl (%rcx,%rax,4), %r13d
imull 0x28(%rsp), %r13d
leaq 0x8b16(%rip), %rcx      # 0x124c0
addl (%rcx,%rax,4), %r13d
movq 0x70(%rsp), %r15
movq 0x68(%rsp), %rbx
movl %ebx, %edi
imulq %r14, %rdi
addq 0x60(%rsp), %rdi
movl %r13d, %esi
imulq %r14, %rsi
addq %rbp, %rsi
movq %r14, %rdx
callq 0x2150
addl 0x10(%rsp), %r13d
incq %rbx
decq %r15
jne 0x99b8
movq 0x30(%rsp), %rdx
incq %rdx
movq 0x70(%rsp), %rax
addq %rax, 0x68(%rsp)
movq %rdx, 0x30(%rsp)
cmpq 0x78(%rsp), %rdx
jne 0x9955
movq 0x58(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x9918
jmp 0x9be4
movl %r14d, %ebx
movq %r15, 0x28(%rsp)
imull %r15d, %ebx
leal 0x7(%rbx), %eax
movl %eax, 0x10(%rsp)
movl %eax, %r15d
shrl $0x3, %r15d
imull %r8d, %r15d
movl %r14d, 0x18(%rsp)
movq %r8, 0x40(%rsp)
leal (%r15,%r8), %r14d
movq %r14, (%rsi)
movq %r14, %rdi
callq 0x2270
movq %rax, %rdi
movq 0x38(%rsp), %rax
movq %rdi, (%rax)
testq %rdi, %rdi
sete %al
testl %r14d, %r14d
setne %cl
testb %al, %cl
jne 0x9aa4
cmpl $0x7, 0x18(%rsp)
ja 0x9a83
movl 0x10(%rsp), %eax
andl $-0x8, %eax
cmpl %eax, %ebx
jne 0x9d43
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rsi
movq 0x28(%rsp), %rdx
movq 0x40(%rsp), %rcx
movl %r13d, %r8d
movl %r12d, %r9d
callq 0xd4cc
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movl 0xc0(%rsp,%rax,4), %eax
movl %eax, 0x60(%rsp)
testl %eax, %eax
je 0x9bd2
movq 0x30(%rsp), %rax
movl 0xe0(%rsp,%rax,4), %r10d
movl $0x0, 0x10(%rsp)
testq %r10, %r10
je 0x9bbe
movq 0x30(%rsp), %rax
leaq 0x89e6(%rip), %rcx      # 0x124e0
movl (%rcx,%rax,4), %r14d
movl 0x10(%rsp), %esi
imull %esi, %r14d
leaq 0x89f3(%rip), %rcx      # 0x12500
addl (%rcx,%rax,4), %r14d
imull 0x28(%rsp), %r14d
leaq 0x8982(%rip), %rcx      # 0x124a0
movl (%rcx,%rax,4), %ebx
movq 0x180(%rsp,%rax,8), %r13
shlq $0x3, %r13
movl %r10d, %edx
imull %esi, %edx
leaq 0x8986(%rip), %rcx      # 0x124c0
addl (%rcx,%rax,4), %r14d
xorl %esi, %esi
cmpl $0x0, 0x18(%rsp)
je 0x9bb6
leal (%rdx,%rsi), %edi
movl 0x18(%rsp), %r15d
imull %r15d, %edi
addq %r13, %rdi
movl %ebx, %eax
imull %esi, %eax
addl %r14d, %eax
imull %r15d, %eax
movl %eax, %r9d
notb %r9b
movl %edi, %ecx
notb %cl
movq %rax, %r8
shrq $0x3, %r8
movzbl (%rbp,%r8), %r8d
movzbl %r9b, %r11d
andl $0x7, %r11d
andb $0x7, %cl
movb $0x1, %r9b
shlb %cl, %r9b
btl %r11d, %r8d
jae 0x9b9d
movq %rdi, %rcx
shrq $0x3, %rcx
orb %r9b, (%r12,%rcx)
jmp 0x9bab
notb %r9b
movq %rdi, %rcx
shrq $0x3, %rcx
andb %r9b, (%r12,%rcx)
incq %rdi
incq %rax
decl %r15d
jne 0x9b62
incq %rsi
cmpq %r10, %rsi
jne 0x9b40
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl 0x60(%rsp), %eax
jne 0x9ae5
movq 0x30(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x9ab8
movq 0x28(%rsp), %rbx
movl 0x18(%rsp), %r14d
imull %r14d, %ebx
addl $0x7, %ebx
shrl $0x3, %ebx
imull 0x40(%rsp), %ebx
leaq (%rbx,%rbx), %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
movq 0x38(%rsp), %r13
movq %rbx, 0x28(%rsp)
cmpl $0x7, %r14d
ja 0x9c3e
testl %ebx, %ebx
je 0x9c87
movq 0x10(%rsp), %rdi
callq 0x2270
movq %rax, %r14
testq %rax, %rax
jne 0x9c8a
movl $0x53, 0x24(%rsp)
xorl %r14d, %r14d
jmp 0x9d0f
movq (%r13), %rdi
addq 0x140(%rsp,%rbp,2), %rdi
movq 0x100(%rsp,%rbp,2), %rsi
addq %r12, %rsi
movl 0xa0(%rsp,%rbp), %edx
movl 0x80(%rsp,%rbp), %ecx
movq 0x50(%rsp), %rax
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
callq 0xd4cc
movl %eax, 0x24(%rsp)
jmp 0x9d1c
xorl %r14d, %r14d
cmpl $0x0, 0x24(%rsp)
jne 0x9d0f
movq 0x100(%rsp,%rbp,2), %r13
addq %r14, %r13
movq 0x1c0(%rsp,%rbp,2), %rsi
addq %r12, %rsi
movl 0xa0(%rsp,%rbp), %ebx
movl %ebx, %ecx
imull 0x18(%rsp), %ecx
leal 0x7(%rcx), %edx
andl $-0x8, %edx
movl 0x80(%rsp,%rbp), %r15d
movq %r13, %rdi
movl %r15d, %r8d
callq 0xd3ed
movq 0x38(%rsp), %rax
movq (%rax), %rdi
addq 0x140(%rsp,%rbp,2), %rdi
movq 0x50(%rsp), %rax
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rsi
movq 0x38(%rsp), %r13
movl %ebx, %edx
movq 0x28(%rsp), %rbx
movl %r15d, %ecx
callq 0xd4cc
movl %eax, 0x24(%rsp)
movq %r14, %rdi
callq 0x2220
movl 0x18(%rsp), %r14d
addq $0x4, %rbp
cmpq $0x1c, %rbp
jne 0x9c12
movq %r12, %rdi
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220
movl %eax, %r14d
movq %rdi, 0x18(%rsp)
testl %r15d, %r15d
je 0x9d68
movl %r15d, %edi
addq %rdi, %rdi
callq 0x2270
movq %rax, %r15
testq %rax, %rax
jne 0x9d6b
xorl %r15d, %r15d
jmp 0x9da6
xorl %r15d, %r15d
movl %r14d, %edx
movl %ebx, %ecx
movq %r15, %rdi
movq %rbp, %rsi
movq 0x40(%rsp), %rbx
movl %ebx, %r8d
callq 0xd3ed
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movl %ebx, %ecx
movl %r13d, %r8d
movl %r12d, %r9d
callq 0xd4cc
movq %r15, %rdi
jmp 0x9d2d