// File: /workspace/github_cpp_makefile_star2_O3/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, %r12d
movl %r8d, %r13d
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %rbp
movq %rdx, %rdi
movq %rcx, %rsi
callq 0x68b8
testl %eax, %eax
je 0x640e
movl %r13d, %edi
movl %r12d, %esi
movq %r15, %rdx
callq 0x5c52
xorl %r15d, %r15d
testq %rax, %rax
je 0x68a6
xorl %ecx, %ecx
movb (%rbx,%rcx), %dl
movb %dl, (%rbp,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x63fa
jmp 0x68a6
movl %r13d, 0x24(%rsp)
movq %rbx, 0x30(%rsp)
cmpl $0x3, (%r14)
movq %r15, 0x28(%rsp)
movq %r14, %r9
movq %r14, 0x18(%rsp)
jne 0x64de
movb 0x4(%r9), %cl
movl $0x1, %ebx
shll %cl, %ebx
movq 0x10(%r9), %r15
movl $0x1000, %edi           # imm = 0x1000
callq 0x2270
movq %rax, %r13
movq %rax, 0x38(%rsp)
movl $0x8, %eax
movq $0x0, -0x8(%r13,%rax)
movl $0xffffffff, (%r13,%rax) # imm = 0xFFFFFFFF
addq $0x10, %rax
cmpq $0x1008, %rax           # imm = 0x1008
jne 0x6455
movl $0xffffffff, 0x40(%rsp) # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x64d4
movslq %ebx, %rbx
cmpq %rbx, %r15
cmovbq %r15, %rbx
cmpq $0x1, %rbx
adcq $0x0, %rbx
xorl %r15d, %r15d
movq 0x18(%rsp), %r9
movq 0x8(%r9), %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 %r13, %rdi
movl %r15d, %r9d
callq 0x6925
movq 0x18(%rsp), %r9
incq %r15
cmpq %r15, %rbx
jne 0x649a
movq 0x28(%rsp), %r15
jmp 0x64de
movq 0x28(%rsp), %r15
movq 0x18(%rsp), %r9
cmpl $0x10, 0x4(%r15)
jne 0x6611
cmpl $0x10, 0x4(%r9)
jne 0x6611
imull 0x24(%rsp), %r12d
testl %r12d, %r12d
je 0x687e
movq %r12, %r13
xorl %r12d, %r12d
xorl %edi, %edi
xorl %ebx, %ebx
movq %rdi, %r14
movw %r12w, 0x16(%rsp)
movw %r12w, 0x14(%rsp)
movw %r12w, 0x12(%rsp)
movw %r12w, 0x10(%rsp)
movq %r15, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq 0x30(%rsp), %r8
movq %rbx, %r9
callq 0x6a28
testl %eax, %eax
jne 0x6893
movq 0x18(%rsp), %r9
cmpl $0x10, 0x4(%r9)
jne 0x68a0
movl (%r9), %esi
cmpq $0x6, %rsi
movq %r14, %rdi
ja 0x65f7
movzwl 0x16(%rsp), %eax
movzwl 0x14(%rsp), %edx
movzwl 0x12(%rsp), %r10d
movzwl 0x10(%rsp), %ecx
leaq 0xbb8b(%rip), %r8       # 0x1211c
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
rolw $0x8, %ax
movw %ax, (%rbp,%rbx,2)
jmp 0x65f7
movb %ah, (%rbp,%rbx,4)
movb %al, 0x1(%rbp,%rbx,4)
movb %ch, 0x2(%rbp,%rbx,4)
movb %cl, 0x3(%rbp,%rbx,4)
jmp 0x65f7
movb %ah, (%rbp,%rdi)
movb %al, 0x1(%rbp,%rdi)
movb %dh, 0x2(%rbp,%rdi)
movb %dl, 0x3(%rbp,%rdi)
movl %r10d, %eax
movb %ah, 0x4(%rbp,%rdi)
movb %al, 0x5(%rbp,%rdi)
jmp 0x65f7
movb %ah, (%rbp,%rbx,8)
movb %al, 0x1(%rbp,%rbx,8)
movb %dh, 0x2(%rbp,%rbx,8)
movb %dl, 0x3(%rbp,%rbx,8)
movl %r10d, %eax
movb %ah, 0x4(%rbp,%rbx,8)
movb %al, 0x5(%rbp,%rbx,8)
movb %ch, 0x6(%rbp,%rbx,8)
movb %cl, 0x7(%rbp,%rbx,8)
incq %rbx
addq $0x6, %rdi
cmpq %rbx, %r13
movq 0x28(%rsp), %r15
jne 0x650d
jmp 0x687e
imull 0x24(%rsp), %r12d
testl %r12d, %r12d
je 0x687e
movq %r12, %rbx
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %eax, %eax
movb %al, 0x16(%rsp)
movb %al, 0x14(%rsp)
movb %al, 0x12(%rsp)
movb %al, 0x10(%rsp)
movq %r15, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq 0x30(%rsp), %r8
movq %r14, %r9
callq 0x6bbe
testl %eax, %eax
jne 0x6893
movq 0x18(%rsp), %r9
movl (%r9), %r8d
cmpq $0x6, %r8
movq 0x28(%rsp), %r15
ja 0x686e
movb 0x16(%rsp), %dl
movzbl %dl, %edi
movb 0x14(%rsp), %sil
movb 0x12(%rsp), %cl
movb 0x10(%rsp), %al
leaq 0xba66(%rip), %r10      # 0x12100
movslq (%r10,%r8,4), %r8
addq %r10, %r8
jmpq *%r8
movl 0x4(%r9), %esi
cmpq $0x10, %rsi
je 0x67fc
cmpl $0x8, %esi
jne 0x681e
movb %dl, (%rbp,%r14)
jmp 0x686e
shll $0x4, %edi
movq (%r13,%rdi), %rdx
testq %rdx, %rdx
je 0x6898
movzbl %sil, %esi
shll $0x4, %esi
movq (%rdx,%rsi), %rdx
testq %rdx, %rdx
je 0x6898
movzbl %cl, %ecx
shll $0x4, %ecx
movq (%rdx,%rcx), %rcx
testq %rcx, %rcx
je 0x6898
movzbl %al, %eax
shll $0x4, %eax
movl 0x8(%rcx,%rax), %r8d
testl %r8d, %r8d
js 0x6898
movl 0x4(%r9), %esi
cmpq $0x8, %rsi
jne 0x67d9
movb %r8b, (%rbp,%r14)
jmp 0x686e
cmpl $0x8, 0x4(%r9)
jne 0x6789
movb %dl, (%rbp,%r12)
movb %sil, 0x1(%rbp,%r12)
movb %cl, 0x2(%rbp,%r12)
jmp 0x686e
movl 0x4(%r9), %ecx
cmpl $0x10, %ecx
je 0x6808
cmpl $0x8, %ecx
jne 0x686e
movb %dl, (%rbp,%r14,2)
movb %al, 0x1(%rbp,%r14,2)
jmp 0x686e
cmpl $0x8, 0x4(%r9)
jne 0x67ac
movb %dl, (%rbp,%r14,4)
movb %sil, 0x1(%rbp,%r14,4)
movb %cl, 0x2(%rbp,%r14,4)
movb %al, 0x3(%rbp,%r14,4)
jmp 0x686e
movb %dl, 0x1(%rbp,%r12,2)
movb %dl, (%rbp,%r12,2)
movb %sil, 0x3(%rbp,%r12,2)
movb %sil, 0x2(%rbp,%r12,2)
movb %cl, 0x5(%rbp,%r12,2)
movb %cl, 0x4(%rbp,%r12,2)
jmp 0x686e
movb %dl, 0x1(%rbp,%r14,8)
movb %dl, (%rbp,%r14,8)
movb %sil, 0x3(%rbp,%r14,8)
movb %sil, 0x2(%rbp,%r14,8)
movb %cl, 0x5(%rbp,%r14,8)
movb %cl, 0x4(%rbp,%r14,8)
movb %al, 0x7(%rbp,%r14,8)
movb %al, 0x6(%rbp,%r14,8)
jmp 0x686e
movl $0x8, %eax
xorl %edx, %edx
divl %esi
movl %eax, %edi
movq %r14, %rax
xorl %edx, %edx
divq %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %esi, %ecx
shll %cl, %eax
notl %eax
andl %eax, %r8d
jmp 0x6849
movb %dl, 0x1(%rbp,%r14,2)
movb %dl, (%rbp,%r14,2)
jmp 0x686e
movb %dl, 0x1(%rbp,%r14,4)
movb %dl, (%rbp,%r14,4)
movb %al, 0x3(%rbp,%r14,4)
movb %al, 0x2(%rbp,%r14,4)
jmp 0x686e
movb $0x8, %cl
subb %sil, %cl
shrl %cl, %edi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %esi, %ecx
shll %cl, %r8d
notl %r8d
andl %edi, %r8d
movl $0x8, %eax
xorl %edx, %edx
divl %esi
movl %eax, %edi
movq %r14, %rax
xorl %edx, %edx
divq %rdi
movl %edx, %ecx
notl %ecx
addl %edi, %ecx
imull %esi, %ecx
shll %cl, %r8d
imulq %r14, %rsi
shrq $0x3, %rsi
testq %rdx, %rdx
je 0x6869
orb %r8b, (%rbp,%rsi)
jmp 0x686e
movb %r8b, (%rbp,%rsi)
incq %r14
addq $0x3, %r12
cmpq %r14, %rbx
jne 0x6629
xorl %r15d, %r15d
cmpl $0x3, (%r9)
jne 0x68a6
leaq 0x38(%rsp), %rdi
callq 0x6ecf
jmp 0x68a6
movl %eax, %r15d
jmp 0x68a6
movl $0x52, %r15d
jmp 0x68a6
movl $0x55, %r15d
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq