// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq 0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
subl $0x1, %ecx
movl $0xffff, %eax           # imm = 0xFFFF
xorl %edx, %edx
divl %ecx
movl %eax, -0x3c(%rbp)
movq 0x10(%rbp), %rcx
movl $0x10, %eax
subl 0x4(%rcx), %eax
movl %eax, -0x40(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x99b8
movq 0x18(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x99cd
movl -0x24(%rbp), %eax
imull -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl %eax, -0x34(%rbp)
movl %eax, -0x30(%rbp)
jmp 0x9a96
movq 0x18(%rbp), %rax
cmpl $0x2, (%rax)
je 0x99df
movq 0x18(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x9a02
movl -0x24(%rbp), %eax
imull -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
imull -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
imull -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x9a94
movq 0x18(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x9a86
movl -0x24(%rbp), %eax
movq 0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jb 0x9a24
movl $0x52, -0x4(%rbp)
jmp 0x9c0e
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
imull $0x101, %eax, %eax      # imm = 0x101
movl %eax, -0x30(%rbp)
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
imull $0x101, %eax, %eax      # imm = 0x101
movl %eax, -0x34(%rbp)
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
imull $0x101, %eax, %eax      # imm = 0x101
movl %eax, -0x38(%rbp)
jmp 0x9a92
movl $0x1f, -0x4(%rbp)
jmp 0x9c0e
jmp 0x9a94
jmp 0x9a96
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x9aa8
movq 0x10(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x9abd
movl -0x30(%rbp), %eax
movl -0x40(%rbp), %ecx
shrl %cl, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x9c07
movq 0x10(%rbp), %rax
cmpl $0x2, (%rax)
je 0x9acf
movq 0x10(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x9b04
movl -0x30(%rbp), %eax
movl -0x40(%rbp), %ecx
shrl %cl, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
movl -0x40(%rbp), %ecx
shrl %cl, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x38(%rbp), %eax
movl -0x40(%rbp), %ecx
shrl %cl, %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x9c05
movq 0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x9bfc
movl -0x30(%rbp), %eax
shrl $0x8, %eax
movl -0x30(%rbp), %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
jne 0x9b4a
movl -0x34(%rbp), %eax
shrl $0x8, %eax
movl -0x34(%rbp), %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
jne 0x9b4a
movl -0x38(%rbp), %eax
shrl $0x8, %eax
movl -0x38(%rbp), %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
je 0x9b56
movl $0x52, -0x4(%rbp)
jmp 0x9c0e
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x9bf3
movl -0x44(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x48(%rbp)
movl -0x30(%rbp), %eax
shrl $0x8, %eax
movq 0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x48(%rbp), %edx
addl $0x0, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x9be3
movl -0x34(%rbp), %eax
shrl $0x8, %eax
movq 0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x48(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x9be3
movl -0x38(%rbp), %eax
shrl $0x8, %eax
movq 0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x48(%rbp), %edx
addl $0x2, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x9be3
movl -0x44(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x9c0e
jmp 0x9be5
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x9b5d
movl $0x52, -0x4(%rbp)
jmp 0x9c0e
movl $0x1f, -0x4(%rbp)
jmp 0x9c0e
jmp 0x9c07
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)