// File: /workspace/github_cpp_makefile_star2_O2/drummyfish[P]flowchart/src/lodepng.cpp
// Function: lodepng_convert(unsigned char*, unsigned char const*, LodePNGColorMode*, LodePNGColorMode*, unsigned int, unsigned int)
unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
                         LodePNGColorMode* mode_out, LodePNGColorMode* mode_in,
                         unsigned w, unsigned h)
{
  unsigned error = 0;
  size_t i;
  ColorTree tree;

  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 error;
  }

  if(mode_out->colortype == LCT_PALETTE)
  {
    size_t palsize = 1 << mode_out->bitdepth;
    if(mode_out->palettesize < palsize) palsize = mode_out->palettesize;
    color_tree_init(&tree, 1);
    for(i = 0; i < palsize; i++)
    {
      unsigned char* p = &mode_out->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)
  {
    size_t numpixels = w * h;
    for(i = 0; i < numpixels; i++)
    {
      unsigned short r = 0, g = 0, b = 0, a = 0;
      error = getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode_in);
      if(error) return error;
      error = rgba16ToPixel(out, i, mode_out, r, g, b, a);
      if(error) return error;
    }
  }
  else
  {
    size_t numpixels = w * h;
    for(i = 0; i < numpixels; i++)
    {
      unsigned char r = 0, g = 0, b = 0, a = 0;
      error = getPixelColorRGBA8(&r, &g, &b, &a, in, i, mode_in);
      if(error) return error;
      error = rgba8ToPixel(out, i, mode_out, &tree, r, g, b, a);
      if(error) return error;
    }
  }

  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 $0x48, %rsp
