// File: /workspace/github_c_makefile_star2_O0/pje[P]pixelsort/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;

  lodepng_info_init(&info);
  lodepng_info_copy(&info, &state->info_png);

  if((info.color.colortype == LCT_PALETTE || state->encoder.force_palette)
      && (info.color.palettesize == 0 || info.color.palettesize > 256))
  {
    state->error = 68; /*invalid palette size, it is only allowed to be 1-256*/
    return state->error;
  }

  if(state->encoder.auto_convert)
  {
    state->error = lodepng_auto_choose_color(&info.color, image, w, h, &state->info_raw);
  }
  if(state->error) return state->error;

  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(info.color.colortype, info.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*/

  if(!lodepng_color_mode_equal(&state->info_raw, &info.color))
  {
    unsigned char* converted;
    size_t size = (w * h * 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);

  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", 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)
leaq -0x118(%rbp), %rdi
callq 0x35d0
movq -0x30(%rbp), %rsi
addq $0xb0, %rsi
leaq -0x118(%rbp), %rdi
callq 0x37e0
cmpl $0x3, -0x108(%rbp)
je 0x7a12
movq -0x30(%rbp), %rax
cmpl $0x0, 0x78(%rax)
je 0x7a49
cmpq $0x0, -0xf8(%rbp)
je 0x7a29
cmpq $0x100, -0xf8(%rbp) # imm = 0x100
jbe 0x7a49
movq -0x30(%rbp), %rax
movl $0x44, 0x198(%rax)
movq -0x30(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x8218
movq -0x30(%rbp), %rax
cmpl $0x0, 0x60(%rax)
je 0x7a84
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 0x6440
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x7aa3
movq -0x30(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x8218
movq -0x30(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jbe 0x7ac7
movq -0x30(%rbp), %rax
movl $0x3d, 0x198(%rax)
movl $0x3d, -0x4(%rbp)
jmp 0x8218
movq -0x30(%rbp), %rax
cmpl $0x1, 0xb8(%rax)
jbe 0x7aee
movq -0x30(%rbp), %rax
movl $0x47, 0x198(%rax)
movl $0x47, -0x4(%rbp)
jmp 0x8218
movl -0x108(%rbp), %edi
movl -0x104(%rbp), %esi
callq 0x6ae0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x7b2a
movq -0x30(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x8218
movq -0x30(%rbp), %rax
movl 0x88(%rax), %edi
movq -0x30(%rbp), %rax
movl 0x8c(%rax), %esi
callq 0x6ae0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x7b6e
movq -0x30(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x8218
movq -0x30(%rbp), %rdi
addq $0x88, %rdi
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
callq 0x3f90
cmpl $0x0, %eax
jne 0x7c94
movl -0x24(%rbp), %eax
imull -0x28(%rbp), %eax
movl %eax, -0x160(%rbp)
leaq -0x118(%rbp), %rdi
addq $0x10, %rdi
callq 0x2d60
movl %eax, %ecx
movl -0x160(%rbp), %eax
imull %ecx, %eax
addl $0x7, %eax
shrl $0x3, %eax
movl %eax, %eax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
callq 0x13a0
movq %rax, -0x148(%rbp)
cmpq $0x0, -0x148(%rbp)
jne 0x7bfe
cmpq $0x0, -0x150(%rbp)
je 0x7bfe
movq -0x30(%rbp), %rax
movl $0x53, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
jne 0x7c45
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 0x3be0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
jne 0x7c86
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 0x8230
movq -0x148(%rbp), %rdi
callq 0x1840
jmp 0x7cc5
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 0x8230
leaq -0x130(%rbp), %rdi
callq 0x8620
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7cea
jmp 0x81d7
leaq -0x130(%rbp), %rdi
callq 0x8650
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 0x86e0
cmpq $0x0, -0x60(%rbp)
je 0x7d57
movq -0x60(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x87a0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x7d55
jmp 0x81d7
jmp 0x7d57
cmpl $0x3, -0x108(%rbp)
jne 0x7d77
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
leaq -0x130(%rbp), %rdi
callq 0x8830
movq -0x30(%rbp), %rax
cmpl $0x0, 0x78(%rax)
je 0x7daa
cmpl $0x2, -0x108(%rbp)
je 0x7d93
cmpl $0x6, -0x108(%rbp)
jne 0x7daa
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
leaq -0x130(%rbp), %rdi
callq 0x8830
cmpl $0x3, -0x108(%rbp)
jne 0x7de2
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x88e0
cmpl $0x0, %eax
je 0x7de2
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
leaq -0x130(%rbp), %rdi
callq 0x8a20
cmpl $0x0, -0x108(%rbp)
je 0x7df4
cmpl $0x2, -0x108(%rbp)
jne 0x7e14
cmpl $0x0, -0xf0(%rbp)
je 0x7e14
leaq -0x118(%rbp), %rsi
addq $0x10, %rsi
leaq -0x130(%rbp), %rdi
callq 0x8a20
cmpl $0x0, -0xe0(%rbp)
je 0x7e30
leaq -0x130(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x8c10
cmpl $0x0, -0x74(%rbp)
je 0x7e49
leaq -0x130(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x8d70
cmpq $0x0, -0x58(%rbp)
je 0x7e84
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x87a0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x7e82
jmp 0x81d7
jmp 0x7e84
movq -0x138(%rbp), %rsi
movq -0x140(%rbp), %rdx
movq -0x30(%rbp), %rcx
addq $0x30, %rcx
leaq -0x130(%rbp), %rdi
callq 0x8e00
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x7ec4
jmp 0x81d7
cmpl $0x0, -0x90(%rbp)
je 0x7ee7
leaq -0x118(%rbp), %rsi
addq $0x8c, %rsi
leaq -0x130(%rbp), %rdi
callq 0x8e80
movq $0x0, -0x158(%rbp)
movq -0x158(%rbp), %rax
cmpq -0xd0(%rbp), %rax
jae 0x7ff6
movq -0xc8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1080
cmpq $0x4f, %rax
jbe 0x7f36
movq -0x30(%rbp), %rax
movl $0x42, 0x198(%rax)
jmp 0x7ff6
movq -0xc8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1080
cmpq $0x1, %rax
jae 0x7f66
movq -0x30(%rbp), %rax
movl $0x43, 0x198(%rax)
jmp 0x7ff6
movq -0x30(%rbp), %rax
cmpl $0x0, 0x80(%rax)
je 0x7fad
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 0x8f70
jmp 0x7fdd
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 0x90c0
jmp 0x7fdf
movq -0x158(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x158(%rbp)
jmp 0x7ef2
movq -0x30(%rbp), %rax
cmpl $0x0, 0x7c(%rax)
je 0x8093
movl $0x0, -0x15c(%rbp)
movq $0x0, -0x158(%rbp)
movq -0x158(%rbp), %rax
cmpq -0xd0(%rbp), %rax
jae 0x806e
movq -0xc8(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xb4e0(%rip), %rsi      # 0x13522
callq 0x10d0
cmpl $0x0, %eax
jne 0x8058
movl $0x1, -0x15c(%rbp)
jmp 0x806e
jmp 0x805a
movq -0x158(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x158(%rbp)
jmp 0x8019
cmpl $0x0, -0x15c(%rbp)
jne 0x8091
leaq -0x130(%rbp), %rdi
leaq 0xb49d(%rip), %rsi      # 0x13522
leaq 0xb49e(%rip), %rdx      # 0x1352a
callq 0x90c0
jmp 0x8093
movq $0x0, -0x158(%rbp)
movq -0x158(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jae 0x8193
movq -0xb0(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1080
cmpq $0x4f, %rax
jbe 0x80e2
movq -0x30(%rbp), %rax
movl $0x42, 0x198(%rax)
jmp 0x8193
movq -0xb0(%rbp), %rax
movq -0x158(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1080
cmpq $0x1, %rax
jae 0x8112
movq -0x30(%rbp), %rax
movl $0x43, 0x198(%rax)
jmp 0x8193
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 0x91c0
movq -0x158(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x158(%rbp)
jmp 0x809e
cmpq $0x0, -0x50(%rbp)
je 0x81cb
movq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x87a0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x198(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x198(%rax)
je 0x81c9
jmp 0x81d7
jmp 0x81cb
leaq -0x130(%rbp), %rdi
callq 0x9410
leaq -0x118(%rbp), %rdi
callq 0x3760
movq -0x138(%rbp), %rdi
callq 0x1840
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
nopw %cs:(%rax,%rax)