// File: /workspace/github_cpp_makefile_star2_O3/phillip-h[P]fractal-gen/lodepng.cpp
// Function: lodepng_convert(unsigned char*, unsigned char const*, LodePNGColorMode const*, LodePNGColorMode const*, unsigned int, unsigned int)
unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
                         const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in,
                         unsigned w, unsigned h)
{
  size_t i;
  ColorTree tree;
  size_t numpixels = w * h;

  if(lodepng_color_mode_equal(mode_out, mode_in))
  {
    size_t numbytes = lodepng_get_raw_size(w, h, mode_in);
    for(i = 0; i != numbytes; ++i) out[i] = in[i];
    return 0;
  }

  if(mode_out->colortype == LCT_PALETTE)
  {
    size_t palettesize = mode_out->palettesize;
    const unsigned char* palette = mode_out->palette;
    size_t palsize = 1u << mode_out->bitdepth;
    /*if the user specified output palette but did not give the values, assume
    they want the values of the input color type (assuming that one is palette).
    Note that we never create a new palette ourselves.*/
    if(palettesize == 0)
    {
      palettesize = mode_in->palettesize;
      palette = mode_in->palette;
    }
    if(palettesize < palsize) palsize = palettesize;
    color_tree_init(&tree);
    for(i = 0; i != palsize; ++i)
    {
      const unsigned char* p = &palette[i * 4];
      color_tree_add(&tree, p[0], p[1], p[2], p[3], i);
    }
  }

  if(mode_in->bitdepth == 16 && mode_out->bitdepth == 16)
  {
    for(i = 0; i != numpixels; ++i)
    {
      unsigned short r = 0, g = 0, b = 0, a = 0;
      getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in);
      rgba16ToPixel(out, i, mode_out, r, g, b, a);
    }
  }
  else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGBA)
  {
    getPixelColorsRGBA8(out, numpixels, 1, in, mode_in);
  }
  else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGB)
  {
    getPixelColorsRGBA8(out, numpixels, 0, in, mode_in);
  }
  else
  {
    unsigned char r = 0, g = 0, b = 0, a = 0;
    for(i = 0; i != numpixels; ++i)
    {
      getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in);
      CERROR_TRY_RETURN(rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a));
    }
  }

  if(mode_out->colortype == LCT_PALETTE)
  {
    color_tree_cleanup(&tree);
  }

  return 0; /*no error*/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl %r9d, %ebp
