// File: /workspace/github_cpp_makefile_star2_O3/phillip-h[P]fractal-gen/lodepng.cpp
// Function: lodepng_encode(unsigned char**, unsigned long*, unsigned char const*, unsigned int, unsigned int, LodePNGState*)
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 * (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);

  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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %ecx, %r12d
movabsq $0x800000006, %rcx      # imm = 0x800000006
leaq 0x70(%rsp), %r14
vxorps %xmm0, %xmm0, %xmm0
xorl %eax, %eax
movq %rax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movq %rax, (%rdi)
movq %rax, (%rsi)
movq %rsi, 0x68(%rsp)
movl %eax, 0x1a0(%r9)
leaq 0xb8(%r9), %rsi
movq %rdi, %r15
movq %r9, %rbx
movl %r8d, %ebp
movq %rdx, %r13
movq %rcx, 0x10(%r14)
vmovups %ymm0, 0x18(%r14)
movl %eax, 0x8(%r14)
movq %rax, (%r14)
movl %eax, 0xa4(%r14)
vmovups %ymm0, 0xb8(%r14)
vmovups %ymm0, 0xc8(%r14)
vxorps %xmm0, %xmm0, %xmm0
movq %r14, %rdi
vmovups %zmm0, 0x38(%r14)
vmovups %zmm0, 0x4c(%r14)
vzeroupper
callq 0x7d17
cmpl $0x3, 0x10(%r14)
je 0xadbc
cmpl $0x0, 0x80(%rbx)
je 0xade7
movq 0x90(%rsp), %rcx
movq $-0x101, %rax           # imm = 0xFEFF
addq %rax, %rcx
cmpq %rax, %rcx
ja 0xade7
movl $0x44, 0x1a0(%rbx)
movl $0x44, %eax
jmp 0xaffc
cmpl $0x0, 0x68(%rbx)
leaq 0x80(%rsp), %rdi
je 0xae11
leaq 0x90(%rbx), %r8
movq %r13, %rsi
movl %r12d, %edx
movl %ebp, %ecx
callq 0x95dd
movl %eax, 0x1a0(%rbx)
jmp 0xae17
movl 0x1a0(%rbx), %eax
testl %eax, %eax
jne 0xaffc
leaq 0x38(%rbx), %r14
cmpl $0x3, (%r14)
jb 0xae3d
movl $0x3d, 0x1a0(%rbx)
movl $0x3d, %eax
jmp 0xaffc
cmpl $0x2, 0xc0(%rbx)
jb 0xae5a
movl $0x47, 0x1a0(%rbx)
movl $0x47, %eax
jmp 0xaffc
movq %r15, 0x60(%rsp)
movl 0x80(%rsp), %edi
movl 0x84(%rsp), %r15d
movq %rdi, 0x38(%rsp)
movl %r15d, %esi
callq 0x9a4f
movl %eax, 0x1a0(%rbx)
testl %eax, %eax
jne 0xaffc
movl 0x90(%rbx), %edi
movl 0x94(%rbx), %esi
movl %r15d, 0x40(%rsp)
callq 0x9a4f
movl %eax, 0x1a0(%rbx)
testl %eax, %eax
jne 0xaffc
leaq 0x90(%rbx), %r15
leaq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0x840e
testl %eax, %eax
je 0xaeee
leaq 0x48(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x70(%rsp), %r9
movq %r14, (%rsp)
movq %r13, %rdx
movl %r12d, %ecx
movl %ebp, %r8d
callq 0xb357
jmp 0xafa7
movq 0x38(%rsp), %rdx
movl %ebp, %eax
imull %r12d, %eax
movq %r14, 0x30(%rsp)
movq %r15, 0x58(%rsp)
xorl %r14d, %r14d
cmpl $0x6, %edx
ja 0xaf16
leaq 0x72b2(%rip), %rcx      # 0x121c4
movl (%rcx,%rdx,4), %r14d
imull 0x40(%rsp), %r14d
imulq %rax, %r14
leaq 0x7(%r14), %rdi
shrq $0x3, %rdi
callq 0x21e0
testq %rax, %rax
movq %rax, %r15
setne %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0xaf51
movq 0x30(%rsp), %r14
movl $0x53, 0x1a0(%rbx)
jmp 0xaf9f
movq 0x58(%rsp), %rcx
leaq 0x80(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
movl %r12d, %r8d
movl %ebp, %r9d
callq 0x7fac
movq 0x30(%rsp), %r14
movl %eax, 0x1a0(%rbx)
testl %eax, %eax
jne 0xaf9f
leaq 0x48(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x70(%rsp), %r9
movq %r14, (%rsp)
movq %r15, %rdx
movl %r12d, %ecx
movl %ebp, %r8d
callq 0xb357
movq %r15, %rdi
callq 0x21b0
vxorps %xmm0, %xmm0, %xmm0
movq $0x0, 0x20(%rsp)
movl 0x40(%rsp), %r13d
vmovaps %xmm0, 0x10(%rsp)
cmpl $0x0, 0x1a0(%rbx)
je 0xb00e
leaq 0x70(%rsp), %rdi
callq 0x7cc4
movq 0x48(%rsp), %rdi
callq 0x21b0
movq 0x10(%rsp), %rax
movq 0x60(%rsp), %rcx
movq %rax, (%rcx)
movq 0x68(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rax, (%rcx)
movl 0x1a0(%rbx), %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x30(%rsp)
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0xb8c0
movl 0x78(%rsp), %r9d
movq %r14, %rdi
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rcx
movl %r12d, %esi
movl %ebp, %edx
movl %r13d, %r8d
callq 0xb9e4
movq 0x128(%rsp), %rsi
testq %rsi, %rsi
je 0xb06c
movq 0x140(%rsp), %rdx
leaq 0x10(%rsp), %rdi
callq 0xbc0a
movl %eax, 0x1a0(%rbx)
testl %eax, %eax
jne 0xafc8
movq 0x38(%rsp), %rcx
cmpl $0x3, %ecx
jne 0xb0a3
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xbc73
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0xbd63
testl %eax, %eax
jne 0xb0df
jmp 0xb0f1
movl %ecx, %eax
andl $-0x5, %eax
cmpl $0x2, %eax
jne 0xb0cd
cmpl $0x0, 0x80(%rbx)
je 0xb0cd
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xbc73
movq 0x38(%rsp), %rcx
testl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
jne 0xb0f1
cmpl $0x0, 0x98(%rsp)
je 0xb0f1
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xbe05
cmpl $0x0, 0xa8(%rsp)
je 0xb10a
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xc1b6
cmpl $0x0, 0x114(%rsp)
je 0xb123
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xc4af
movq 0x130(%rsp), %rsi
testq %rsi, %rsi
je 0xb150
movq 0x148(%rsp), %rdx
leaq 0x10(%rsp), %rdi
callq 0xbc0a
movl %eax, 0x1a0(%rbx)
testl %eax, %eax
jne 0xafc8
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0x10(%rsp), %rdi
movq %r14, %rcx
callq 0xc57e
movl %eax, 0x1a0(%rbx)
testl %eax, %eax
jne 0xafc8
cmpl $0x0, 0xf8(%rsp)
je 0xb191
leaq 0xfc(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0xc60d
movq 0xb8(%rsp), %r14
testq %r14, %r14
je 0xb1f9
movq 0xc0(%rsp), %rbp
movq 0xc8(%rsp), %r15
xorl %r12d, %r12d
movq (%rbp,%r12,8), %r13
movq %r13, %rdi
callq 0x2090
cmpq $0x4f, %rax
ja 0xb204
testq %rax, %rax
je 0xb20b
cmpl $0x0, 0x88(%rbx)
movq (%r15,%r12,8), %rdx
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
je 0xb1ea
movq 0x30(%rsp), %rcx
callq 0xc684
jmp 0xb1ef
callq 0xc90a
incq %r12
cmpq %r12, %r14
jne 0xb1b1
jmp 0xb216
cmpl $0x0, 0x84(%rbx)
jne 0xb24e
jmp 0xb266
movl $0x42, %eax
jmp 0xb210
movl $0x43, %eax
movl %eax, 0x1a0(%rbx)
cmpl $0x0, 0x84(%rbx)
je 0xb266
testq %r14, %r14
je 0xb24e
movq 0xc0(%rsp), %r13
xorl %ebp, %ebp
leaq 0x7138(%rip), %r12      # 0x1236d
movq (%r13,%rbp,8), %rdi
movq %r12, %rsi
callq 0x21f0
testl %eax, %eax
je 0xb266
incq %rbp
cmpq %rbp, %r14
jne 0xb235
movq 0xbf2b(%rip), %rdx      # 0x17180
leaq 0x7111(%rip), %rsi      # 0x1236d
leaq 0x10(%rsp), %rdi
callq 0xc90a
movq 0xd0(%rsp), %r14
testq %r14, %r14
je 0xb30a
movq 0xe8(%rsp), %rax
movq 0xf0(%rsp), %rcx
movq 0xd8(%rsp), %rbp
movq 0xe0(%rsp), %r15
xorl %r12d, %r12d
movq %rax, 0x38(%rsp)
movq %rcx, 0x40(%rsp)
movq (%rbp,%r12,8), %r13
movq %r13, %rdi
callq 0x2090
cmpq $0x4f, %rax
ja 0xb2f8
testq %rax, %rax
je 0xb2ff
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rdi
movl 0x88(%rbx), %esi
movq (%r15,%r12,8), %rcx
movq 0x30(%rsp), %rdx
movq (%rdi,%r12,8), %r9
movq (%rax,%r12,8), %r8
leaq 0x10(%rsp), %rdi
movq %rdx, (%rsp)
movq %r13, %rdx
callq 0xcaa8
incq %r12
cmpq %r12, %r14
jne 0xb2a4
jmp 0xb30a
movl $0x42, %eax
jmp 0xb304
movl $0x43, %eax
movl %eax, 0x1a0(%rbx)
movq 0x138(%rsp), %rsi
testq %rsi, %rsi
je 0xb337
movq 0x150(%rsp), %rdx
leaq 0x10(%rsp), %rdi
callq 0xbc0a
movl %eax, 0x1a0(%rbx)
testl %eax, %eax
jne 0xafc8
leaq 0x18(%rsp), %rsi
leaq 0x7f15(%rip), %rcx      # 0x13258
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x74dc
jmp 0xafc8