// File: /workspace/github_c_makefile_star2_O1/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 $0xb8, %rsp
movl %r9d, %r13d
movl %r8d, %r12d
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %rbp
movq %rdx, %rdi
movq %rcx, %rsi
callq 0x511f
testl %eax, %eax
je 0x4d01
movl %r12d, %edi
movl %r13d, %esi
movq %r15, %rdx
callq 0x4528
testq %rax, %rax
je 0x510b
xorl %ecx, %ecx
movb (%r14,%rcx), %dl
movb %dl, (%rbp,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x4cec
jmp 0x510b
movq %r15, 0x28(%rsp)
imull %r12d, %r13d
movq %r13, 0x18(%rsp)
cmpl $0x3, (%rbx)
movq %rbx, %r15
jne 0x4db4
movl 0x4(%r15), %ecx
movq 0x10(%r15), %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movl $0xffffffff, 0xb0(%rsp) # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x4db4
movl $0x1, %ebx
shlq %cl, %rbx
cmpq %rbx, %rax
cmovbq %rax, %rbx
cmpq $0x1, %rbx
adcq $0x0, %rbx
xorl %r13d, %r13d
leaq 0x30(%rsp), %r12
movq 0x8(%r15), %rax
movzbl (%rax,%r13,4), %esi
movzbl 0x1(%rax,%r13,4), %edx
movzbl 0x2(%rax,%r13,4), %ecx
movzbl 0x3(%rax,%r13,4), %r8d
movq %r12, %rdi
movl %r13d, %r9d
callq 0x518c
incq %r13
cmpq %r13, %rbx
jne 0x4d86
movq 0x28(%rsp), %r8
cmpl $0x10, 0x4(%r8)
movq %r15, %rbx
jne 0x4ee0
cmpl $0x10, 0x4(%rbx)
jne 0x4ee0
movq %rbx, %r13
movq %rbp, 0x20(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x50fa
xorl %r15d, %r15d
leaq 0x927d(%rip), %r12      # 0xe06c
xorl %ebx, %ebx
xorl %ebp, %ebp
movw %r15w, 0x16(%rsp)
movw %r15w, 0x14(%rsp)
movw %r15w, 0x12(%rsp)
movw %r15w, 0x10(%rsp)
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %r8
movq %rbp, %r9
callq 0x5248
movl (%r13), %esi
cmpq $0x6, %rsi
ja 0x4ec9
movzwl 0x16(%rsp), %eax
movzwl 0x14(%rsp), %edx
movzwl 0x12(%rsp), %edi
movzwl 0x10(%rsp), %ecx
movslq (%r12,%rsi,4), %rsi
addq %r12, %rsi
jmpq *%rsi
rolw $0x8, %ax
movq 0x20(%rsp), %rcx
movw %ax, (%rcx,%rbp,2)
jmp 0x4ec9
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 0x4ec9
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 0x4ec9
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 0x4df3
jmp 0x50fa
movl 0x4(%rbx), %eax
cmpl $0x8, %eax
jne 0x4f23
cmpl $0x6, (%rbx)
jne 0x4f0a
movq %rbx, %r13
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
movq %r14, %rcx
callq 0x53c7
jmp 0x50fa
cmpl $0x8, %eax
jne 0x4f23
cmpl $0x2, (%rbx)
jne 0x4f23
movq %rbx, %r13
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
jmp 0x4efd
xorl %eax, %eax
movb %al, 0x16(%rsp)
movb %al, 0x14(%rsp)
movb %al, 0x12(%rsp)
movb %al, 0x10(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x50f7
movl $0x1, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %r8
movq %r13, %r9
callq 0x5834
movl (%rbx), %r8d
cmpq $0x6, %r8
ja 0x50e1
movb 0x16(%rsp), %al
movzbl %al, %esi
movb 0x14(%rsp), %dl
movb 0x12(%rsp), %cl
movb 0x10(%rsp), %dil
leaq 0x90b3(%rip), %r9       # 0xe050
movslq (%r9,%r8,4), %r8
addq %r9, %r8
jmpq *%r8
movl 0x4(%rbx), %edx
cmpl $0x10, %edx
je 0x509f
cmpl $0x8, %edx
jne 0x50c1
movb %al, (%rbp,%r13)
jmp 0x50e1
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %dil, %r8d
leaq 0x30(%rsp), %rdi
callq 0xae34
testl %eax, %eax
js 0x50e1
movl 0x4(%rbx), %edx
cmpl $0x8, %edx
jne 0x50d4
movb %al, (%rbp,%r13)
jmp 0x50e1
cmpl $0x8, 0x4(%rbx)
jne 0x5055
movb %al, (%rbp,%r15)
movb %dl, 0x1(%rbp,%r15)
movb %cl, 0x2(%rbp,%r15)
jmp 0x50e1
movl 0x4(%rbx), %ecx
cmpl $0x10, %ecx
je 0x50ab
cmpl $0x8, %ecx
jne 0x50e1
movb %al, -0x1(%rbp,%r12)
movb %dil, (%rbp,%r12)
jmp 0x50e1
cmpl $0x8, 0x4(%rbx)
jne 0x5075
movb %al, -0x2(%rbp,%r12,2)
movb %dl, -0x1(%rbp,%r12,2)
movb %cl, (%rbp,%r12,2)
movb %dil, 0x1(%rbp,%r12,2)
jmp 0x50e1
movb %al, 0x1(%rbp,%r15,2)
movb %al, (%rbp,%r15,2)
movb %dl, 0x3(%rbp,%r15,2)
movb %dl, 0x2(%rbp,%r15,2)
movb %cl, 0x5(%rbp,%r15,2)
movb %cl, 0x4(%rbp,%r15,2)
jmp 0x50e1
movb %al, -0x3(%rbp,%r12,4)
movb %al, -0x4(%rbp,%r12,4)
movb %dl, -0x1(%rbp,%r12,4)
movb %dl, -0x2(%rbp,%r12,4)
movb %cl, 0x1(%rbp,%r12,4)
movb %cl, (%rbp,%r12,4)
movb %dil, 0x3(%rbp,%r12,4)
movb %dil, 0x2(%rbp,%r12,4)
jmp 0x50e1
movb %al, (%rbp,%r12)
movb %al, -0x1(%rbp,%r12)
jmp 0x50e1
movb %al, -0x1(%rbp,%r12,2)
movb %al, -0x2(%rbp,%r12,2)
movb %dil, 0x1(%rbp,%r12,2)
movb %dil, (%rbp,%r12,2)
jmp 0x50e1
movb $0x8, %cl
subb %dl, %cl
shrl %cl, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %edx, %ecx
shll %cl, %eax
notl %eax
andl %esi, %eax
movq %rbp, %rdi
movq %r13, %rsi
movl %eax, %ecx
callq 0xaddc
incq %r13
addq $0x2, %r12
addq $0x3, %r15
cmpq %r13, 0x18(%rsp)
jne 0x4f4d
movq %rbx, %r13
cmpl $0x3, (%r13)
jne 0x510b
leaq 0x30(%rsp), %rdi
callq 0x5b46
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq