// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movl %r9d, %r14d
movl %r8d, %r15d
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, 0x18(%rsp)
movq %rdx, %rdi
movq %rcx, %rsi
callq 0x6843
testl %eax, %eax
je 0x6283
movl %r15d, %edi
movl %r14d, %esi
movq %r12, %rdx
callq 0x5aa8
xorl %r13d, %r13d
testq %rax, %rax
je 0x6831
xorl %ecx, %ecx
movq 0x18(%rsp), %rsi
movb (%rbx,%rcx), %dl
movb %dl, (%rsi,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x6270
jmp 0x6831
movq %r12, 0x40(%rsp)
movq %r14, 0x38(%rsp)
movq %rbx, 0x48(%rsp)
cmpl $0x3, (%rbp)
jne 0x632d
movb 0x4(%rbp), %cl
movl $0x1, %ebx
shll %cl, %ebx
movq 0x10(%rbp), %r14
movl $0x1000, %edi           # imm = 0x1000
callq 0x2270
movq %rax, 0x50(%rsp)
xorl %ecx, %ecx
movq $0x0, (%rax,%rcx)
movl $0xffffffff, 0x8(%rax,%rcx) # imm = 0xFFFFFFFF
addq $0x10, %rcx
cmpq $0x1000, %rcx           # imm = 0x1000
jne 0x62bb
movl $0xffffffff, 0x58(%rsp) # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x632d
movslq %ebx, %rbx
cmpq %rbx, %r14
cmovbq %r14, %rbx
cmpq $0x1, %rbx
adcq $0x0, %rbx
xorl %r12d, %r12d
leaq 0x50(%rsp), %r13
movq 0x8(%rbp), %rax
movzbl (%rax,%r12,4), %esi
movzbl 0x1(%rax,%r12,4), %edx
movzbl 0x2(%rax,%r12,4), %ecx
movzbl 0x3(%rax,%r12,4), %r8d
movq %r13, %rdi
movl %r12d, %r9d
callq 0x68b0
incq %r12
cmpq %r12, %rbx
jne 0x62ff
movq 0x40(%rsp), %rax
cmpl $0x10, 0x4(%rax)
movq %rbp, 0x30(%rsp)
jne 0x64c2
cmpl $0x10, 0x4(%rbp)
jne 0x64c2
movq 0x38(%rsp), %rcx
imull %r15d, %ecx
testl %ecx, %ecx
setne %r12b
je 0x6811
movq %rcx, %rax
negq %rax
movq %rax, 0x20(%rsp)
movl $0x1, %ebx
movl $0x5, %ebp
movq %rcx, 0x38(%rsp)
leaq -0x1(%rbx), %r9
xorl %r14d, %r14d
movw %r14w, 0x16(%rsp)
movw %r14w, 0x14(%rsp)
movw %r14w, 0x12(%rsp)
movw %r14w, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq 0x48(%rsp), %r8
callq 0x69a3
testl %eax, %eax
je 0x63cc
movl %eax, %r15d
movl %eax, %r13d
jmp 0x6427
movq 0x30(%rsp), %rax
cmpl $0x10, 0x4(%rax)
sete %r14b
movl $0x55, %r15d
jne 0x6421
movl (%rax), %esi
xorl %r15d, %r15d
cmpq $0x6, %rsi
ja 0x6427
movzwl 0x16(%rsp), %eax
movzwl 0x14(%rsp), %edx
movzwl 0x12(%rsp), %r8d
movzwl 0x10(%rsp), %ecx
leaq 0xbc44(%rip), %rdi      # 0x1204c
movslq (%rdi,%rsi,4), %rsi
addq %rdi, %rsi
jmpq *%rsi
rolw $0x8, %ax
movq 0x18(%rsp), %rcx
movw %ax, -0x2(%rcx,%rbx,2)
jmp 0x6427
movl $0x55, %r13d
testb %r14b, %r14b
je 0x6814
movq 0x38(%rsp), %rcx
cmpq %rcx, %rbx
setb %r12b
movq 0x20(%rsp), %rax
addq %rbx, %rax
incq %rax
incq %rbx
addq $0x6, %rbp
cmpq $0x1, %rax
jne 0x637a
jmp 0x6814
movq 0x18(%rsp), %rdx
movb %ah, -0x4(%rdx,%rbx,4)
movb %al, -0x3(%rdx,%rbx,4)
movb %ch, -0x2(%rdx,%rbx,4)
movb %cl, -0x1(%rdx,%rbx,4)
jmp 0x6427
movq 0x18(%rsp), %rcx
movb %ah, -0x5(%rcx,%rbp)
movb %al, -0x4(%rcx,%rbp)
movb %dh, -0x3(%rcx,%rbp)
movb %dl, -0x2(%rcx,%rbp)
movl %r8d, %eax
movb %ah, -0x1(%rcx,%rbp)
movb %al, (%rcx,%rbp)
jmp 0x6427
movq 0x18(%rsp), %rsi
movb %ah, -0x8(%rsi,%rbx,8)
movb %al, -0x7(%rsi,%rbx,8)
movb %dh, -0x6(%rsi,%rbx,8)
movb %dl, -0x5(%rsi,%rbx,8)
movl %r8d, %eax
movb %ah, -0x4(%rsi,%rbx,8)
movb %al, -0x3(%rsi,%rbx,8)
movb %ch, -0x2(%rsi,%rbx,8)
movb %cl, -0x1(%rsi,%rbx,8)
jmp 0x6427
movq 0x38(%rsp), %rax
imull %r15d, %eax
testl %eax, %eax
setne %cl
je 0x6801
movq %rax, 0x38(%rsp)
negq %rax
movq %rax, 0x60(%rsp)
movl $0x1, %ebx
xorl %ebp, %ebp
movb %cl, 0x2f(%rsp)
leaq -0x1(%rbx), %r14
xorl %r12d, %r12d
movb %r12b, 0x16(%rsp)
movb %r12b, 0x14(%rsp)
movb %r12b, 0x12(%rsp)
movb %r12b, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
leaq 0x16(%rsp), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x12(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq 0x48(%rsp), %r8
movq %r14, %r9
callq 0x6b39
movl %eax, %r15d
movl $0x0, %r8d
movl %eax, %r13d
testl %eax, %eax
jne 0x67d1
movq 0x30(%rsp), %rax
movl (%rax), %r9d
movb $0x1, %r8b
cmpq $0x6, %r9
ja 0x67c0
movb 0x16(%rsp), %dl
movzbl %dl, %edi
movb 0x14(%rsp), %sil
movb 0x12(%rsp), %cl
movb 0x10(%rsp), %al
leaq 0xbab9(%rip), %r10      # 0x12030
movslq (%r10,%r9,4), %r9
addq %r10, %r9
jmpq *%r9
movq 0x30(%rsp), %rax
movl 0x4(%rax), %esi
cmpq $0x10, %rsi
je 0x66e9
cmpl $0x8, %esi
jne 0x6715
movq 0x18(%rsp), %rax
movb %dl, -0x1(%rax,%rbx)
jmp 0x67c0
movq 0x50(%rsp), %rdx
shll $0x4, %edi
movq (%rdx,%rdi), %rdx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
testq %rdx, %rdx
je 0x65eb
movzbl %sil, %esi
shll $0x4, %esi
movq (%rdx,%rsi), %rdx
testq %rdx, %rdx
je 0x65eb
movzbl %cl, %ecx
shll $0x4, %ecx
movq (%rdx,%rcx), %rcx
testq %rcx, %rcx
je 0x65eb
movzbl %al, %eax
shll $0x4, %eax
movl 0x8(%rcx,%rax), %r9d
testl %r9d, %r9d
js 0x66db
movq 0x30(%rsp), %rax
movl 0x4(%rax), %esi
cmpq $0x8, %rsi
jne 0x6764
movq 0x18(%rsp), %rax
movb %r9b, -0x1(%rax,%rbx)
jmp 0x67bd
movq 0x30(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x668c
movq 0x18(%rsp), %rax
movb %dl, (%rax,%rbp)
movb %sil, 0x1(%rax,%rbp)
movb %cl, 0x2(%rax,%rbp)
jmp 0x67c0
movq 0x30(%rsp), %rcx
movl 0x4(%rcx), %ecx
cmpl $0x10, %ecx
je 0x66fb
cmpl $0x8, %ecx
movl 0x20(%rsp), %esi
jne 0x67c4
movq 0x18(%rsp), %rcx
movb %dl, -0x2(%rcx,%rbx,2)
movb %al, -0x1(%rcx,%rbx,2)
jmp 0x67c4
movq 0x30(%rsp), %rdi
cmpl $0x8, 0x4(%rdi)
jne 0x66af
movq 0x18(%rsp), %rdi
movb %dl, -0x4(%rdi,%rbx,4)
movb %sil, -0x3(%rdi,%rbx,4)
movb %cl, -0x2(%rdi,%rbx,4)
movb %al, -0x1(%rdi,%rbx,4)
jmp 0x67c0
movq 0x18(%rsp), %rax
movb %dl, 0x1(%rax,%rbp,2)
movb %dl, (%rax,%rbp,2)
movb %sil, 0x3(%rax,%rbp,2)
movb %sil, 0x2(%rax,%rbp,2)
movb %cl, 0x5(%rax,%rbp,2)
movb %cl, 0x4(%rax,%rbp,2)
jmp 0x67c0
movq 0x18(%rsp), %rdi
movb %dl, -0x7(%rdi,%rbx,8)
movb %dl, -0x8(%rdi,%rbx,8)
movb %sil, -0x5(%rdi,%rbx,8)
movb %sil, -0x6(%rdi,%rbx,8)
movb %cl, -0x3(%rdi,%rbx,8)
movb %cl, -0x4(%rdi,%rbx,8)
movb %al, -0x1(%rdi,%rbx,8)
movb %al, -0x2(%rdi,%rbx,8)
jmp 0x67c0
movl $0x52, %r12d
xorl %r8d, %r8d
jmp 0x67c0
movq 0x18(%rsp), %rax
movb %dl, -0x1(%rax,%rbx,2)
movb %dl, -0x2(%rax,%rbx,2)
jmp 0x67c0
movq 0x18(%rsp), %rcx
movb %dl, -0x3(%rcx,%rbx,4)
movb %dl, -0x4(%rcx,%rbx,4)
movb %al, -0x1(%rcx,%rbx,4)
movb %al, -0x2(%rcx,%rbx,4)
jmp 0x67c0
movb $0x8, %cl
subb %sil, %cl
shrl %cl, %edi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %esi, %ecx
shll %cl, %r9d
notl %r9d
andl %edi, %r9d
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, %r9d
imulq %rsi, %r14
shrq $0x3, %r14
testq %rdx, %rdx
je 0x67a9
movq 0x18(%rsp), %rax
orb %r9b, (%rax,%r14)
jmp 0x67c0
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, %r9d
movl %edx, %ecx
notl %ecx
addl %edi, %ecx
imull %esi, %ecx
shll %cl, %r9d
imulq %rsi, %r14
shrq $0x3, %r14
testq %rdx, %rdx
je 0x67b4
movq 0x18(%rsp), %rax
orb %r9b, (%rax,%r14)
jmp 0x67bd
movq 0x18(%rsp), %rax
movb %r9b, (%rax,%r14)
jmp 0x67c0
movq 0x18(%rsp), %rax
movb %r9b, (%rax,%r14)
xorl %r12d, %r12d
movl 0x20(%rsp), %esi
testb %r8b, %r8b
cmovel %r12d, %esi
movl %r12d, %r15d
movl %esi, %r13d
testb %r8b, %r8b
je 0x6806
cmpq 0x38(%rsp), %rbx
setb %cl
movq 0x60(%rsp), %rax
addq %rbx, %rax
incq %rax
incq %rbx
addq $0x3, %rbp
movl %r13d, 0x20(%rsp)
cmpq $0x1, %rax
jne 0x64ea
jmp 0x680a
xorl %r15d, %r15d
jmp 0x680a
movb 0x2f(%rsp), %cl
testb $0x1, %cl
je 0x681a
jmp 0x6831
xorl %r15d, %r15d
testb $0x1, %r12b
jne 0x6831
movq 0x30(%rsp), %rax
cmpl $0x3, (%rax)
jne 0x682e
leaq 0x50(%rsp), %rdi
callq 0x6e4b
movl %r15d, %r13d
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq