// File: /workspace/github_c_makefile_star2_O3/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: preProcessScanlines
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
movl %r8d, %ebp
movl %ecx, 0x20(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x40(%rsp)
movl 0x10(%r9), %r13d
movq %r9, 0x48(%rsp)
movl 0x14(%r9), %edx
xorl %eax, %eax
cmpq $0x6, %r13
ja 0x8965
leaq 0x61a3(%rip), %rax      # 0xeb04
movl (%rax,%r13,4), %eax
movq 0x2b0(%rsp), %r14
imull %edx, %eax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x8(%rcx)
movl %eax, 0x24(%rsp)
je 0x8b4f
movl %eax, 0x8(%rsp)
movl %ebp, (%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x130(%rsp), %r13
leaq 0xf0(%rsp), %rcx
leaq 0x1b0(%rsp), %rbx
movq %r13, %rdx
movq %rbx, %r8
movl 0x20(%rsp), %r9d
callq 0xc193
movq 0x38(%r13), %rdi
movq %rdi, (%r12)
callq 0x1100
movq %rax, %r13
movq 0x40(%rsp), %rax
movq %r13, (%rax)
movq 0x38(%rbx), %rbx
movq %rbx, %rdi
callq 0x1100
movq %rax, %r12
testq %rax, %rax
setne %al
testq %rbx, %rbx
movl 0x24(%rsp), %ebx
sete %cl
testq %r13, %r13
je 0x8e0c
orb %al, %cl
je 0x8e0c
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 0xc193
cmpl $0x7, %ebx
jbe 0x8beb
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 0x8b38
movq 0x50(%rsp), %rax
movl 0xd0(%rsp,%rax,4), %eax
movq $0x0, 0x58(%rsp)
movq $0x0, 0x28(%rsp)
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x8b16
movq 0x50(%rsp), %rax
leaq 0x5e4b(%rip), %rcx      # 0xe8f0
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x1c(%rsp)
movq 0x170(%rsp,%rax,8), %rcx
addq %r12, %rcx
movq %rcx, 0x30(%rsp)
leaq 0x5e6d(%rip), %rcx      # 0xe930
movl (%rcx,%rax,4), %ebx
imull 0x28(%rsp), %ebx
leaq 0x5e7e(%rip), %rcx      # 0xe950
addl (%rcx,%rax,4), %ebx
imull 0x20(%rsp), %ebx
leaq 0x5e2f(%rip), %rcx      # 0xe910
addl (%rcx,%rax,4), %ebx
movq 0x60(%rsp), %r14
movq 0x58(%rsp), %rbp
movl %ebp, %edi
imulq %r13, %rdi
addq 0x30(%rsp), %rdi
movl %ebx, %esi
imulq %r13, %rsi
addq %r15, %rsi
movq %r13, %rdx
callq 0x10f0
addl 0x1c(%rsp), %ebx
incq %rbp
decq %r14
jne 0x8aee
movq 0x28(%rsp), %rdx
incq %rdx
movq 0x60(%rsp), %rax
addq %rax, 0x58(%rsp)
movq %rdx, 0x28(%rsp)
cmpq 0x68(%rsp), %rdx
jne 0x8a94
movq 0x50(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x8a57
jmp 0x8d14
movl %edx, 0x28(%rsp)
movq %r14, 0x38(%rsp)
movq %rbp, %rcx
movl %eax, %ebp
imull 0x20(%rsp), %ebp
leal 0x7(%rbp), %edx
movl %edx, 0x1c(%rsp)
movl %edx, %r14d
shrl $0x3, %r14d
imull %ecx, %r14d
movq %rcx, 0x30(%rsp)
leal (%r14,%rcx), %ebx
movq %rbx, (%r12)
movq %rbx, %rdi
callq 0x1100
movq %rax, %r12
movq 0x40(%rsp), %rax
movq %r12, (%rax)
testq %r12, %r12
sete %al
testl %ebx, %ebx
setne %cl
testb %al, %cl
jne 0x8e14
cmpl $0x7, 0x24(%rsp)
ja 0x8bc1
movl 0x1c(%rsp), %eax
andl $-0x8, %eax
movl %eax, 0x1c(%rsp)
cmpl %eax, %ebp
jne 0x8e26
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movl 0x20(%rsp), %edx
movq 0x30(%rsp), %rcx
movl %r13d, %r8d
movl 0x28(%rsp), %r9d
callq 0xc36f
jmp 0x8e14
xorl %eax, %eax
movq %rax, 0x28(%rsp)
movl 0xb0(%rsp,%rax,4), %eax
movl %eax, 0x30(%rsp)
testl %eax, %eax
je 0x8d02
movq 0x28(%rsp), %rax
movl 0xd0(%rsp,%rax,4), %r10d
movl $0x0, 0x1c(%rsp)
testq %r10, %r10
je 0x8cee
movq 0x28(%rsp), %rax
leaq 0x5d01(%rip), %rcx      # 0xe930
movl (%rcx,%rax,4), %ebx
movl 0x1c(%rsp), %edi
imull %edi, %ebx
leaq 0x5d10(%rip), %rcx      # 0xe950
addl (%rcx,%rax,4), %ebx
imull 0x20(%rsp), %ebx
leaq 0x5ca1(%rip), %rcx      # 0xe8f0
movl (%rcx,%rax,4), %r13d
movq 0x170(%rsp,%rax,8), %rdx
shlq $0x3, %rdx
movl %r10d, %esi
imull %edi, %esi
leaq 0x5ca4(%rip), %rcx      # 0xe910
addl (%rcx,%rax,4), %ebx
xorl %edi, %edi
cmpl $0x0, 0x24(%rsp)
je 0x8ce6
leal (%rsi,%rdi), %ebp
movl 0x24(%rsp), %r14d
imull %r14d, %ebp
addq %rdx, %rbp
movl %r13d, %eax
imull %edi, %eax
addl %ebx, %eax
imull %r14d, %eax
movl %eax, %r9d
notb %r9b
movl %ebp, %ecx
notb %cl
movq %rax, %r8
shrq $0x3, %r8
movzbl (%r15,%r8), %r8d
movzbl %r9b, %r11d
andl $0x7, %r11d
andb $0x7, %cl
movb $0x1, %r9b
shlb %cl, %r9b
btl %r11d, %r8d
jae 0x8ccd
movq %rbp, %rcx
shrq $0x3, %rcx
orb %r9b, (%r12,%rcx)
jmp 0x8cdb
notb %r9b
movq %rbp, %rcx
shrq $0x3, %rcx
andb %r9b, (%r12,%rcx)
incq %rbp
incq %rax
decl %r14d
jne 0x8c93
incq %rdi
cmpq %r10, %rdi
jne 0x8c71
movl 0x1c(%rsp), %eax
incl %eax
movl %eax, 0x1c(%rsp)
cmpl 0x30(%rsp), %eax
jne 0x8c1a
movq 0x28(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x8bed
xorl %r13d, %r13d
movq 0x38(%rsp), %r14
movl 0x24(%rsp), %ebx
cmpl $0x7, %ebx
ja 0x8db7
movq 0xf8(%rsp,%r13,2), %rdi
subq 0xf0(%rsp,%r13,2), %rdi
callq 0x1100
testq %rax, %rax
je 0x8e0c
movq %rax, %r15
movq 0x1b0(%rsp,%r13,2), %rsi
addq %r12, %rsi
movl 0x90(%rsp,%r13), %ebx
movl %ebx, %ecx
imull 0x24(%rsp), %ecx
leal 0x7(%rcx), %edx
andl $-0x8, %edx
movl 0x70(%rsp,%r13), %ebp
movq %rax, %rdi
movl %ebp, %r8d
callq 0xc297
movq 0x40(%rsp), %rax
movq (%rax), %rdi
addq 0x130(%rsp,%r13,2), %rdi
movq 0x48(%rsp), %rax
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
movq %r14, (%rsp)
movq %r15, %rsi
movl %ebx, %edx
movl 0x24(%rsp), %ebx
movl %ebp, %ecx
callq 0xc36f
movl %eax, %ebp
movq %r15, %rdi
callq 0x1030
jmp 0x8df7
movq 0x40(%rsp), %rax
movq (%rax), %rdi
addq 0x130(%rsp,%r13,2), %rdi
movq 0xf0(%rsp,%r13,2), %rsi
addq %r12, %rsi
movl 0x90(%rsp,%r13), %edx
movl 0x70(%rsp,%r13), %ecx
movq 0x48(%rsp), %rax
movl 0x10(%rax), %r8d
movl 0x14(%rax), %r9d
movq %r14, (%rsp)
callq 0xc36f
movl %eax, %ebp
testl %ebp, %ebp
jne 0x8e0c
leaq 0x4(%r13), %rax
cmpq $0x18, %r13
movq %rax, %r13
jne 0x8d20
movq %r12, %rdi
callq 0x1030
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %edi
callq 0x1100
movq %rax, %rbx
testq %rax, %rax
je 0x8e72
movl 0x1c(%rsp), %edx
movl %ebp, %ecx
movq %rbx, %rdi
movq %r15, %rsi
movq 0x30(%rsp), %r14
movl %r14d, %r8d
callq 0xc297
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movl 0x20(%rsp), %edx
movl %r14d, %ecx
movl %r13d, %r8d
movl 0x28(%rsp), %r9d
callq 0xc36f
movq %rbx, %rdi
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030