// File: /workspace/github_c_makefile_star2_O2/pje[P]pixelsort/lodepng.c
// Function: lodepng_convert
unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
                         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 palsize = 1u << mode_out->bitdepth;
    if(mode_out->palettesize < palsize) palsize = mode_out->palettesize;
    color_tree_init(&tree);
    for(i = 0; i < palsize; i++)
    {
      unsigned char* p = &mode_out->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);
      rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a);
    }
  }

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

  return 0; /*no error (this function currently never has one, but maybe OOM detection added later.)*/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r9d, %r13d
movl %r8d, %r12d
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbp
movq %rdx, %rdi
movq %rcx, %rsi
callq 0x3e8e
testl %eax, %eax
je 0x3add
movl %r12d, %edi
movl %r13d, %esi
movq %rbx, %rdx
callq 0x3400
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x3e7a
movb (%r15,%rcx), %dl
movb %dl, (%rbp,%rcx)
incq %rcx
jmp 0x3ac7
movq %rbx, 0x18(%rsp)
imull %r12d, %r13d
movq %r13, 0x10(%rsp)
cmpl $0x3, (%r14)
jne 0x3b46
movb 0x4(%r14), %cl
pushq $0x1
popq %rbx
shlq %cl, %rbx
movq 0x10(%r14), %rax
cmpq %rbx, %rax
cmovbq %rax, %rbx
leaq 0x20(%rsp), %r13
movq %r13, %rdi
callq 0x3efa
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x3b46
movq 0x8(%r14), %rax
movzbl (%rax,%r12,4), %esi
movzbl 0x1(%rax,%r12,4), %edx
movzbl 0x2(%rax,%r12,4), %ecx
movzbl 0x3(%rax,%r12,4), %r8d
movq %r13, %rdi
movl %r12d, %r9d
callq 0x3f14
incq %r12
jmp 0x3b16
movq 0x18(%rsp), %rbx
movl 0x4(%rbx), %ecx
xorl $0x10, %ecx
movl 0x4(%r14), %eax
movl %eax, %edx
xorl $0x10, %edx
orl %ecx, %edx
jne 0x3c60
movq %rbp, %r13
pushq $0x5
popq %rdi
xorl %ebp, %ebp
leaq 0x74fb(%rip), %r12      # 0xb06c
cmpq %rbp, 0x10(%rsp)
je 0x3e6a
andw $0x0, 0xe(%rsp)
andw $0x0, 0xc(%rsp)
andw $0x0, 0xa(%rsp)
andw $0x0, 0x8(%rsp)
movq %rbx, (%rsp)
movq %rdi, %rbx
leaq 0xe(%rsp), %rdi
leaq 0xc(%rsp), %rsi
leaq 0xa(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %r8
movq %rbp, %r9
callq 0x3fb5
movq %rbx, %rdi
movl (%r14), %esi
cmpq $0x6, %rsi
ja 0x3c4f
movzwl 0xe(%rsp), %ebx
movzwl 0xc(%rsp), %edx
movzwl 0xa(%rsp), %eax
movzwl 0x8(%rsp), %ecx
movslq (%r12,%rsi,4), %rsi
addq %r12, %rsi
jmpq *%rsi
rolw $0x8, %bx
movw %bx, (%r13,%rbp,2)
jmp 0x3c4f
movq %r13, %rax
movb %bh, (%rax,%rbp,4)
movb %bl, 0x1(%r13,%rbp,4)
movb %ch, 0x2(%rax,%rbp,4)
movb %cl, 0x3(%r13,%rbp,4)
jmp 0x3c4f
movq %r13, %rcx
movb %bh, -0x5(%rcx,%rdi)
movb %bl, -0x4(%r13,%rdi)
movb %dh, -0x3(%rcx,%rdi)
movb %dl, -0x2(%r13,%rdi)
movb %ah, -0x1(%rcx,%rdi)
movb %al, (%r13,%rdi)
jmp 0x3c4f
movq %r13, %rsi
movb %bh, (%rsi,%rbp,8)
movb %bl, 0x1(%r13,%rbp,8)
movb %dh, 0x2(%rsi,%rbp,8)
movb %dl, 0x3(%r13,%rbp,8)
movb %ah, 0x4(%rsi,%rbp,8)
movb %al, 0x5(%r13,%rbp,8)
movb %ch, 0x6(%rsi,%rbp,8)
movb %cl, 0x7(%r13,%rbp,8)
incq %rbp
addq $0x6, %rdi
movq 0x18(%rsp), %rbx
jmp 0x3b71
cmpl $0x8, %eax
jne 0x3c86
movl (%r14), %eax
cmpl $0x2, %eax
je 0x3e55
cmpl $0x6, %eax
jne 0x3c86
pushq $0x1
popq %rdx
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
jmp 0x3e5f
xorl %r12d, %r12d
leaq 0xe(%rsp), %rax
movb %r12b, (%rax)
leaq 0xc(%rsp), %rax
movb %r12b, (%rax)
leaq 0xa(%rsp), %rax
movb %r12b, (%rax)
leaq 0x8(%rsp), %rax
movb %r12b, (%rax)
xorl %r13d, %r13d
cmpq %r13, 0x10(%rsp)
je 0x3e6a
movq %rbx, (%rsp)
leaq 0xe(%rsp), %rdi
leaq 0xc(%rsp), %rsi
leaq 0xa(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %r8
movq %r13, %r9
callq 0x4516
movl (%r14), %r8d
cmpq $0x6, %r8
ja 0x3e49
movb 0xe(%rsp), %al
movzbl %al, %esi
movb 0xc(%rsp), %dl
movb 0xa(%rsp), %cl
movb 0x8(%rsp), %dil
leaq 0x734e(%rip), %r9       # 0xb050
movslq (%r9,%r8,4), %r8
addq %r9, %r8
jmpq *%r8
movl 0x4(%r14), %edx
cmpl $0x10, %edx
je 0x3e09
cmpl $0x8, %edx
jne 0x3e2b
movb %al, (%rbp,%r13)
jmp 0x3e49
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %dil, %r8d
leaq 0x20(%rsp), %rdi
callq 0x8978
testl %eax, %eax
js 0x3e49
movl 0x4(%r14), %edx
cmpl $0x8, %edx
jne 0x3e3c
movb %al, (%rbp,%r13)
jmp 0x3e49
cmpl $0x8, 0x4(%r14)
jne 0x3dbf
movb %al, (%rbp,%r12)
movb %dl, 0x1(%rbp,%r12)
movb %cl, 0x2(%rbp,%r12)
jmp 0x3e49
movl 0x4(%r14), %ecx
cmpl $0x10, %ecx
je 0x3e15
cmpl $0x8, %ecx
jne 0x3e49
movb %al, (%rbp,%r13,2)
movb %dil, 0x1(%rbp,%r13,2)
jmp 0x3e49
cmpl $0x8, 0x4(%r14)
jne 0x3ddf
movb %al, (%rbp,%r13,4)
movb %dl, 0x1(%rbp,%r13,4)
movb %cl, 0x2(%rbp,%r13,4)
movb %dil, 0x3(%rbp,%r13,4)
jmp 0x3e49
movb %al, 0x1(%rbp,%r12,2)
movb %al, (%rbp,%r12,2)
movb %dl, 0x3(%rbp,%r12,2)
movb %dl, 0x2(%rbp,%r12,2)
movb %cl, 0x5(%rbp,%r12,2)
movb %cl, 0x4(%rbp,%r12,2)
jmp 0x3e49
movb %al, 0x1(%rbp,%r13,8)
movb %al, (%rbp,%r13,8)
movb %dl, 0x3(%rbp,%r13,8)
movb %dl, 0x2(%rbp,%r13,8)
movb %cl, 0x5(%rbp,%r13,8)
movb %cl, 0x4(%rbp,%r13,8)
movb %dil, 0x7(%rbp,%r13,8)
movb %dil, 0x6(%rbp,%r13,8)
jmp 0x3e49
movb %al, 0x1(%rbp,%r13,2)
movb %al, (%rbp,%r13,2)
jmp 0x3e49
movb %al, 0x1(%rbp,%r13,4)
movb %al, (%rbp,%r13,4)
movb %dil, 0x3(%rbp,%r13,4)
movb %dil, 0x2(%rbp,%r13,4)
jmp 0x3e49
movb $0x8, %cl
subb %dl, %cl
shrl %cl, %esi
pushq $-0x1
popq %rax
movl %edx, %ecx
shll %cl, %eax
notl %eax
andl %esi, %eax
movq %rbp, %rdi
movq %r13, %rsi
movl %eax, %ecx
callq 0x8924
incq %r13
addq $0x3, %r12
jmp 0x3cac
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rbx, %r8
callq 0x412d
cmpl $0x3, (%r14)
jne 0x3e7a
leaq 0x20(%rsp), %rdi
callq 0x47d9
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq