// File: /workspace/github_c_makefile_star2_O1/tditlu[P]shadetabler/src/lodepng/lodepng.c
// Function: lodepng_convert_rgb
unsigned lodepng_convert_rgb(
    unsigned* r_out, unsigned* g_out, unsigned* b_out,
    unsigned r_in, unsigned g_in, unsigned b_in,
    const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in) {
  unsigned r = 0, g = 0, b = 0;
  unsigned mul = 65535 / ((1u << mode_in->bitdepth) - 1u); /*65535, 21845, 4369, 257, 1*/
  unsigned shift = 16 - mode_out->bitdepth;

  if(mode_in->colortype == LCT_GREY || mode_in->colortype == LCT_GREY_ALPHA) {
    r = g = b = r_in * mul;
  } else if(mode_in->colortype == LCT_RGB || mode_in->colortype == LCT_RGBA) {
    r = r_in * mul;
    g = g_in * mul;
    b = b_in * mul;
  } else if(mode_in->colortype == LCT_PALETTE) {
    if(r_in >= mode_in->palettesize) return 82;
    r = mode_in->palette[r_in * 4 + 0] * 257u;
    g = mode_in->palette[r_in * 4 + 1] * 257u;
    b = mode_in->palette[r_in * 4 + 2] * 257u;
  } else {
    return 31;
  }

  /* now convert to output format */
  if(mode_out->colortype == LCT_GREY || mode_out->colortype == LCT_GREY_ALPHA) {
    *r_out = r >> shift ;
  } else if(mode_out->colortype == LCT_RGB || mode_out->colortype == LCT_RGBA) {
    *r_out = r >> shift ;
    *g_out = g >> shift ;
    *b_out = b >> shift ;
  } else if(mode_out->colortype == LCT_PALETTE) {
    unsigned i;
    /* a 16-bit color cannot be in the palette */
    if((r >> 8) != (r & 255) || (g >> 8) != (g & 255) || (b >> 8) != (b & 255)) return 82;
    for(i = 0; i < mode_out->palettesize; i++) {
      unsigned j = i * 4;
      if((r >> 8) == mode_out->palette[j + 0] && (g >> 8) == mode_out->palette[j + 1] &&
          (b >> 8) == mode_out->palette[j + 2]) {
        *r_out = i;
        return 0;
      }
    }
    return 82;
  } else {
    return 31;
  }

  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %ecx, %r11d
movq %rdx, %r10
movq 0x28(%rsp), %r14
movb 0x4(%r14), %cl
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
shll %cl, %ebx
notl %ebx
movl $0xffff, %eax           # imm = 0xFFFF
xorl %edx, %edx
divl %ebx
movl %eax, %edx
movl (%r14), %eax
cmpq $0x6, %rax
ja 0x7485
movq 0x20(%rsp), %rbx
movl $0x10, %ecx
subl 0x4(%rbx), %ecx
leaq 0xad9e(%rip), %r15      # 0x121c4
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
imull %r11d, %edx
movl %edx, %r8d
movl %edx, %r11d
jmp 0x7447
imull %edx, %r11d
imull %edx, %r8d
imull %r9d, %edx
movl (%rbx), %eax
cmpq $0x6, %rax
ja 0x7485
leaq 0xad8a(%rip), %r9       # 0x121e0
movslq (%r9,%rax,4), %r14
addq %r9, %r14
movl $0x1f, %eax
jmpq *%r14
shrl %cl, %r11d
movl %r11d, (%rdi)
jmp 0x747e
shrl %cl, %r11d
shrl %cl, %r8d
shrl %cl, %edx
movl %r11d, (%rdi)
movl %r8d, (%rsi)
movl %edx, (%r10)
xorl %eax, %eax
jmp 0x7554
movl $0x1f, %eax
jmp 0x7554
movl %r11d, %edx
movl $0x52, %eax
cmpq %rdx, 0x10(%r14)
jbe 0x7554
movq 0x8(%r14), %rax
shll $0x2, %r11d
movzbl (%rax,%r11), %edx
movzbl 0x1(%rax,%r11), %r9d
movzbl 0x2(%rax,%r11), %eax
movl %edx, %r11d
shll $0x8, %r11d
orl %edx, %r11d
movl %r9d, %r8d
shll $0x8, %r8d
orl %r9d, %r8d
movl %eax, %edx
shll $0x8, %edx
orl %eax, %edx
jmp 0x7447
movl %r11d, %ecx
shrl $0x8, %ecx
movzbl %r11b, %esi
movl $0x52, %eax
cmpl %esi, %ecx
jne 0x7554
movl %r8d, %esi
shrl $0x8, %esi
movzbl %r8b, %r8d
cmpl %r8d, %esi
jne 0x7554
movl %edx, %r8d
shrl $0x8, %r8d
movzbl %dl, %edx
cmpl %edx, %r8d
jne 0x7554
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
je 0x7554
movq 0x8(%rbx), %r10
xorl %r9d, %r9d
movl $0x2, %r11d
leal -0x2(%r11), %ebx
movzbl (%r10,%rbx), %ebx
cmpl %ebx, %ecx
jne 0x7548
leal -0x1(%r11), %ebx
movzbl (%r10,%rbx), %ebx
cmpl %ebx, %esi
jne 0x7548
movl %r11d, %ebx
movzbl (%r10,%rbx), %ebx
cmpl %ebx, %r8d
je 0x755a
incl %r9d
addl $0x4, %r11d
cmpq %r9, %rdx
ja 0x7521
popq %rbx
popq %r14
popq %r15
retq
movl %r9d, (%rdi)
jmp 0x747e