// File: /workspace/github_c_makefile_star2_O3/tditlu[P]shadetabler/src/lodepng/lodepng.c
// Function: lodepng_convert
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 = (size_t)w * (size_t)h;
  unsigned error = 0;

  if(mode_in->colortype == LCT_PALETTE && !mode_in->palette) {
    return 107; /* error: must provide palette if input mode is palette */
  }

  if(lodepng_color_mode_equal(mode_out, mode_in)) {
    size_t numbytes = lodepng_get_raw_size(w, h, mode_in);
    lodepng_memcpy(out, in, numbytes);
    return 0;
  }

  if(mode_out->colortype == LCT_PALETTE) {
    size_t palettesize = mode_out->palettesize;
    const unsigned char* palette = mode_out->palette;
    size_t palsize = (size_t)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 the input was also palette with same bitdepth, then the color types are also
      equal, so copy literally. This to preserve the exact indices that were in the PNG
      even in case there are duplicate colors in the palette.*/
      if(mode_in->colortype == LCT_PALETTE && mode_in->bitdepth == mode_out->bitdepth) {
        size_t numbytes = lodepng_get_raw_size(w, h, mode_in);
        lodepng_memcpy(out, in, numbytes);
        return 0;
      }
    }
    if(palettesize < palsize) palsize = palettesize;
    color_tree_init(&tree);
    for(i = 0; i != palsize; ++i) {
      const unsigned char* p = &palette[i * 4];
      error = color_tree_add(&tree, p[0], p[1], p[2], p[3], (unsigned)i);
      if(error) break;
    }
  }

  if(!error) {
    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, in, mode_in);
    } else if(mode_out->bitdepth == 8 && mode_out->colortype == LCT_RGB) {
      getPixelColorsRGB8(out, numpixels, 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);
        error = rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a);
        if(error) break;
      }
    }
  }

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

  return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %r9d, %r13d
