// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movl -0x30(%rbp), %ecx
imulq %rcx, %rax
movq %rax, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x770e
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x770e
movl $0x6b, -0x4(%rbp)
jmp 0x7b1b
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x7b30
cmpl $0x0, %eax
je 0x7756
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x68a0
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0xd8(%rbp), %rdx
callq 0x6440
movl $0x0, -0x4(%rbp)
jmp 0x7b1b
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x78dd
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xe8(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0xf0(%rbp)
cmpq $0x0, -0xe0(%rbp)
jne 0x7812
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xe8(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x7810
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x7810
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x68a0
movq %rax, -0xf8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0xf8(%rbp), %rdx
callq 0x6440
movl $0x0, -0x4(%rbp)
jmp 0x7b1b
jmp 0x7812
movq -0xe0(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jae 0x7830
movq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x7c70
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xf0(%rbp), %rax
je 0x78db
movq -0xe8(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movb (%rax), %sil
movq -0x100(%rbp), %rax
movb 0x1(%rax), %dl
movq -0x100(%rbp), %rax
movb 0x2(%rax), %cl
movq -0x100(%rbp), %rax
movb 0x3(%rax), %al
movq -0x38(%rbp), %rdi
movl %edi, %r9d
leaq -0xc0(%rbp), %rdi
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %al, %r8d
callq 0x7ca0
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
je 0x78c8
jmp 0x78db
jmp 0x78ca
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x7844
jmp 0x78dd
cmpl $0x0, -0xcc(%rbp)
jne 0x7afd
movq -0x28(%rbp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x79c6
movq -0x20(%rbp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x79c6
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xc8(%rbp), %rax
je 0x79c1
movw $0x0, -0x102(%rbp)
movw $0x0, -0x104(%rbp)
movw $0x0, -0x106(%rbp)
movw $0x0, -0x108(%rbp)
movq -0x18(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x28(%rbp), %rax
leaq -0x102(%rbp), %rdi
leaq -0x104(%rbp), %rsi
leaq -0x106(%rbp), %rdx
leaq -0x108(%rbp), %rcx
movq %rax, (%rsp)
callq 0x7db0
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movw -0x102(%rbp), %cx
movw -0x104(%rbp), %r8w
movw -0x106(%rbp), %ax
movzwl %cx, %ecx
movzwl %r8w, %r8d
movzwl %ax, %r9d
movzwl -0x108(%rbp), %eax
movl %eax, (%rsp)
callq 0x80f0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x790e
jmp 0x7afb
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x79f6
movq -0x20(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x79f6
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x83c0
jmp 0x7af9
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x7a26
movq -0x20(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x7a26
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x8b50
jmp 0x7af7
movb $0x0, -0x109(%rbp)
movb $0x0, -0x10a(%rbp)
movb $0x0, -0x10b(%rbp)
movb $0x0, -0x10c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xc8(%rbp), %rax
je 0x7af5
movq -0x18(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x28(%rbp), %rax
leaq -0x109(%rbp), %rdi
leaq -0x10a(%rbp), %rsi
leaq -0x10b(%rbp), %rdx
leaq -0x10c(%rbp), %rcx
movq %rax, (%rsp)
callq 0x8ff0
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movb -0x109(%rbp), %r8b
movb -0x10a(%rbp), %r9b
movb -0x10b(%rbp), %al
leaq -0xc0(%rbp), %rcx
movzbl %r8b, %r8d
movzbl %r9b, %r9d
movzbl %al, %eax
movl %eax, (%rsp)
movzbl -0x10c(%rbp), %eax
movl %eax, 0x8(%rsp)
callq 0x9520
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
je 0x7ae2
jmp 0x7af5
jmp 0x7ae4
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x7a4a
jmp 0x7af7
jmp 0x7af9
jmp 0x7afb
jmp 0x7afd
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x7b12
leaq -0xc0(%rbp), %rdi
callq 0x98e0
movl -0xcc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw (%rax,%rax)