// File: /workspace/github_c_makefile_star2_O2/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 $0x268, %rsp            # imm = 0x268
movq %r9, %r12
movl %r8d, %r14d
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r15
movq 0x2a0(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x10(%r9), %rdi
movq %rdi, 0x28(%rsp)
callq 0x35f5
cmpl $0x0, 0x8(%r12)
movl %ebp, 0xc(%rsp)
movq %rax, 0x20(%rsp)
je 0x79b8
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x160(%rsp), %r12
leaq 0xe0(%rsp), %rcx
leaq 0x120(%rsp), %r8
movq %r12, %rdx
movl %ebp, %r9d
pushq %rax
movq %r14, %rbp
pushq %r14
callq 0x929c
popq %rax
popq %rcx
movq 0x38(%r12), %rdi
movq %rdi, (%rbx)
callq 0x10f0
movq %rax, %r12
movq %r15, 0x48(%rsp)
movq %rax, (%r15)
leaq 0x120(%rsp), %rax
movq 0x38(%rax), %r14
movq %r14, %rdi
callq 0x10f0
movq %rax, %rbx
testq %rax, %rax
setne %al
testq %r14, %r14
sete %cl
testq %r12, %r12
je 0x7c41
orb %al, %cl
je 0x7c41
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x220(%rsp), %rdx
leaq 0x1e0(%rsp), %rcx
leaq 0x1a0(%rsp), %r8
movl 0xc(%rsp), %r9d
movq 0x20(%rsp), %r14
pushq %r14
pushq %rbp
callq 0x929c
popq %rax
popq %rcx
cmpl $0x7, %r14d
jbe 0x7a4b
movl %r14d, %eax
shrl $0x3, %eax
xorl %ecx, %ecx
leaq 0x3f46(%rip), %rsi      # 0xb850
leaq 0x3f1f(%rip), %rdi      # 0xb830
leaq 0x3ef8(%rip), %r8       # 0xb810
cmpq $0x7, %rcx
je 0x7b5a
movl 0xa0(%rsp,%rcx,4), %edx
movl %edx, 0x10(%rsp)
xorl %r10d, %r10d
cmpl 0x10(%rsp), %r10d
je 0x79b0
movl 0xc0(%rsp,%rcx,4), %r11d
movl %r11d, %ebp
imull %r10d, %ebp
xorl %r14d, %r14d
cmpq %r11, %r14
je 0x79ab
movl %ebp, %r15d
imulq %rax, %r15
addq 0x1a0(%rsp,%rcx,8), %r15
addq %rbx, %r15
movl (%r8,%rcx,4), %r9d
imull %r14d, %r9d
addl (%rdi,%rcx,4), %r9d
movl (%rsi,%rcx,4), %r12d
imull %r10d, %r12d
leaq 0x3ef5(%rip), %rdx      # 0xb870
addl (%rdx,%rcx,4), %r12d
imull 0xc(%rsp), %r12d
addl %r9d, %r12d
imulq %rax, %r12
addq %r13, %r12
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x79a4
movb (%r12,%r9), %dl
movb %dl, (%r15,%r9)
incq %r9
jmp 0x7992
incq %r14
incl %ebp
jmp 0x7949
incl %r10d
jmp 0x7930
incq %rcx
jmp 0x7918
imull %ebp, %eax
movq %rax, 0x38(%rsp)
addl $0x7, %eax
movq %r15, %rbp
movl %eax, 0x1c(%rsp)
movl %eax, %r15d
shrl $0x3, %r15d
imull %r14d, %r15d
movq %r14, 0x10(%rsp)
leal (%r15,%r14), %r12d
movq %r12, (%rbx)
movq %r12, %rdi
callq 0x10f0
movq %rax, %rbx
movq %rax, (%rbp)
testq %rax, %rax
sete %al
testl %r12d, %r12d
setne %cl
testb %al, %cl
jne 0x7c49
cmpl $0x7, 0x20(%rsp)
movl 0x1c(%rsp), %ebp
ja 0x7a1c
andl $-0x8, %ebp
cmpl %ebp, 0x38(%rsp)
jne 0x7c5b
movq %rbx, %rdi
movq %r13, %rsi
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x94fb
xorl %esi, %esi
leaq 0x58(%rsp), %r14
cmpq $0x7, %rsi
je 0x7b5a
movl 0xc0(%rsp,%rsi,4), %eax
movq %rax, 0x10(%rsp)
movl 0xa0(%rsp,%rsi,4), %eax
movl %eax, 0x44(%rsp)
xorl %edx, %edx
movl 0xc(%rsp), %ecx
movq %rsi, 0x50(%rsp)
cmpl 0x44(%rsp), %edx
je 0x7b52
movl %edx, %eax
imull 0x10(%rsp), %eax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
movl %edx, 0x1c(%rsp)
cmpq 0x10(%rsp), %r15
je 0x7b4b
leaq 0x3da3(%rip), %rax      # 0xb850
movl (%rax,%rsi,4), %eax
imull %edx, %eax
leaq 0x3db6(%rip), %rdx      # 0xb870
addl (%rdx,%rsi,4), %eax
imull %ecx, %eax
leaq 0x3d49(%rip), %rcx      # 0xb810
movl (%rcx,%rsi,4), %ebp
imull %r15d, %ebp
leaq 0x3d5b(%rip), %rcx      # 0xb830
addl (%rcx,%rsi,4), %ebp
movq 0x38(%rsp), %rcx
addl %r15d, %ecx
addl %eax, %ebp
movq 0x20(%rsp), %rdx
imull %edx, %ebp
movq 0x1a0(%rsp,%rsi,8), %rax
imull %edx, %ecx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x58(%rsp)
movl %edx, %r12d
subl $0x1, %r12d
jb 0x7b36
movq %rbp, %rax
shrq $0x3, %rax
movl %ebp, %ecx
notb %cl
movzbl (%r13,%rax), %eax
movzbl %cl, %ecx
andl $0x7, %ecx
xorl %edx, %edx
btl %ecx, %eax
setb %dl
incq %rbp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9405
jmp 0x7b01
incq %r15
movl 0xc(%rsp), %ecx
movq 0x50(%rsp), %rsi
movl 0x1c(%rsp), %edx
jmp 0x7a9b
incl %edx
jmp 0x7a7e
incq %rsi
jmp 0x7a52
xorl %r15d, %r15d
cmpq $0x7, %r15
je 0x7c41
cmpl $0x7, 0x20(%rsp)
ja 0x7bfd
movq 0xe8(%rsp,%r15,8), %rdi
subq 0xe0(%rsp,%r15,8), %rdi
callq 0x10f0
testq %rax, %rax
je 0x7c41
movq %rax, %r14
leaq 0x1(%r15), %r13
movq 0x120(%rsp,%r15,8), %rsi
addq %rbx, %rsi
movl 0x80(%rsp,%r15,4), %ebp
movl %ebp, %ecx
imull 0x20(%rsp), %ecx
leal 0x7(%rcx), %edx
andl $-0x8, %edx
movl 0x60(%rsp,%r15,4), %r12d
movq %rax, %rdi
movl %r12d, %r8d
callq 0x9432
movq 0x48(%rsp), %rax
movq (%rax), %rdi
addq 0x160(%rsp,%r15,8), %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r12d, %ecx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0x94fb
movl %eax, %ebp
movq %r14, %rdi
callq 0x1030
movq %r13, %r15
jmp 0x7c39
movq 0x48(%rsp), %rax
movq (%rax), %rdi
addq 0x160(%rsp,%r15,8), %rdi
movq 0xe0(%rsp,%r15,8), %rsi
addq %rbx, %rsi
movl 0x80(%rsp,%r15,4), %edx
movl 0x60(%rsp,%r15,4), %ecx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0x94fb
movl %eax, %ebp
incq %r15
testl %ebp, %ebp
je 0x7b5d
movq %rbx, %rdi
callq 0x1030
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %edi
callq 0x10f0
movq %rax, %r15
testq %rax, %rax
movq 0x10(%rsp), %r12
je 0x7ca0
movl %ebp, %edx
movl 0x38(%rsp), %ecx
movq %r15, %rdi
movq %r13, %rsi
movl %r12d, %r8d
callq 0x9432
movq %rbx, %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
movl %r12d, %ecx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0x94fb
movq %r15, %rdi
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030