movl %r9d, %r14d
movl %r8d, %r13d
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %rbp
movq %rdx, %rdi
movq %rcx, %rsi
callq 0x510e
testl %eax, %eax
je 0x4d3c
movl %r13d, %edi
movl %r14d, %esi
movq %r12, %rdx
callq 0x4660
xorl %r12d, %r12d
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x50fc
movb (%rbx,%rcx), %dl
movb %dl, (%rbp,%rcx)
incq %rcx
jmp 0x4d27
movl %r13d, 0x24(%rsp)
movq %r14, 0x28(%rsp)
cmpl $0x3, (%r15)
movq %r15, %r11
movq %r15, 0x18(%rsp)
jne 0x4db5
movb 0x4(%r11), %cl
pushq $0x1
popq %rax
shll %cl, %eax
movslq %eax, %r13
movq 0x10(%r11), %rax
cmpq %r13, %rax
cmovbq %rax, %r13
leaq 0x38(%rsp), %r14
movq %r14, %rdi
callq 0x9e88
orl $-0x1, 0x8(%r14)
xorl %r15d, %r15d
cmpq %r15, %r13
movq 0x18(%rsp), %r11
je 0x4db5
movq 0x8(%r11), %rax
movzbl (%rax,%r15,4), %esi
movzbl 0x1(%rax,%r15,4), %edx
movzbl 0x2(%rax,%r15,4), %ecx
movzbl 0x3(%rax,%r15,4), %r8d
movq %r14, %rdi
movl %r15d, %r9d
callq 0x517a
incq %r15
jmp 0x4d80
cmpl $0x10, 0x4(%r12)
movq %r12, 0x30(%rsp)
jne 0x4ef4
cmpl $0x10, 0x4(%r11)
jne 0x4ef4
movq 0x28(%rsp), %r13
imull 0x24(%rsp), %r13d
pushq $0x5
popq %rdi
xorl %r9d, %r9d
cmpq %r9, %r13
je 0x50da
movq %rdi, %r14
andw $0x0, 0x16(%rsp)
andw $0x0, 0x14(%rsp)
andw $0x0, 0x12(%rsp)
andw $0x0, 0x10(%rsp)
movq %r12, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %r8
movq %r9, %r15
callq 0x5207
testl %eax, %eax
jne 0x50ef
movq 0x18(%rsp), %r11
cmpl $0x10, 0x4(%r11)
jne 0x50f4
movq %r14, %rdi
movl (%r11), %esi
cmpq $0x6, %rsi
ja 0x4ee0
movzwl 0x16(%rsp), %eax
movzwl 0x14(%rsp), %edx
movzwl 0x12(%rsp), %r9d
movzwl 0x10(%rsp), %ecx
leaq 0x91ff(%rip), %r8       # 0xe06c
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
rolw $0x8, %ax
movw %ax, (%rbp,%r15,2)
jmp 0x4ee0
movq %r15, %rdx
movb %ah, (%rbp,%rdx,4)
movb %al, 0x1(%rbp,%r15,4)
movb %ch, 0x2(%rbp,%rdx,4)
movb %cl, 0x3(%rbp,%r15,4)
jmp 0x4ee0
movb %ah, -0x5(%rbp,%rdi)
movb %al, -0x4(%rbp,%rdi)
movb %dh, -0x3(%rbp,%rdi)
movb %dl, -0x2(%rbp,%rdi)
movl %r9d, %eax
movb %ah, -0x1(%rbp,%rdi)
movb %al, (%rbp,%rdi)
jmp 0x4ee0
movq %r15, %rsi
movb %ah, (%rbp,%rsi,8)
movb %al, 0x1(%rbp,%r15,8)
movb %dh, 0x2(%rbp,%rsi,8)
movb %dl, 0x3(%rbp,%r15,8)
movl %r9d, %eax
movb %ah, 0x4(%rbp,%rsi,8)
movb %al, 0x5(%rbp,%r15,8)
movb %ch, 0x6(%rbp,%rsi,8)
movb %cl, 0x7(%rbp,%r15,8)
movq %r15, %r9
incq %r9
addq $0x6, %rdi
movq 0x30(%rsp), %r12
jmp 0x4de2
movq 0x28(%rsp), %r14
imull 0x24(%rsp), %r14d
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq %r13, %r14
je 0x50da
xorl %eax, %eax
movb %al, 0x16(%rsp)
movb %al, 0x14(%rsp)
movb %al, 0x12(%rsp)
movb %al, 0x10(%rsp)
movq %r12, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %r8
movq %r13, %r9
callq 0x5398
testl %eax, %eax
jne 0x50ef
movq 0x18(%rsp), %r11
movl (%r11), %r8d
cmpq $0x6, %r8
movq 0x30(%rsp), %r12
ja 0x50ce
movb 0x16(%rsp), %al
movzbl %al, %esi
movb 0x14(%rsp), %dl
movb 0x12(%rsp), %cl
movb 0x10(%rsp), %dil
leaq 0x90d3(%rip), %r10      # 0xe050
movslq (%r10,%r8,4), %r8
addq %r10, %r8
jmpq *%r8
movl 0x4(%r11), %edx
cmpl $0x10, %edx
je 0x5089
cmpl $0x8, %edx
jne 0x50ab
movb %al, (%rbp,%r13)
jmp 0x50ce
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %dil, %r8d
leaq 0x38(%rsp), %rdi
callq 0x9f68
testl %eax, %eax
js 0x50f8
movq 0x18(%rsp), %r11
movl 0x4(%r11), %edx
cmpl $0x8, %edx
jne 0x50bc
movb %al, (%rbp,%r13)
jmp 0x50ce
cmpl $0x8, 0x4(%r11)
jne 0x503f
movb %al, (%rbp,%r15)
movb %dl, 0x1(%rbp,%r15)
movb %cl, 0x2(%rbp,%r15)
jmp 0x50ce
movl 0x4(%r11), %ecx
cmpl $0x10, %ecx
je 0x5095
cmpl $0x8, %ecx
jne 0x50ce
movb %al, (%rbp,%r13,2)
movb %dil, 0x1(%rbp,%r13,2)
jmp 0x50ce
cmpl $0x8, 0x4(%r11)
jne 0x505f
movb %al, (%rbp,%r13,4)
movb %dl, 0x1(%rbp,%r13,4)
movb %cl, 0x2(%rbp,%r13,4)
movb %dil, 0x3(%rbp,%r13,4)
jmp 0x50ce
movb %al, 0x1(%rbp,%r15,2)
movb %al, (%rbp,%r15,2)
movb %dl, 0x3(%rbp,%r15,2)
movb %dl, 0x2(%rbp,%r15,2)
movb %cl, 0x5(%rbp,%r15,2)
movb %cl, 0x4(%rbp,%r15,2)
jmp 0x50ce
movb %al, 0x1(%rbp,%r13,8)
movb %al, (%rbp,%r13,8)
movb %dl, 0x3(%rbp,%r13,8)
movb %dl, 0x2(%rbp,%r13,8)
movb %cl, 0x5(%rbp,%r13,8)
movb %cl, 0x4(%rbp,%r13,8)
movb %dil, 0x7(%rbp,%r13,8)
movb %dil, 0x6(%rbp,%r13,8)
jmp 0x50ce
movb %al, 0x1(%rbp,%r13,2)
movb %al, (%rbp,%r13,2)
jmp 0x50ce
movb %al, 0x1(%rbp,%r13,4)
movb %al, (%rbp,%r13,4)
movb %dil, 0x3(%rbp,%r13,4)
movb %dil, 0x2(%rbp,%r13,4)
jmp 0x50ce
movb $0x8, %cl
subb %dl, %cl
shrl %cl, %esi
pushq $-0x1
popq %rax
movl %edx, %ecx
shll %cl, %eax
notl %eax
andl %esi, %eax
movq %rbp, %rdi
movq %r13, %rsi
movl %eax, %ecx
callq 0x9f1d
movq 0x18(%rsp), %r11
incq %r13
addq $0x3, %r15
jmp 0x4f05
xorl %r12d, %r12d
cmpl $0x3, (%r11)
jne 0x50fc
leaq 0x38(%rsp), %rdi
callq 0x5656
jmp 0x50fc
movl %eax, %r12d
jmp 0x50fc
pushq $0x55
jmp 0x50fa
pushq $0x52
popq %r12
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq