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

/* Variables and functions */
void rgb24to16_C(const uint8_t *src, uint8_t *dst, unsigned src_size) {
  const uint8_t *s = src;
  const uint8_t *end;
  uint16_t *d = (uint16_t *)dst;
  end = s + src_size;
  while (s < end) {
    const int b = *s++;
    const int g = *s++;
    const int r = *s++;
    *d++ = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
  }
}


x86 assembly (clang, -O0):
<rgb24to16_C>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11b1 <rgb24to16_C+0xb1>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%ecx
sar    $0x3,%ecx
mov    -0x38(%rbp),%eax
and    $0xfc,%eax
shl    $0x3,%eax
or     %eax,%ecx
mov    -0x3c(%rbp),%eax
and    $0xf8,%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x30(%rbp)
mov    %ecx,(%rax)
jmp    1131 <rgb24to16_C+0x31>
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb24to16_C>:
test   %edx,%edx
je     113f <rgb24to16_C+0x3f>
mov    %edx,%eax
lea    (%rdi,%rax,4),%r8
nopw   0x0(%rax,%rax,1)
mov    (%rdi),%ecx
mov    0x4(%rdi),%edx
mov    0x8(%rdi),%eax
sar    $0x3,%ecx
shl    $0x3,%edx
and    $0x7e0,%edx
or     %ecx,%edx
shl    $0x8,%eax
and    $0xf800,%eax
or     %edx,%eax
mov    %eax,(%rsi)
add    $0x4,%rsi
add    $0xc,%rdi
cmp    %r8,%rdi
jb     1110 <rgb24to16_C+0x10>
ret

LLVM IR (-O0):
define void @rgb24to16_C(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%13 = load i32*, i32** %4
store i32* %13, i32** %7
%14 = load i32*, i32** %5
store i32* %14, i32** %9
%15 = load i32*, i32** %7
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32* %18, i32** %8
br label %19
19: ; preds = %23, %3
%20 = load i32*, i32** %7
%21 = load i32*, i32** %8
%22 = icmp ult i32* %20, %21
br i1 %22, label %23, label %45
23: ; preds = %19
%24 = load i32*, i32** %7
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %7
%26 = load i32, i32* %24
store i32 %26, i32* %10
%27 = load i32*, i32** %7
%28 = getelementptr inbounds i32, i32* %27, i32 1
store i32* %28, i32** %7
%29 = load i32, i32* %27
store i32 %29, i32* %11
%30 = load i32*, i32** %7
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %7
%32 = load i32, i32* %30
store i32 %32, i32* %12
%33 = load i32, i32* %10
%34 = ashr i32 %33, 3
%35 = load i32, i32* %11
%36 = and i32 %35, 252
%37 = shl i32 %36, 3
%38 = or i32 %34, %37
%39 = load i32, i32* %12
%40 = and i32 %39, 248
%41 = shl i32 %40, 8
%42 = or i32 %38, %41
%43 = load i32*, i32** %9
%44 = getelementptr inbounds i32, i32* %43, i32 1
store i32* %44, i32** %9
store i32 %42, i32* %43
br label %19
45: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @rgb24to16_C(i32* %0, i32* nocapture writeonly %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = getelementptr inbounds i32, i32* %0, i64 %4
%6 = icmp eq i32 %2, 0
br i1 %6, label %25, label %7
7: ; preds = %3, %7
%8 = phi i32* [ %14, %7 ], [ %0, %3 ]
%9 = phi i32* [ %23, %7 ], [ %1, %3 ]
%10 = getelementptr inbounds i32, i32* %8, i64 1
%11 = load i32, i32* %8
%12 = getelementptr inbounds i32, i32* %8, i64 2
%13 = load i32, i32* %10
%14 = getelementptr inbounds i32, i32* %8, i64 3
%15 = load i32, i32* %12
%16 = ashr i32 %11, 3
%17 = shl i32 %13, 3
%18 = and i32 %17, 2016
%19 = or i32 %18, %16
%20 = shl i32 %15, 8
%21 = and i32 %20, 63488
%22 = or i32 %19, %21
%23 = getelementptr inbounds i32, i32* %9, i64 1
store i32 %22, i32* %9
%24 = icmp ult i32* %14, %5
br i1 %24, label %7, label %25
25: ; preds = %7, %3
ret void
}