movl %r8d, %ebx
movq %rdx, %rbp
movq %rdi, 0x10(%rsp)
movl (%rcx), %r14d
cmpl $0x3, %r14d
jne 0x6443
cmpq $0x0, 0x8(%rcx)
je 0x652d
movq %rsi, 0x28(%rsp)
movl %ebx, %eax
movl %r13d, %r15d
imulq %rax, %r15
movq %rbp, %rdi
movq %rcx, %rsi
movq %rcx, %r12
callq 0x698e
testl %eax, %eax
je 0x64b1
movl 0x4(%r12), %ebx
movl %r14d, %edi
callq 0x5b92
imull %ebx, %eax
movq %r15, %rcx
shrq $0x3, %rcx
imulq %rax, %rcx
andl $0x7, %r15d
imulq %rax, %r15
addq $0x7, %r15
shrq $0x3, %r15
xorl %r13d, %r13d
addq %rcx, %r15
je 0x6971
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x1130
jmp 0x6971
movq %r12, 0x20(%rsp)
movq %rbp, 0x18(%rsp)
cmpl $0x3, (%rbp)
jne 0x65fc
movq 0x18(%rsp), %rdx
movq 0x10(%rdx), %rax
movl 0x4(%rdx), %ecx
movl $0x1, %ebp
shlq %cl, %rbp
testq %rax, %rax
je 0x6538
movq 0x8(%rdx), %r12
cmpq %rbp, %rax
cmovbq %rax, %rbp
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
jmp 0x65c3
movl $0x6b, %r13d
jmp 0x6971
movq 0x20(%rsp), %rdx
movq 0x8(%rdx), %r12
movq 0x10(%rdx), %rax
cmpl $0x3, %r14d
jne 0x6578
cmpl %ecx, 0x4(%rdx)
jne 0x6578
movl %ebx, %edi
movl %r13d, %esi
callq 0x5c41
xorl %r13d, %r13d
testq %rax, %rax
je 0x6971
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rax, %rdx
jmp 0x64a7
cmpq %rbp, %rax
cmovbq %rax, %rbp
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 0x65fc
xorl %ebx, %ebx
leaq 0x30(%rsp), %r14
movzbl (%r12,%rbx,4), %esi
movzbl 0x1(%r12,%rbx,4), %edx
movzbl 0x2(%r12,%rbx,4), %ecx
movzbl 0x3(%r12,%rbx,4), %r8d
movq %r14, %rdi
movl %ebx, %r9d
callq 0x69fb
testl %eax, %eax
jne 0x6944
incq %rbx
cmpq %rbx, %rbp
jne 0x65ca
movq 0x20(%rsp), %rcx
movl 0x4(%rcx), %esi
xorl $0x10, %esi
movq 0x18(%rsp), %r14
movl 0x4(%r14), %eax
movl %eax, %edx
xorl $0x10, %edx
orl %esi, %edx
movq 0x28(%rsp), %r12
jne 0x672a
testq %r15, %r15
je 0x695e
xorl %r13d, %r13d
leaq 0xbc03(%rip), %r14      # 0x12238
xorl %ebp, %ebp
xorl %ebx, %ebx
movw %r13w, 0xe(%rsp)
movw %r13w, 0xc(%rsp)
movw %r13w, 0xa(%rsp)
movw %r13w, 0x8(%rsp)
movq %rcx, (%rsp)
leaq 0xe(%rsp), %rdi
leaq 0xc(%rsp), %rsi
leaq 0xa(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r12, %r8
movq %rbx, %r9
callq 0x6acd
movq 0x18(%rsp), %rax
movl (%rax), %esi
cmpq $0x6, %rsi
ja 0x670d
movzwl 0xe(%rsp), %eax
movzwl 0xc(%rsp), %edx
movzwl 0xa(%rsp), %edi
movzwl 0x8(%rsp), %ecx
movslq (%r14,%rsi,4), %rsi
addq %r14, %rsi
jmpq *%rsi
rolw $0x8, %ax
movq 0x10(%rsp), %rcx
movw %ax, (%rcx,%rbx,2)
jmp 0x670d
movq 0x10(%rsp), %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 0x670d
movq 0x10(%rsp), %rcx
movb %ah, (%rcx,%rbp,2)
movb %al, 0x1(%rcx,%rbp,2)
movb %dh, 0x2(%rcx,%rbp,2)
movb %dl, 0x3(%rcx,%rbp,2)
movl %edi, %eax
movb %ah, 0x4(%rcx,%rbp,2)
movb %al, 0x5(%rcx,%rbp,2)
jmp 0x670d
movq 0x10(%rsp), %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 %edi, %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 $0x3, %rbp
cmpq %rbx, %r15
movq 0x20(%rsp), %rcx
jne 0x6639
xorl %r13d, %r13d
jmp 0x6947
cmpl $0x8, %eax
jne 0x6755
movl (%r14), %eax
cmpl $0x2, %eax
je 0x694e
cmpl $0x6, %eax
jne 0x6755
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x6c4c
jmp 0x695e
xorl %r13d, %r13d
movb %r13b, 0xe(%rsp)
movb %r13b, 0xc(%rsp)
movb %r13b, 0xa(%rsp)
movb %r13b, 0x8(%rsp)
testq %r15, %r15
je 0x6961
xorl %r13d, %r13d
leaq 0xe(%rsp), %rbp
leaq 0xba98(%rip), %rbx      # 0x1221c
movq %rcx, (%rsp)
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
leaq 0xa(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r12, %r8
movq %r13, %r9
callq 0x7329
movl (%r14), %r8d
cmpq $0x6, %r8
ja 0x6931
movb 0xe(%rsp), %al
movzbl %al, %esi
movb 0xc(%rsp), %dl
movb 0xa(%rsp), %cl
movb 0x8(%rsp), %dil
movslq (%rbx,%r8,4), %r8
addq %rbx, %r8
jmpq *%r8
movl 0x4(%r14), %edx
cmpl $0x10, %edx
je 0x68e5
cmpl $0x8, %edx
jne 0x690f
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r13)
jmp 0x6931
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %dil, %r8d
leaq 0x30(%rsp), %rdi
callq 0xd336
testl %eax, %eax
js 0x6986
movl 0x4(%r14), %edx
cmpl $0x8, %edx
jne 0x6922
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r13)
jmp 0x6931
cmpl $0x8, 0x4(%r14)
leaq (%r13,%r13,2), %rsi
jne 0x6899
movq 0x10(%rsp), %rdi
movb %al, (%rdi,%rsi)
movb %dl, 0x1(%rdi,%rsi)
movb %cl, 0x2(%rdi,%rsi)
jmp 0x6931
movl 0x4(%r14), %ecx
cmpl $0x10, %ecx
je 0x68f5
cmpl $0x8, %ecx
jne 0x6931
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r13,2)
movb %dil, 0x1(%rcx,%r13,2)
jmp 0x6931
cmpl $0x8, 0x4(%r14)
jne 0x68b7
movq 0x10(%rsp), %rsi
movb %al, (%rsi,%r13,4)
movb %dl, 0x1(%rsi,%r13,4)
movb %cl, 0x2(%rsi,%r13,4)
movb %dil, 0x3(%rsi,%r13,4)
jmp 0x6931
movq 0x10(%rsp), %rdi
movb %al, 0x1(%rdi,%rsi,2)
movb %al, (%rdi,%rsi,2)
movb %dl, 0x3(%rdi,%rsi,2)
movb %dl, 0x2(%rdi,%rsi,2)
movb %cl, 0x5(%rdi,%rsi,2)
movb %cl, 0x4(%rdi,%rsi,2)
jmp 0x6931
movq 0x10(%rsp), %rsi
movb %al, 0x1(%rsi,%r13,8)
movb %al, (%rsi,%r13,8)
movb %dl, 0x3(%rsi,%r13,8)
movb %dl, 0x2(%rsi,%r13,8)
movb %cl, 0x5(%rsi,%r13,8)
movb %cl, 0x4(%rsi,%r13,8)
movb %dil, 0x7(%rsi,%r13,8)
movb %dil, 0x6(%rsi,%r13,8)
jmp 0x6931
movq 0x10(%rsp), %rcx
movb %al, 0x1(%rcx,%r13,2)
movb %al, (%rcx,%r13,2)
jmp 0x6931
movq 0x10(%rsp), %rcx
movb %al, 0x1(%rcx,%r13,4)
movb %al, (%rcx,%r13,4)
movb %dil, 0x3(%rcx,%r13,4)
movb %dil, 0x2(%rcx,%r13,4)
jmp 0x6931
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 0x10(%rsp), %rdi
movq %r13, %rsi
movl %eax, %ecx
callq 0xd2de
incq %r13
cmpq %r15, %r13
movq 0x20(%rsp), %rcx
jne 0x6784
jmp 0x695e
movl %eax, %r13d
movq 0x18(%rsp), %r14
jmp 0x6961
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x703a
xorl %r13d, %r13d
cmpl $0x3, (%r14)
jne 0x6971
leaq 0x30(%rsp), %rdi
callq 0x75fb
movl %r13d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x52, %r13d
jmp 0x6961