// File: /workspace/github_cpp_makefile_star2_O3/logicx24[P]RayTracer/lodepng.cpp
// Function: lodepng_convert(unsigned char*, unsigned char const*, LodePNGColorMode*, LodePNGColorMode const*, unsigned int, unsigned int)
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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r9d, %r14d
movl %r8d, %r12d
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, -0x48(%rbp)
movq %rdi, %rbx
movq %rdx, %rdi
movq %rcx, %rsi
callq 0xe747
testl %eax, %eax
je 0xe34d
movl %r12d, %edi
movl %r14d, %esi
movq %r13, %rdx
callq 0xdb6a
testq %rax, %rax
movq -0x48(%rbp), %rsi
je 0xe733
xorl %ecx, %ecx
movb (%rsi,%rcx), %dl
movb %dl, (%rbx,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0xe33a
jmp 0xe733
movq %r13, -0x50(%rbp)
movq %rbx, -0x40(%rbp)
imull %r12d, %r14d
cmpl $0x3, (%r15)
jne 0xe3f3
movb 0x4(%r15), %cl
movl $0x1, %ebx
shlq %cl, %rbx
movq 0x10(%r15), %rax
cmpq %rbx, %rax
cmovbq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
movaps %xmm0, -0xe0(%rbp)
movl $0xffffffff, -0x60(%rbp) # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xe3f3
xorl %r13d, %r13d
leaq -0xe0(%rbp), %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 0xe7b9
incq %r13
cmpq %r13, %rbx
jne 0xe3c5
movq -0x50(%rbp), %r8
movl 0x4(%r8), %ecx
xorl $0x10, %ecx
movl 0x4(%r15), %eax
movl %eax, %edx
xorl $0x10, %edx
orl %ecx, %edx
movq %r15, -0x38(%rbp)
jne 0xe510
testq %r14, %r14
je 0xe71e
xorl %r15d, %r15d
leaq 0x9146(%rip), %r12      # 0x1756c
xorl %edi, %edi
xorl %ebx, %ebx
movw %r15w, -0x30(%rbp)
movw %r15w, -0x2e(%rbp)
movw %r15w, -0x2c(%rbp)
movw %r15w, -0x2a(%rbp)
movq -0x50(%rbp), %rax
movq %rax, (%rsp)
movq %rdi, %r13
leaq -0x30(%rbp), %rdi
leaq -0x2e(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
leaq -0x2a(%rbp), %rcx
movq -0x48(%rbp), %r8
movq %rbx, %r9
callq 0xe882
movq %r13, %rdi
movq -0x38(%rbp), %rax
movl (%rax), %esi
cmpq $0x6, %rsi
ja 0xe4fb
movzwl -0x30(%rbp), %eax
movzwl -0x2e(%rbp), %edx
movzwl -0x2c(%rbp), %r8d
movzwl -0x2a(%rbp), %ecx
movslq (%r12,%rsi,4), %rsi
addq %r12, %rsi
jmpq *%rsi
rolw $0x8, %ax
movq -0x40(%rbp), %rcx
movw %ax, (%rcx,%rbx,2)
jmp 0xe4fb
movq -0x40(%rbp), %rdx
movb %ah, (%rdx,%rbx,4)
movb %al, 0x1(%rdx,%rbx,4)
movb %ch, 0x2(%rdx,%rbx,4)
movb %cl, 0x3(%rdx,%rbx,4)
jmp 0xe4fb
movq -0x40(%rbp), %rcx
movb %ah, (%rcx,%rdi)
movb %al, 0x1(%rcx,%rdi)
movb %dh, 0x2(%rcx,%rdi)
movb %dl, 0x3(%rcx,%rdi)
movl %r8d, %eax
movb %ah, 0x4(%rcx,%rdi)
movb %al, 0x5(%rcx,%rdi)
jmp 0xe4fb
movq -0x40(%rbp), %rsi
movb %ah, (%rsi,%rbx,8)
movb %al, 0x1(%rsi,%rbx,8)
movb %dh, 0x2(%rsi,%rbx,8)
movb %dl, 0x3(%rsi,%rbx,8)
movl %r8d, %eax
movb %ah, 0x4(%rsi,%rbx,8)
movb %al, 0x5(%rsi,%rbx,8)
movb %ch, 0x6(%rsi,%rbx,8)
movb %cl, 0x7(%rsi,%rbx,8)
incq %rbx
addq $0x6, %rdi
cmpq %rbx, %r14
jne 0xe42a
jmp 0xe71e
cmpl $0x8, %eax
movq -0x40(%rbp), %rbx
movq %r14, %rsi
jne 0xe53a
movl (%r15), %eax
cmpl $0x2, %eax
je 0xe710
cmpl $0x6, %eax
jne 0xe53a
movq %rbx, %rdi
movl $0x1, %edx
jmp 0xe715
xorl %eax, %eax
movb %al, -0x30(%rbp)
movb %al, -0x2e(%rbp)
movb %al, -0x2c(%rbp)
movb %al, -0x2a(%rbp)
testq %rsi, %rsi
je 0xe71e
movl $0x1, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq -0x50(%rbp), %rax
movq %rax, (%rsp)
leaq -0x30(%rbp), %rdi
leaq -0x2e(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
leaq -0x2a(%rbp), %rcx
movq -0x48(%rbp), %r8
movq %r13, %r9
callq 0xee79
movq -0x38(%rbp), %rax
movl (%rax), %r8d
cmpq $0x6, %r8
ja 0xe6fa
movb -0x30(%rbp), %al
movzbl %al, %esi
movb -0x2e(%rbp), %dl
movb -0x2c(%rbp), %cl
movb -0x2a(%rbp), %dil
leaq 0x8fa7(%rip), %r9       # 0x17550
movslq (%r9,%r8,4), %r8
addq %r9, %r8
jmpq *%r8
movq -0x38(%rbp), %rcx
movl 0x4(%rcx), %edx
cmpl $0x10, %edx
je 0xe6ba
cmpl $0x8, %edx
jne 0xe6da
movb %al, (%rbx,%r13)
jmp 0xe6fa
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %dil, %r8d
leaq -0xe0(%rbp), %rdi
callq 0x14de5
testl %eax, %eax
js 0xe6fa
movq -0x38(%rbp), %rcx
movl 0x4(%rcx), %edx
cmpl $0x8, %edx
jne 0xe6ed
movb %al, (%rbx,%r13)
jmp 0xe6fa
movq -0x38(%rbp), %rsi
cmpl $0x8, 0x4(%rsi)
jne 0xe672
movb %al, (%rbx,%r15)
movb %dl, 0x1(%rbx,%r15)
movb %cl, 0x2(%rbx,%r15)
jmp 0xe6fa
movq -0x38(%rbp), %rcx
movl 0x4(%rcx), %ecx
cmpl $0x10, %ecx
je 0xe6c5
cmpl $0x8, %ecx
jne 0xe6fa
movb %al, -0x1(%rbx,%r12)
movb %dil, (%rbx,%r12)
jmp 0xe6fa
movq -0x38(%rbp), %rsi
cmpl $0x8, 0x4(%rsi)
jne 0xe691
movb %al, -0x2(%rbx,%r12,2)
movb %dl, -0x1(%rbx,%r12,2)
movb %cl, (%rbx,%r12,2)
movb %dil, 0x1(%rbx,%r12,2)
jmp 0xe6fa
movb %al, 0x1(%rbx,%r15,2)
movb %al, (%rbx,%r15,2)
movb %dl, 0x3(%rbx,%r15,2)
movb %dl, 0x2(%rbx,%r15,2)
movb %cl, 0x5(%rbx,%r15,2)
movb %cl, 0x4(%rbx,%r15,2)
jmp 0xe6fa
movb %al, -0x3(%rbx,%r12,4)
movb %al, -0x4(%rbx,%r12,4)
movb %dl, -0x1(%rbx,%r12,4)
movb %dl, -0x2(%rbx,%r12,4)
movb %cl, 0x1(%rbx,%r12,4)
movb %cl, (%rbx,%r12,4)
movb %dil, 0x3(%rbx,%r12,4)
movb %dil, 0x2(%rbx,%r12,4)
jmp 0xe6fa
movb %al, (%rbx,%r12)
movb %al, -0x1(%rbx,%r12)
jmp 0xe6fa
movb %al, -0x1(%rbx,%r12,2)
movb %al, -0x2(%rbx,%r12,2)
movb %dil, 0x1(%rbx,%r12,2)
movb %dil, (%rbx,%r12,2)
jmp 0xe6fa
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 %rbx, %rdi
movq %r13, %rsi
movl %eax, %ecx
callq 0x14d87
incq %r13
addq $0x2, %r12
addq $0x3, %r15
cmpq %r13, %r14
jne 0xe55d
jmp 0xe71e
movq %rbx, %rdi
xorl %edx, %edx
movq -0x48(%rbp), %rcx
callq 0xea05
movq -0x38(%rbp), %rax
cmpl $0x3, (%rax)
jne 0xe733
leaq -0xe0(%rbp), %rdi
callq 0xf196
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq