// File: /workspace/github_c_makefile_star2_O1/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 $0xc8, %rsp
movq %rdi, 0x20(%rsp)
movl (%rcx), %ebp
cmpl $0x3, %ebp
jne 0x6196
cmpq $0x0, 0x8(%rcx)
je 0x624c
movq %rsi, %r12
movl %r8d, %eax
movl %r9d, %r15d
imulq %rax, %r15
movq %rdx, %rdi
movq %rcx, %rsi
movq %rcx, %rbx
movq %rdx, %r14
movl %r9d, 0x3c(%rsp)
movl %r8d, %r13d
callq 0x672f
testl %eax, %eax
je 0x6209
movl 0x4(%rbx), %ebx
movl %ebp, %edi
callq 0x58b3
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 %r14d, %r14d
addq %rcx, %r15
je 0x6711
movq 0x20(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1130
jmp 0x6711
movl 0x3c(%rsp), %esi
xorl %eax, %eax
cmpl $0x3, (%r14)
movq %rbx, %r8
movq %rbx, 0x18(%rsp)
movq %r12, %rbx
movq %r14, %r9
jne 0x6358
movq %rbx, 0x28(%rsp)
movq 0x10(%r9), %rax
movl 0x4(%r9), %ecx
movl $0x1, %ebx
shlq %cl, %rbx
testq %rax, %rax
movq %r9, 0x30(%rsp)
je 0x6257
movq 0x8(%r9), %r12
jmp 0x62a1
movl $0x6b, %r14d
jmp 0x6711
movq 0x8(%r8), %r12
movq 0x10(%r8), %rax
cmpl $0x3, %ebp
jne 0x62a1
cmpl %ecx, 0x4(%r8)
jne 0x62a1
movl %r13d, %edi
movq %r8, %rdx
callq 0x5962
testq %rax, %rax
je 0x6726
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1130
xorl %ebp, %ebp
xorl %eax, %eax
movq 0x30(%rsp), %r9
jmp 0x6339
cmpq %rbx, %rax
cmovbq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0xb0(%rsp)
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)
movl $0xffffffff, 0xc0(%rsp) # imm = 0xFFFFFFFF
movb $0x1, %bpl
testq %rax, %rax
je 0x6340
decq %rbx
xorl %r14d, %r14d
leaq 0x40(%rsp), %r13
movzbl (%r12,%r14,4), %esi
movzbl 0x1(%r12,%r14,4), %edx
movzbl 0x2(%r12,%r14,4), %ecx
movzbl 0x3(%r12,%r14,4), %r8d
movq %r13, %rdi
movl %r14d, %r9d
callq 0x679c
testl %eax, %eax
jne 0x632f
leaq 0x1(%r14), %rcx
cmpq %r14, %rbx
movq %rcx, %r14
jne 0x62fd
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %rbx
movq 0x18(%rsp), %r8
jmp 0x634c
xorl %eax, %eax
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %rbx
xorl %r14d, %r14d
testb %bpl, %bpl
je 0x6711
movl %eax, %r14d
testl %eax, %eax
jne 0x6701
cmpl $0x10, 0x4(%r8)
movq %r9, %r12
jne 0x648a
cmpl $0x10, 0x4(%r9)
jne 0x648a
testq %r15, %r15
je 0x66fe
movq %rbx, %r14
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %ebx, %ebx
movw %r13w, 0x16(%rsp)
movw %r13w, 0x14(%rsp)
movw %r13w, 0x12(%rsp)
movw %r13w, 0x10(%rsp)
movq %r8, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x6876
movl (%r12), %esi
cmpq $0x6, %rsi
ja 0x646a
movzwl 0x16(%rsp), %eax
movzwl 0x14(%rsp), %edx
movzwl 0x12(%rsp), %r8d
movzwl 0x10(%rsp), %ecx
leaq 0xbd44(%rip), %rdi      # 0x12138
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
rolw $0x8, %ax
movq 0x20(%rsp), %rcx
movw %ax, (%rcx,%rbx,2)
jmp 0x646a
movq 0x20(%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 0x646a
movq 0x20(%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 %r8d, %eax
movb %ah, 0x4(%rcx,%rbp,2)
movb %al, 0x5(%rcx,%rbp,2)
jmp 0x646a
movq 0x20(%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 %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 $0x3, %rbp
cmpq %rbx, %r15
movq 0x18(%rsp), %r8
jne 0x638f
xorl %r14d, %r14d
movq %r12, %r9
jmp 0x6701
movl 0x4(%r9), %eax
cmpl $0x8, %eax
jne 0x64d4
cmpl $0x6, (%r9)
jne 0x64b4
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r8, %rcx
callq 0x69f5
movq %r12, %r9
jmp 0x66fe
cmpl $0x8, %eax
jne 0x64d4
cmpl $0x2, (%r9)
jne 0x64d4
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r8, %rcx
callq 0x6ded
jmp 0x64ac
xorl %r14d, %r14d
movb %r14b, 0x16(%rsp)
movb %r14b, 0x14(%rsp)
movb %r14b, 0x12(%rsp)
movb %r14b, 0x10(%rsp)
testq %r15, %r15
je 0x6701
xorl %r13d, %r13d
movq %r8, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %r8
movq %r13, %r9
callq 0x70dc
movq %r12, %r9
movl (%r12), %r8d
movb $0x1, %bpl
cmpq $0x6, %r8
ja 0x66e5
movb 0x16(%rsp), %al
movzbl %al, %esi
movb 0x14(%rsp), %dl
movb 0x12(%rsp), %cl
movb 0x10(%rsp), %dil
leaq 0xbbd3(%rip), %r10      # 0x1211c
movslq (%r10,%r8,4), %r8
addq %r10, %r8
jmpq *%r8
movl 0x4(%r9), %edx
cmpl $0x10, %edx
je 0x6696
cmpl $0x8, %edx
jne 0x66c0
movq 0x20(%rsp), %rcx
movb %al, (%rcx,%r13)
jmp 0x66e5
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %dil, %r8d
leaq 0x40(%rsp), %rdi
callq 0xd51d
testl %eax, %eax
js 0x6684
movl 0x4(%r12), %edx
cmpl $0x8, %edx
jne 0x66d3
movq %r12, %r9
movq 0x20(%rsp), %rcx
movb %al, (%rcx,%r13)
jmp 0x66e5
cmpl $0x8, 0x4(%r9)
jne 0x662a
leaq (,%r13,2), %rsi
addq %r13, %rsi
movq 0x20(%rsp), %rdi
movb %al, (%rdi,%rsi)
movb %dl, 0x1(%rdi,%rsi)
movb %cl, 0x2(%rdi,%rsi)
jmp 0x66e5
movl 0x4(%r9), %ecx
cmpl $0x10, %ecx
je 0x66a6
cmpl $0x8, %ecx
movq 0x18(%rsp), %r8
jne 0x65fe
movq 0x20(%rsp), %rcx
movb %al, (%rcx,%r13,2)
movb %dil, 0x1(%rcx,%r13,2)
xorl %r14d, %r14d
jmp 0x66ed
cmpl $0x8, 0x4(%r9)
jne 0x6656
movq 0x20(%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 0x66e5
leaq (,%r13,2), %rsi
addq %r13, %rsi
movq 0x20(%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 0x66e5
movq 0x20(%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 0x66e5
movl $0x52, %r14d
xorl %ebp, %ebp
movq 0x18(%rsp), %r8
movq %r12, %r9
jmp 0x66ed
movq 0x20(%rsp), %rcx
movb %al, 0x1(%rcx,%r13,2)
movb %al, (%rcx,%r13,2)
jmp 0x66e5
movq 0x20(%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 0x66e5
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 0x20(%rsp), %rdi
movq %r13, %rsi
movl %eax, %ecx
callq 0xd4c5
movq %r12, %r9
xorl %r14d, %r14d
movq 0x18(%rsp), %r8
testb %bpl, %bpl
je 0x6701
incq %r13
cmpq %r15, %r13
jne 0x64f7
xorl %r14d, %r14d
cmpl $0x3, (%r9)
jne 0x6711
leaq 0x40(%rsp), %rdi
callq 0x73af
movl %r14d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
xorl %eax, %eax
jmp 0x632f