movl %r8d, %r12d
movq %rcx, %r15
movq %rdx, %r13
movq %rdx, %rdi
movq %rcx, %rsi
callq 0x840e
testl %eax, %eax
je 0x800d
movl %r12d, %edi
movl %ebp, %esi
movq %r15, %rdx
callq 0x77be
xorl %r15d, %r15d
testq %rax, %rax
je 0x83ee
xorl %ecx, %ecx
movb (%r14,%rcx), %dl
movb %dl, (%rbx,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x7ff9
jmp 0x83ee
imull %r12d, %ebp
cmpl $0x3, (%r13)
movq %rbx, 0x20(%rsp)
movq %r13, 0x28(%rsp)
movq %rbp, 0x18(%rsp)
jne 0x80bb
movq 0x28(%rsp), %rsi
movl $0x1, %edx
movb 0x4(%rsi), %cl
movq 0x10(%rsi), %rax
shlxq %rcx, %rdx, %rbx
movq %rsi, %rcx
testq %rax, %rax
jne 0x8050
movq 0x10(%r15), %rax
movq %r15, %rcx
movq 0x8(%rcx), %rbp
cmpq %rbx, %rax
vpxor %xmm0, %xmm0, %xmm0
cmovbq %rax, %rbx
vmovdqu64 %zmm0, 0x70(%rsp)
vmovdqu64 %zmm0, 0x30(%rsp)
movl $0xffffffff, 0xb0(%rsp) # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x80bb
leaq 0x30(%rsp), %r12
xorl %r13d, %r13d
movzbl (%rbp,%r13,4), %esi
movzbl 0x1(%rbp,%r13,4), %edx
movzbl 0x2(%rbp,%r13,4), %ecx
movzbl 0x3(%rbp,%r13,4), %r8d
movq %r12, %rdi
movl %r13d, %r9d
vzeroupper
callq 0x847b
incq %r13
cmpq %r13, %rbx
jne 0x808d
movq 0x28(%rsp), %rbp
movl 0x4(%r15), %ecx
movl 0x4(%rbp), %eax
xorl $0x10, %ecx
movl %eax, %edx
xorl $0x10, %edx
orl %ecx, %edx
jne 0x81de
cmpq $0x0, 0x18(%rsp)
je 0x83d4
leaq 0x94b6(%rip), %r13      # 0x115a0
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %ebp, %ebp
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movw %r12w, 0x16(%rsp)
movw %r12w, 0x14(%rsp)
movw %r12w, 0x12(%rsp)
movw %r12w, 0x10(%rsp)
movq %r15, (%rsp)
movq %r14, %r8
movq %rbp, %r9
vzeroupper
callq 0x8530
movq 0x28(%rsp), %rax
movl (%rax), %esi
cmpq $0x6, %rsi
ja 0x81c7
movslq (%r13,%rsi,4), %rsi
movzwl 0x16(%rsp), %eax
movzwl 0x14(%rsp), %edx
movzwl 0x12(%rsp), %edi
movzwl 0x10(%rsp), %ecx
addq %r13, %rsi
jmpq *%rsi
movq 0x20(%rsp), %rcx
movbew %ax, (%rcx,%rbp,2)
jmp 0x81c7
movq 0x20(%rsp), %rdx
movb %ah, (%rdx,%rbp,4)
movb %al, 0x1(%rdx,%rbp,4)
movb %ch, 0x2(%rdx,%rbp,4)
movb %cl, 0x3(%rdx,%rbp,4)
jmp 0x81c7
movq 0x20(%rsp), %rcx
movb %ah, (%rcx,%rbx)
movb %al, 0x1(%rcx,%rbx)
movb %dh, 0x2(%rcx,%rbx)
movb %dl, 0x3(%rcx,%rbx)
movl %edi, %eax
movb %ah, 0x4(%rcx,%rbx)
movb %al, 0x5(%rcx,%rbx)
jmp 0x81c7
movq 0x20(%rsp), %rsi
movb %ah, (%rsi,%rbp,8)
movb %al, 0x1(%rsi,%rbp,8)
movb %dh, 0x2(%rsi,%rbp,8)
movb %dl, 0x3(%rsi,%rbp,8)
movl %edi, %eax
movb %ah, 0x4(%rsi,%rbp,8)
movb %al, 0x5(%rsi,%rbp,8)
movb %ch, 0x6(%rsi,%rbp,8)
movb %cl, 0x7(%rsi,%rbp,8)
incq %rbp
addq $0x6, %rbx
cmpq %rbp, 0x18(%rsp)
jne 0x80f1
jmp 0x83d4
movq 0x20(%rsp), %rbx
cmpl $0x8, %eax
jne 0x820b
movl (%rbp), %eax
cmpl $0x2, %eax
je 0x83bc
cmpl $0x6, %eax
jne 0x820b
movq 0x18(%rsp), %rsi
movl $0x1, %edx
movq %rbx, %rdi
jmp 0x83c6
xorl %eax, %eax
cmpq $0x0, 0x18(%rsp)
movb %al, 0x16(%rsp)
movb %al, 0x14(%rsp)
movb %al, 0x12(%rsp)
movb %al, 0x10(%rsp)
je 0x83d4
xorl %r12d, %r12d
xorl %r13d, %r13d
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r15, (%rsp)
movq %r14, %r8
movq %r13, %r9
vzeroupper
callq 0x8ae3
movl (%rbp), %r8d
cmpq $0x6, %r8
ja 0x83a8
leaq 0x931a(%rip), %r9       # 0x11584
movb 0x16(%rsp), %al
movb 0x14(%rsp), %dl
movb 0x12(%rsp), %cl
movb 0x10(%rsp), %dil
movslq (%r9,%r8,4), %r8
movzbl %al, %esi
addq %r9, %r8
jmpq *%r8
movl 0x4(%rbp), %edx
cmpl $0x10, %edx
je 0x838a
cmpl $0x8, %edx
je 0x82da
movb $0x8, %al
movq %rbx, %rdi
subb %dl, %al
shrxl %eax, %esi, %eax
movq %r13, %rsi
bzhil %edx, %eax, %ecx
jmp 0x8383
movzbl %dil, %r8d
movzbl %dl, %edx
movzbl %cl, %ecx
leaq 0x30(%rsp), %rdi
callq 0xe9cc
testl %eax, %eax
js 0x8406
movl 0x4(%rbp), %edx
cmpl $0x8, %edx
jne 0x837b
movb %al, (%rbx,%r13)
jmp 0x83a8
cmpl $0x8, 0x4(%rbp)
jne 0x833a
movb %al, (%rbx,%r12)
movb %dl, 0x1(%rbx,%r12)
movb %cl, 0x2(%rbx,%r12)
jmp 0x83a8
movl 0x4(%rbp), %ecx
cmpl $0x10, %ecx
je 0x8395
cmpl $0x8, %ecx
jne 0x83a8
movb %al, (%rbx,%r13,2)
movb %dil, 0x1(%rbx,%r13,2)
jmp 0x83a8
cmpl $0x8, 0x4(%rbp)
jne 0x8359
movb %al, (%rbx,%r13,4)
movb %dl, 0x1(%rbx,%r13,4)
movb %cl, 0x2(%rbx,%r13,4)
movb %dil, 0x3(%rbx,%r13,4)
jmp 0x83a8
movb %al, 0x1(%rbx,%r12,2)
movb %al, (%rbx,%r12,2)
movb %dl, 0x3(%rbx,%r12,2)
movb %dl, 0x2(%rbx,%r12,2)
movb %cl, 0x5(%rbx,%r12,2)
movb %cl, 0x4(%rbx,%r12,2)
jmp 0x83a8
vmovd %eax, %xmm0
vpinsrb $0x1, %edx, %xmm0, %xmm0
vpinsrb $0x2, %ecx, %xmm0, %xmm0
vpinsrb $0x3, %edi, %xmm0, %xmm0
vpunpcklbw %xmm0, %xmm0, %xmm0 # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
vmovq %xmm0, (%rbx,%r13,8)
jmp 0x83a8
movq %rbx, %rdi
movq %r13, %rsi
movl %eax, %ecx
callq 0xe985
jmp 0x83a8
movb %al, 0x1(%rbx,%r13,2)
movb %al, (%rbx,%r13,2)
jmp 0x83a8
movb %al, 0x1(%rbx,%r13,4)
movb %al, (%rbx,%r13,4)
movb %dil, 0x3(%rbx,%r13,4)
movb %dil, 0x2(%rbx,%r13,4)
incq %r13
addq $0x3, %r12
cmpq %r13, 0x18(%rsp)
jne 0x822f
jmp 0x83d4
movq 0x18(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r14, %rcx
movq %r15, %r8
vzeroupper
callq 0x866c
movq 0x28(%rsp), %rax
xorl %r15d, %r15d
cmpl $0x3, (%rax)
jne 0x83ee
leaq 0x30(%rsp), %rdi
vzeroupper
callq 0x8dc4
movl %r15d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
movl $0x52, %r15d
jmp 0x83ee