#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 /*<<< orphan*/ uint8_t;
typedef int uint16_t;

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


x86 assembly (clang, -O0):
<rgb565_bep>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%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    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
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    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
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    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb565_bep>:
mov    %edi,%ecx
and    $0xf8,%ecx
mov    %edi,%eax
sar    $0x5,%eax
mov    %eax,%edx
and    $0x7,%edx
or     %ecx,%edx
mov    %edx,(%rsi)
mov    %edi,%ecx
shl    $0x5,%ecx
movzbl %cl,%ecx
mov    %edi,%edx
shr    $0xb,%edx
and    $0x1c,%edx
or     %ecx,%edx
mov    %edi,%ecx
shr    %ecx
and    $0x3,%ecx
or     %edx,%ecx
mov    %ecx,0x4(%rsi)
and    $0xf8,%eax
shr    $0xa,%edi
and    $0x7,%edi
or     %eax,%edi
mov    %edi,0x8(%rsi)
ret

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

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