#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 uint16_t;

/* Variables and functions */
void rgb565_be(const uint16_t d, uint8_t *r, uint8_t *g, uint8_t *b) {
  *r = (d & 0xf8) | (d >> 5 & 7);
  *g = (d << 5 & 0xe0) | (d >> 11 & 0x1c) | (d >> 1 & 3);
  *b = (d >> 5 & 0xf8) | (d >> 10 & 0x7);
}


x86 assembly (clang, -O0):
<rgb565_be>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%ecx
and    $0xf8,%ecx
mov    -0x4(%rbp),%eax
sar    $0x5,%eax
and    $0x7,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
shl    $0x5,%ecx
and    $0xe0,%ecx
mov    -0x4(%rbp),%eax
sar    $0xb,%eax
and    $0x1c,%eax
or     %eax,%ecx
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
and    $0x3,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
sar    $0x5,%ecx
and    $0xf8,%ecx
mov    -0x4(%rbp),%eax
sar    $0xa,%eax
and    $0x7,%eax
or     %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb565_be>:
mov    %edi,%r8d
and    $0xf8,%r8d
mov    %edi,%r9d
sar    $0x5,%r9d
mov    %r9d,%eax
and    $0x7,%eax
or     %r8d,%eax
mov    %eax,(%rsi)
mov    %edi,%eax
shl    $0x5,%eax
movzbl %al,%eax
mov    %edi,%esi
shr    $0xb,%esi
and    $0x1c,%esi
or     %eax,%esi
mov    %edi,%eax
shr    %eax
and    $0x3,%eax
or     %esi,%eax
mov    %eax,(%rdx)
and    $0xf8,%r9d
shr    $0xa,%edi
and    $0x7,%edi
or     %r9d,%edi
mov    %edi,(%rcx)
ret

LLVM IR (-O0):
define void @rgb565_be(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%9 = load i32, i32* %5
%10 = and i32 %9, 248
%11 = load i32, i32* %5
%12 = ashr i32 %11, 5
%13 = and i32 %12, 7
%14 = or i32 %10, %13
%15 = load i32*, i32** %6
store i32 %14, i32* %15
%16 = load i32, i32* %5
%17 = shl i32 %16, 5
%18 = and i32 %17, 224
%19 = load i32, i32* %5
%20 = ashr i32 %19, 11
%21 = and i32 %20, 28
%22 = or i32 %18, %21
%23 = load i32, i32* %5
%24 = ashr i32 %23, 1
%25 = and i32 %24, 3
%26 = or i32 %22, %25
%27 = load i32*, i32** %7
store i32 %26, i32* %27
%28 = load i32, i32* %5
%29 = ashr i32 %28, 5
%30 = and i32 %29, 248
%31 = load i32, i32* %5
%32 = ashr i32 %31, 10
%33 = and i32 %32, 7
%34 = or i32 %30, %33
%35 = load i32*, i32** %8
store i32 %34, i32* %35
ret void
}

LLVM IR (-O2):
define void @rgb565_be(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = and i32 %0, 248
%6 = ashr i32 %0, 5
%7 = and i32 %6, 7
%8 = or i32 %7, %5
store i32 %8, i32* %1
%9 = shl i32 %0, 5
%10 = and i32 %9, 224
%11 = lshr i32 %0, 11
%12 = and i32 %11, 28
%13 = or i32 %10, %12
%14 = lshr i32 %0, 1
%15 = and i32 %14, 3
%16 = or i32 %13, %15
store i32 %16, i32* %2
%17 = and i32 %6, 248
%18 = lshr i32 %0, 10
%19 = and i32 %18, 7
%20 = or i32 %17, %19
store i32 %20, i32* %3
ret void
}