// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq -0x28(%rbp), %rdi
addq $0x10, %rdi
callq 0x30e0
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x8ca2
movl -0x20(%rbp), %eax
movl -0x20(%rbp), %ecx
movl -0x1c(%rbp), %edx
imull -0x2c(%rbp), %edx
addl $0x7, %edx
shrl $0x3, %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x13b0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x8baf
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x8baf
movl $0x53, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x8c9d
cmpl $0x8, -0x2c(%rbp)
jae 0x8c76
movl -0x1c(%rbp), %eax
imull -0x2c(%rbp), %eax
movl -0x1c(%rbp), %ecx
imull -0x2c(%rbp), %ecx
addl $0x7, %ecx
shrl $0x3, %ecx
shll $0x3, %ecx
cmpl %ecx, %eax
je 0x8c76
movl -0x20(%rbp), %eax
movl -0x1c(%rbp), %ecx
imull -0x2c(%rbp), %ecx
addl $0x7, %ecx
shrl $0x3, %ecx
imull %ecx, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x13b0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x8c10
movl $0x53, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x8c6b
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
imull -0x2c(%rbp), %eax
addl $0x7, %eax
shrl $0x3, %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %edx
movl -0x1c(%rbp), %eax
imull -0x2c(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
movl -0x20(%rbp), %r8d
callq 0x10130
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movq -0x28(%rbp), %r8
addq $0x10, %r8
movq 0x10(%rbp), %r9
callq 0x10210
movl %eax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1e60
jmp 0x8c9b
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movq -0x28(%rbp), %r8
addq $0x10, %r8
movq 0x10(%rbp), %r9
callq 0x10210
movl %eax, -0x30(%rbp)
jmp 0x8c9d
jmp 0x8eeb
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
leaq -0x100(%rbp), %rcx
leaq -0x140(%rbp), %r8
movl -0x1c(%rbp), %r9d
movl -0x20(%rbp), %r10d
movl -0x2c(%rbp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xf520
movq -0x88(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x13b0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x8d0c
movl $0x53, -0x30(%rbp)
movq -0x108(%rbp), %rdi
callq 0x13b0
movq %rax, -0x148(%rbp)
cmpq $0x0, -0x148(%rbp)
jne 0x8d3a
cmpq $0x0, -0x108(%rbp)
je 0x8d3a
movl $0x53, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x8edf
movq -0x148(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x2c(%rbp), %r8d
callq 0x10d70
movl $0x0, -0x14c(%rbp)
cmpl $0x7, -0x14c(%rbp)
je 0x8edd
cmpl $0x8, -0x2c(%rbp)
jae 0x8e6d
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movq -0x100(%rbp,%rax,8), %rdi
movl -0x14c(%rbp), %eax
subq -0x100(%rbp,%rax,8), %rdi
callq 0x13b0
movq %rax, -0x158(%rbp)
cmpq $0x0, -0x158(%rbp)
jne 0x8dc2
movl $0x53, -0x30(%rbp)
jmp 0x8edd
movq -0x158(%rbp), %rdi
movq -0x148(%rbp), %rsi
movl -0x14c(%rbp), %eax
addq -0x140(%rbp,%rax,8), %rsi
movl -0x14c(%rbp), %eax
movl -0x60(%rbp,%rax,4), %eax
imull -0x2c(%rbp), %eax
addl $0x7, %eax
shrl $0x3, %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %edx
movl -0x14c(%rbp), %eax
movl -0x60(%rbp,%rax,4), %eax
imull -0x2c(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
movl -0x14c(%rbp), %eax
movl -0x80(%rbp,%rax,4), %r8d
callq 0x10130
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl -0x14c(%rbp), %eax
addq -0xc0(%rbp,%rax,8), %rdi
movq -0x158(%rbp), %rsi
movl -0x14c(%rbp), %eax
movl -0x60(%rbp,%rax,4), %edx
movl -0x14c(%rbp), %eax
movl -0x80(%rbp,%rax,4), %ecx
movq -0x28(%rbp), %r8
addq $0x10, %r8
movq 0x10(%rbp), %r9
callq 0x10210
movl %eax, -0x30(%rbp)
movq -0x158(%rbp), %rdi
callq 0x1e60
jmp 0x8ebf
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl -0x14c(%rbp), %eax
addq -0xc0(%rbp,%rax,8), %rdi
movq -0x148(%rbp), %rsi
movl -0x14c(%rbp), %eax
addq -0x100(%rbp,%rax,8), %rsi
movl -0x14c(%rbp), %eax
movl -0x60(%rbp,%rax,4), %edx
movl -0x14c(%rbp), %eax
movl -0x80(%rbp,%rax,4), %ecx
movq -0x28(%rbp), %r8
addq $0x10, %r8
movq 0x10(%rbp), %r9
callq 0x10210
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x8ec7
jmp 0x8edd
jmp 0x8ec9
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x8d68
jmp 0x8edf
movq -0x148(%rbp), %rdi
callq 0x1e60
movl -0x30(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopw (%rax,%rax)