// File: /workspace/github_cpp_makefile_star2_O2/Lut99[P]RayTracer/src/lib/LodePNG.cpp
// Function: lodepng_convert_rgb(unsigned int*, unsigned int*, unsigned int*, unsigned int, unsigned int, unsigned int, LodePNGColorMode const*, LodePNGColorMode const*)
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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %r11d
movq %rdx, %r10
movq 0x38(%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), %r15d
movl $0x1f, %eax
cmpq $0x6, %r15
ja 0x77a0f
movq 0x30(%rsp), %rbx
movl $0x10, %ecx
subl 0x4(%rbx), %ecx
leaq 0x18c8d(%rip), %r12     # 0x90588
movslq (%r12,%r15,4), %r15
addq %r12, %r15
movl $0x52, %ebp
jmpq *%r15
imull %r11d, %edx
movl %edx, %r8d
movl %edx, %r11d
jmp 0x77922
imull %edx, %r11d
imull %edx, %r8d
imull %r9d, %edx
movl (%rbx), %r9d
cmpq $0x6, %r9
ja 0x77a0f
leaq 0x18c6e(%rip), %r14     # 0x905a4
movslq (%r14,%r9,4), %r9
addq %r14, %r9
jmpq *%r9
shrl %cl, %r11d
movl %r11d, (%rdi)
jmp 0x77959
shrl %cl, %r11d
shrl %cl, %r8d
shrl %cl, %edx
movl %r11d, (%rdi)
movl %r8d, (%rsi)
movl %edx, (%r10)
xorl %eax, %eax
jmp 0x77a0f
movl %r11d, %edx
cmpq %rdx, 0x10(%r14)
jbe 0x77a0d
movq 0x8(%r14), %rdx
shll $0x2, %r11d
movzbl (%rdx,%r11), %r8d
movzbl 0x1(%rdx,%r11), %r9d
movzbl 0x2(%rdx,%r11), %edx
imull $0x101, %r8d, %r11d     # imm = 0x101
imull $0x101, %r9d, %r8d      # imm = 0x101
imull $0x101, %edx, %edx      # imm = 0x101
jmp 0x77922
movl %r11d, %eax
shrl $0x8, %eax
movzbl %r11b, %ecx
cmpl %ecx, %eax
jne 0x77a0d
movl %r8d, %ecx
shrl $0x8, %ecx
movzbl %r8b, %esi
cmpl %esi, %ecx
jne 0x77a0d
movl %edx, %esi
shrl $0x8, %esi
movzbl %dl, %edx
cmpl %edx, %esi
jne 0x77a0d
movq 0x10(%rbx), %r8
xorl %edx, %edx
movl $0x2, %r9d
movl %edx, %r10d
cmpq %r10, %r8
jbe 0x77a0d
leal -0x2(%r9), %r11d
movq 0x8(%rbx), %r10
movzbl (%r10,%r11), %r11d
cmpl %r11d, %eax
jne 0x77a05
leal -0x1(%r9), %r11d
movzbl (%r10,%r11), %r11d
cmpl %r11d, %ecx
jne 0x77a05
movl %r9d, %r11d
movzbl (%r10,%r11), %r10d
cmpl %r10d, %esi
je 0x77a18
incl %edx
addl $0x4, %r9d
jmp 0x779d0
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %edx, (%rdi)
jmp 0x77959