// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: lodepng_encode
unsigned lodepng_encode(unsigned char** out, size_t* outsize,
                        const unsigned char* image, unsigned w, unsigned h,
                        LodePNGState* state)
{
  LodePNGInfo info;
  ucvector outv;
  unsigned char* data = 0; /*uncompressed version of the IDAT chunk data*/
  size_t datasize = 0;

  /*provide some proper output values if error will happen*/
  *out = 0;
  *outsize = 0;
  state->error = 0;

  /*check input values validity*/
  if((state->info_png.color.colortype == LCT_PALETTE || state->encoder.force_palette)
      && (state->info_png.color.palettesize == 0 || state->info_png.color.palettesize > 256))
  {
    CERROR_RETURN_ERROR(state->error, 68); /*invalid palette size, it is only allowed to be 1-256*/
  }
  if(state->encoder.zlibsettings.btype > 2)
  {
    CERROR_RETURN_ERROR(state->error, 61); /*error: unexisting btype*/
  }
  if(state->info_png.interlace_method > 1)
  {
    CERROR_RETURN_ERROR(state->error, 71); /*error: unexisting interlace mode*/
  }
  state->error = checkColorValidity(state->info_png.color.colortype, state->info_png.color.bitdepth);
  if(state->error) return state->error; /*error: unexisting color type given*/
  state->error = checkColorValidity(state->info_raw.colortype, state->info_raw.bitdepth);
  if(state->error) return state->error; /*error: unexisting color type given*/

  /* color convert and compute scanline filter types */
  lodepng_info_init(&info);
  lodepng_info_copy(&info, &state->info_png);
  if(state->encoder.auto_convert)
  {
    state->error = lodepng_auto_choose_color(&info.color, image, w, h, &state->info_raw);
  }
  if (!state->error)
  {
    if(!lodepng_color_mode_equal(&state->info_raw, &info.color))
    {
      unsigned char* converted;
      size_t size = (w * h * (size_t)lodepng_get_bpp(&info.color) + 7) / 8;

      converted = (unsigned char*)lodepng_malloc(size);
      if(!converted && size) state->error = 83; /*alloc fail*/
      if(!state->error)
      {
        state->error = lodepng_convert(converted, image, &info.color, &state->info_raw, w, h);
      }
      if(!state->error) preProcessScanlines(&data, &datasize, converted, w, h, &info, &state->encoder);
      lodepng_free(converted);
    }
    else preProcessScanlines(&data, &datasize, image, w, h, &info, &state->encoder);
  }

  /* output all PNG chunks */
  ucvector_init(&outv);
  while(!state->error) /*while only executed once, to break on error*/
  {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    size_t i;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
    /*write signature and chunks*/
    writeSignature(&outv);
    /*IHDR*/
    addChunk_IHDR(&outv, w, h, info.color.colortype, info.color.bitdepth, info.interlace_method);
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    /*unknown chunks between IHDR and PLTE*/
    if(info.unknown_chunks_data[0])
    {
      state->error = addUnknownChunks(&outv, info.unknown_chunks_data[0], info.unknown_chunks_size[0]);
      if(state->error) break;
    }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
    /*PLTE*/
    if(info.color.colortype == LCT_PALETTE)
    {
      addChunk_PLTE(&outv, &info.color);
    }
    if(state->encoder.force_palette && (info.color.colortype == LCT_RGB || info.color.colortype == LCT_RGBA))
    {
      addChunk_PLTE(&outv, &info.color);
    }
    /*tRNS*/
    if(info.color.colortype == LCT_PALETTE && getPaletteTranslucency(info.color.palette, info.color.palettesize) != 0)
    {
      addChunk_tRNS(&outv, &info.color);
    }
    if((info.color.colortype == LCT_GREY || info.color.colortype == LCT_RGB) && info.color.key_defined)
    {
      addChunk_tRNS(&outv, &info.color);
    }
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    /*bKGD (must come between PLTE and the IDAt chunks*/
    if(info.background_defined) addChunk_bKGD(&outv, &info);
    /*pHYs (must come before the IDAT chunks)*/
    if(info.phys_defined) addChunk_pHYs(&outv, &info);

    /*unknown chunks between PLTE and IDAT*/
    if(info.unknown_chunks_data[1])
    {
      state->error = addUnknownChunks(&outv, info.unknown_chunks_data[1], info.unknown_chunks_size[1]);
      if(state->error) break;
    }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
    /*IDAT (multiple IDAT chunks must be consecutive)*/
    state->error = addChunk_IDAT(&outv, data, datasize, &state->encoder.zlibsettings);
    if(state->error) break;
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
    /*tIME*/
    if(info.time_defined) addChunk_tIME(&outv, &info.time);
    /*tEXt and/or zTXt*/
    for(i = 0; i != info.text_num; ++i)
    {
      if(strlen(info.text_keys[i]) > 79)
      {
        state->error = 66; /*text chunk too large*/
        break;
      }
      if(strlen(info.text_keys[i]) < 1)
      {
        state->error = 67; /*text chunk too small*/
        break;
      }
      if(state->encoder.text_compression)
      {
        addChunk_zTXt(&outv, info.text_keys[i], info.text_strings[i], &state->encoder.zlibsettings);
      }
      else
      {
        addChunk_tEXt(&outv, info.text_keys[i], info.text_strings[i]);
      }
    }
    /*LodePNG version id in text chunk*/
    if(state->encoder.add_id)
    {
      unsigned alread_added_id_text = 0;
      for(i = 0; i != info.text_num; ++i)
      {
        if(!strcmp(info.text_keys[i], "LodePNG"))
        {
          alread_added_id_text = 1;
          break;
        }
      }
      if(alread_added_id_text == 0)
      {
        addChunk_tEXt(&outv, "LodePNG", LODEPNG_VERSION_STRING); /*it's shorter as tEXt than as zTXt chunk*/
      }
    }
    /*iTXt*/
    for(i = 0; i != info.itext_num; ++i)
    {
      if(strlen(info.itext_keys[i]) > 79)
      {
        state->error = 66; /*text chunk too large*/
        break;
      }
      if(strlen(info.itext_keys[i]) < 1)
      {
        state->error = 67; /*text chunk too small*/
        break;
      }
      addChunk_iTXt(&outv, state->encoder.text_compression,
                    info.itext_keys[i], info.itext_langtags[i], info.itext_transkeys[i], info.itext_strings[i],
                    &state->encoder.zlibsettings);
    }

    /*unknown chunks between IDAT and IEND*/
    if(info.unknown_chunks_data[2])
    {
      state->error = addUnknownChunks(&outv, info.unknown_chunks_data[2], info.unknown_chunks_size[2]);
      if(state->error) break;
    }
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
    addChunk_IEND(&outv);

    break; /*this isn't really a while loop; no error happened so break out now!*/
  }

  lodepng_info_cleanup(&info);
  lodepng_free(data);
  /*instead of cleaning the vector up, give it to the output*/
  *out = outv.data;
  *outsize = outv.size;

  return state->error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x138(%rbp)
movq $0x0, -0x140(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x3, 0xc0(%rax)
je 0x82d3
movq -0x30(%rbp), %rax
cmpl $0x0, 0x78(%rax)
je 0x830c
movq -0x30(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x82f2
movq -0x30(%rbp), %rax
cmpq $0x100, 0xd0(%rax) # imm = 0x100
jbe 0x830c
movq -0x30(%rbp), %rax
movl $0x44, 0x198(%rax)
movl $0x44, -0x4(%rbp)
jmp 0x8b01
movq -0x30(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jbe 0x8330
movq -0x30(%rbp), %rax
movl $0x3d, 0x198(%rax)
movl $0x3d, -0x4(%rbp)
jmp 0x8b01
movq -0x30(%rbp), %rax
cmpl $0x1, 0xb8(%rax)
jbe 0x8357
movq -0x30(%rbp), %rax
movl $0x47, 0x198(%rax)
movl $0x47, -0x4(%rbp)
jmp 0x8b01
movq -0x30(%rbp), %rax
movl 0xc0(%rax), %edi
movq -0x30(%rbp), %rax
movl 0xc4(%rax), %esi
callq 0x7110
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x839b
movq -0x30(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x8b01
movq -0x30(%rbp), %rax
movl 0x88(%rax), %edi
movq -0x30(%rbp), %rax
movl 0x8c(%rax), %esi
callq 0x7110
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x83df
movq -0x30(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x8b01
leaq -0x118(%rbp), %rdi
callq 0x3980
movq -0x30(%rbp), %rsi
addq $0xb0, %rsi
leaq -0x118(%rbp), %rdi
callq 0x3b90
movq -0x30(%rbp), %rax
cmpl $0x0, 0x60(%rax)
je 0x843d
leaq -0x118(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movq -0x30(%rbp), %r8
addq $0x88, %r8
callq 0x6a80
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
jne 0x85ae
movq -0x30(%rbp), %rdi
addq $0x88, %rdi
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
callq 0x43a0
cmpl $0x0, %eax
jne 0x857b
movl -0x24(%rbp), %eax
imull -0x28(%rbp), %eax
movl %eax, %eax
movq %rax, -0x168(%rbp)
leaq -0x118(%rbp), %rdi
addq $0x10, %rdi
callq 0x30e0
movl %eax, %ecx
movq -0x168(%rbp), %rax
movl %ecx, %ecx
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
callq 0x13b0
movq %rax, -0x148(%rbp)
cmpq $0x0, -0x148(%rbp)
jne 0x84e5
cmpq $0x0, -0x150(%rbp)
je 0x84e5
movq -0x30(%rbp), %rax
movl $0x53, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
jne 0x852c
movq -0x148(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x118(%rbp), %rdx
addq $0x10, %rdx
movq -0x30(%rbp), %rcx
addq $0x88, %rcx
movl -0x24(%rbp), %r8d
movl -0x28(%rbp), %r9d
callq 0x3f90
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
jne 0x856d
movq -0x148(%rbp), %rdx
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %r8d
movq -0x30(%rbp), %rax
addq $0x30, %rax
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0x118(%rbp), %r9
movq %rax, (%rsp)
callq 0x8b10
movq -0x148(%rbp), %rdi
callq 0x1e60
jmp 0x85ac
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %r8d
movq -0x30(%rbp), %rax
addq $0x30, %rax
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0x118(%rbp), %r9
movq %rax, (%rsp)
callq 0x8b10
jmp 0x85ae
leaq -0x130(%rbp), %rdi
callq 0x8f00
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x85d3
jmp 0x8ac0
leaq -0x130(%rbp), %rdi
callq 0x8f30
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x108(%rbp), %ecx
movl -0x104(%rbp), %r8d
movl -0x110(%rbp), %r9d
leaq -0x130(%rbp), %rdi
callq 0x8fc0
cmpq $0x0, -0x60(%rbp)
je 0x8640
movq -0x60(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x9080
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x863e
jmp 0x8ac0
jmp 0x8640
cmpl $0x3, -0x108(%rbp)
jne 0x8660
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
leaq -0x130(%rbp), %rdi
callq 0x9110
movq -0x30(%rbp), %rax
cmpl $0x0, 0x78(%rax)
je 0x8693
cmpl $0x2, -0x108(%rbp)
je 0x867c
cmpl $0x6, -0x108(%rbp)
jne 0x8693
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
leaq -0x130(%rbp), %rdi
callq 0x9110
cmpl $0x3, -0x108(%rbp)
jne 0x86cb
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x91c0
cmpl $0x0, %eax
je 0x86cb
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
leaq -0x130(%rbp), %rdi
callq 0x9300
cmpl $0x0, -0x108(%rbp)
je 0x86dd
cmpl $0x2, -0x108(%rbp)
jne 0x86fd
cmpl $0x0, -0xf0(%rbp)
je 0x86fd
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
leaq -0x130(%rbp), %rdi
callq 0x9300
cmpl $0x0, -0xe0(%rbp)
je 0x8719
leaq -0x130(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x94f0
cmpl $0x0, -0x74(%rbp)
je 0x8732
leaq -0x130(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x9650
cmpq $0x0, -0x58(%rbp)
je 0x876d
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x9080
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x876b
jmp 0x8ac0
jmp 0x876d
movq -0x138(%rbp), %rsi
movq -0x140(%rbp), %rdx
movq -0x30(%rbp), %rcx
addq $0x30, %rcx
leaq -0x130(%rbp), %rdi
callq 0x96e0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x87ad
jmp 0x8ac0
cmpl $0x0, -0x90(%rbp)
je 0x87d0
leaq -0x118(%rbp), %rsi
addq $0x8c, %rsi
leaq -0x130(%rbp), %rdi
callq 0x9760
movq $0x0, -0x158(%rbp)
movq -0x158(%rbp), %rax
cmpq -0xd0(%rbp), %rax
je 0x88df
movq -0xc8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1070
cmpq $0x4f, %rax
jbe 0x881f
movq -0x30(%rbp), %rax
movl $0x42, 0x198(%rax)
jmp 0x88df
movq -0xc8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1070
cmpq $0x1, %rax
jae 0x884f
movq -0x30(%rbp), %rax
movl $0x43, 0x198(%rax)
jmp 0x88df
movq -0x30(%rbp), %rax
cmpl $0x0, 0x80(%rax)
je 0x8896
movq -0xc8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0xc0(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x30(%rbp), %rcx
addq $0x30, %rcx
leaq -0x130(%rbp), %rdi
callq 0x9850
jmp 0x88c6
movq -0xc8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0xc0(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq -0x130(%rbp), %rdi
callq 0x99a0
jmp 0x88c8
movq -0x158(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x158(%rbp)
jmp 0x87db
movq -0x30(%rbp), %rax
cmpl $0x0, 0x7c(%rax)
je 0x897c
movl $0x0, -0x15c(%rbp)
movq $0x0, -0x158(%rbp)
movq -0x158(%rbp), %rax
cmpq -0xd0(%rbp), %rax
je 0x8957
movq -0xc8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xbc12(%rip), %rsi      # 0x1453d
callq 0x10a0
cmpl $0x0, %eax
jne 0x8941
movl $0x1, -0x15c(%rbp)
jmp 0x8957
jmp 0x8943
movq -0x158(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x158(%rbp)
jmp 0x8902
cmpl $0x0, -0x15c(%rbp)
jne 0x897a
movq 0x10749(%rip), %rdx     # 0x190b0
leaq -0x130(%rbp), %rdi
leaq 0xbbc8(%rip), %rsi      # 0x1453d
callq 0x99a0
jmp 0x897c
movq $0x0, -0x158(%rbp)
movq -0x158(%rbp), %rax
cmpq -0xb8(%rbp), %rax
je 0x8a7c
movq -0xb0(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1070
cmpq $0x4f, %rax
jbe 0x89cb
movq -0x30(%rbp), %rax
movl $0x42, 0x198(%rax)
jmp 0x8a7c
movq -0xb0(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1070
cmpq $0x1, %rax
jae 0x89fb
movq -0x30(%rbp), %rax
movl $0x43, 0x198(%rax)
jmp 0x8a7c
movq -0x30(%rbp), %rax
movl 0x80(%rax), %esi
movq -0xb0(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0xa8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0xa0(%rbp), %rax
movq -0x158(%rbp), %rdi
movq (%rax,%rdi,8), %r8
movq -0x98(%rbp), %rax
movq -0x158(%rbp), %rdi
movq (%rax,%rdi,8), %r9
movq -0x30(%rbp), %rax
addq $0x30, %rax
leaq -0x130(%rbp), %rdi
movq %rax, (%rsp)
callq 0x9aa0
movq -0x158(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x158(%rbp)
jmp 0x8987
cmpq $0x0, -0x50(%rbp)
je 0x8ab4
movq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x9080
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x8ab2
jmp 0x8ac0
jmp 0x8ab4
leaq -0x130(%rbp), %rdi
callq 0x9cf0
leaq -0x118(%rbp), %rdi
callq 0x3b10
movq -0x138(%rbp), %rdi
callq 0x1e60
movq -0x130(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x128(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax)