// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-zoe/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(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 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);
        for(i = 0; i != numbytes; ++i) out[i] = in[i];
        return 0;
      }
    }
    if(palettesize < palsize) palsize = palettesize;
    color_tree_init(&tree);
    for(i = 0; i != palsize; ++i)
    {
      const unsigned char* p = &palette[i * 4];
      color_tree_add(&tree, p[0], p[1], p[2], p[3], (unsigned)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);
      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 -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x43e0
cmpl $0x0, %eax
je 0x3ffb
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x3330
movq %rax, -0xd8(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xd8(%rbp), %rax
je 0x3fef
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3fbe
movl $0x0, -0x4(%rbp)
jmp 0x43c7
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x4191
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 0x40e0
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 0x40de
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x40de
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x3330
movq %rax, -0xf8(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xf8(%rbp), %rax
je 0x40d2
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x40a1
movl $0x0, -0x4(%rbp)
jmp 0x43c7
jmp 0x40e0
movq -0xe0(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jae 0x40fe
movq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x4520
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xf0(%rbp), %rax
je 0x418f
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 0x4560
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x4112
jmp 0x4191
movq -0x28(%rbp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x426d
movq -0x20(%rbp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x426d
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xc8(%rbp), %rax
je 0x4268
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 0x4650
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 0x4990
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x41b5
jmp 0x43a9
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x42a2
movq -0x20(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x42a2
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %r8
movl $0x1, %edx
callq 0x4c60
jmp 0x43a7
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x42d4
movq -0x20(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x42d4
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %r8
xorl %edx, %edx
callq 0x4c60
jmp 0x43a5
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 0x43a3
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 0x54d0
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 0x5a30
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
je 0x4390
jmp 0x43a3
jmp 0x4392
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x42f8
jmp 0x43a5
jmp 0x43a7
jmp 0x43a9
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x43be
leaq -0xc0(%rbp), %rdi
callq 0x5df0
movl -0xcc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)