#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
uint32_t cgb_color_to_rgb(uint16_t c) {
  uint8_t red = ((c & 0x1F) * 255) / 31;
  uint8_t green = (((c >> 5) & 0x1F) * 255) / 31;
  uint8_t blue = (((c >> 10) & 0x1F) * 255) / 31;
  return 0xFF000000 | (red << 16) | (green << 8) | (blue << 0);
}


x86 assembly (clang, -O0):
<cgb_color_to_rgb>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1f,%eax
imul   $0xff,%eax,%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x5,%eax
and    $0x1f,%eax
imul   $0xff,%eax,%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0xa,%eax
and    $0x1f,%eax
imul   $0xff,%eax,%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x10,%eax
or     $0xff000000,%eax
mov    -0xc(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgb_color_to_rgb>:
mov    %edi,%eax
and    $0x1f,%eax
mov    %eax,%ecx
shl    $0x8,%ecx
sub    %eax,%ecx
movzwl %cx,%eax
imul   $0x843,%eax,%eax
shr    $0x10,%eax
sub    %eax,%ecx
movzwl %cx,%ecx
shr    %ecx
add    %eax,%ecx
shl    $0xc,%ecx
and    $0xfff0000,%ecx
mov    %edi,%eax
shr    $0x5,%eax
and    $0x1f,%eax
mov    %eax,%edx
shl    $0x8,%edx
sub    %eax,%edx
movzwl %dx,%eax
imul   $0x843,%eax,%eax
shr    $0x10,%eax
sub    %eax,%edx
movzwl %dx,%edx
shr    %edx
add    %eax,%edx
shl    $0x4,%edx
and    $0xfff00,%edx
shr    $0xa,%edi
and    $0x1f,%edi
mov    %edi,%eax
shl    $0x8,%eax
sub    %edi,%eax
movzwl %ax,%esi
imul   $0x843,%esi,%esi
shr    $0x10,%esi
sub    %esi,%eax
movzwl %ax,%eax
shr    %eax
add    %esi,%eax
shr    $0x4,%eax
or     %ecx,%eax
or     %edx,%eax
or     $0xff000000,%eax
ret

LLVM IR (-O0):
define i32 @cgb_color_to_rgb(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = and i32 %6, 31
%8 = mul nsw i32 %7, 255
%9 = sdiv i32 %8, 31
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = ashr i32 %10, 5
%12 = and i32 %11, 31
%13 = mul nsw i32 %12, 255
%14 = sdiv i32 %13, 31
store i32 %14, i32* %4
%15 = load i32, i32* %2
%16 = ashr i32 %15, 10
%17 = and i32 %16, 31
%18 = mul nsw i32 %17, 255
%19 = sdiv i32 %18, 31
store i32 %19, i32* %5
%20 = load i32, i32* %3
%21 = shl i32 %20, 16
%22 = or i32 -16777216, %21
%23 = load i32, i32* %4
%24 = shl i32 %23, 8
%25 = or i32 %22, %24
%26 = load i32, i32* %5
%27 = shl i32 %26, 0
%28 = or i32 %25, %27
ret i32 %28
}

LLVM IR (-O2):
define i32 @cgb_color_to_rgb(i32 %0) {
%2 = trunc i32 %0 to i16
%3 = and i16 %2, 31
%4 = mul nuw nsw i16 %3, 255
%5 = udiv i16 %4, 31
%6 = zext i16 %5 to i32
%7 = lshr i16 %2, 5
%8 = and i16 %7, 31
%9 = mul nuw nsw i16 %8, 255
%10 = udiv i16 %9, 31
%11 = zext i16 %10 to i32
%12 = lshr i16 %2, 10
%13 = and i16 %12, 31
%14 = mul nuw nsw i16 %13, 255
%15 = udiv i16 %14, 31
%16 = zext i16 %15 to i32
%17 = shl nuw nsw i32 %6, 16
%18 = shl nuw nsw i32 %11, 8
%19 = or i32 %17, %16
%20 = or i32 %19, %18
%21 = or i32 %20, -16777216
ret i32 %21
}