// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/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 = w * 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 = 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(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], 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
imull -0x30(%rbp), %eax
movl %eax, %eax
movq %rax, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x43a0
cmpl $0x0, %eax
je 0x403a
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x32e0
movq %rax, -0xd8(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xd8(%rbp), %rax
je 0x402e
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 0x3ffd
movl $0x0, -0x4(%rbp)
jmp 0x438b
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x4155
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), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %eax
movq %rax, -0xf0(%rbp)
cmpq $0x0, -0xe0(%rbp)
jne 0x40a4
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 -0xe0(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jae 0x40c2
movq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x44e0
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xf0(%rbp), %rax
je 0x4153
movq -0xe8(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movb (%rax), %sil
movq -0xf8(%rbp), %rax
movb 0x1(%rax), %dl
movq -0xf8(%rbp), %rax
movb 0x2(%rax), %cl
movq -0xf8(%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 0x4520
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x40d6
jmp 0x4155
movq -0x28(%rbp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x4231
movq -0x20(%rbp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x4231
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xc8(%rbp), %rax
je 0x422c
movw $0x0, -0xfa(%rbp)
movw $0x0, -0xfc(%rbp)
movw $0x0, -0xfe(%rbp)
movw $0x0, -0x100(%rbp)
movq -0x18(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x28(%rbp), %rax
leaq -0xfa(%rbp), %rdi
leaq -0xfc(%rbp), %rsi
leaq -0xfe(%rbp), %rdx
leaq -0x100(%rbp), %rcx
movq %rax, (%rsp)
callq 0x4610
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movw -0xfa(%rbp), %cx
movw -0xfc(%rbp), %r8w
movw -0xfe(%rbp), %ax
movzwl %cx, %ecx
movzwl %r8w, %r8d
movzwl %ax, %r9d
movzwl -0x100(%rbp), %eax
movl %eax, (%rsp)
callq 0x4950
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x4179
jmp 0x436d
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x4266
movq -0x20(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x4266
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %r8
movl $0x1, %edx
callq 0x4c20
jmp 0x436b
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x4298
movq -0x20(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x4298
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %r8
xorl %edx, %edx
callq 0x4c20
jmp 0x4369
movb $0x0, -0x101(%rbp)
movb $0x0, -0x102(%rbp)
movb $0x0, -0x103(%rbp)
movb $0x0, -0x104(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xc8(%rbp), %rax
je 0x4367
movq -0x18(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x28(%rbp), %rax
leaq -0x101(%rbp), %rdi
leaq -0x102(%rbp), %rsi
leaq -0x103(%rbp), %rdx
leaq -0x104(%rbp), %rcx
movq %rax, (%rsp)
callq 0x5490
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movb -0x101(%rbp), %r8b
movb -0x102(%rbp), %r9b
movb -0x103(%rbp), %al
leaq -0xc0(%rbp), %rcx
movzbl %r8b, %r8d
movzbl %r9b, %r9d
movzbl %al, %eax
movl %eax, (%rsp)
movzbl -0x104(%rbp), %eax
movl %eax, 0x8(%rsp)
callq 0x59f0
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
je 0x4354
jmp 0x4367
jmp 0x4356
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x42bc
jmp 0x4369
jmp 0x436b
jmp 0x436d
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x4382
leaq -0xc0(%rbp), %rdi
callq 0x5db0
movl -0xcc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw (%rax,%rax)