#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 */

/* Variables and functions */
int clamp255(int);
int cram_vqenc_rgb2rgb555(int cr, int cg, int cb) {
  int mr, mg, mb, ia;
  mr = cr;
  mg = cg;
  mb = cb;
  mr = mr + 15;
  mg = mg + 15;
  mb = mb + 15;
  mr = clamp255(mr);
  mg = clamp255(mg);
  mb = clamp255(mb);
  ia = ((mb >> 3) << 10) | ((mg >> 3) << 5) | (mr >> 3);
  return (ia);
}


x86 assembly (clang, -O0):
<cram_vqenc_rgb2rgb555>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0xf,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xf,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0xf,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <clamp255@plt>
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <clamp255@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <clamp255@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x3,%eax
shl    $0xa,%eax
mov    -0x14(%rbp),%ecx
sar    $0x3,%ecx
shl    $0x5,%ecx
or     %ecx,%eax
mov    -0x10(%rbp),%ecx
sar    $0x3,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cram_vqenc_rgb2rgb555>:
push   %rbp
push   %r14
push   %rbx
add    $0xf,%edi
lea    0xf(%rsi),%ebx
lea    0xf(%rdx),%r14d
call   1030 <clamp255@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <clamp255@plt>
mov    %eax,%ebx
mov    %r14d,%edi
call   1030 <clamp255@plt>
and    $0xfffffff8,%eax
shl    $0x7,%eax
shl    $0x2,%ebx
and    $0xffffffe0,%ebx
sar    $0x3,%ebp
or     %ebx,%ebp
or     %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cram_vqenc_rgb2rgb555(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
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %4
store i32 %11, i32* %7
%12 = load i32, i32* %5
store i32 %12, i32* %8
%13 = load i32, i32* %6
store i32 %13, i32* %9
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 15
store i32 %15, i32* %7
%16 = load i32, i32* %8
%17 = add nsw i32 %16, 15
store i32 %17, i32* %8
%18 = load i32, i32* %9
%19 = add nsw i32 %18, 15
store i32 %19, i32* %9
%20 = load i32, i32* %7
%21 = call i32 @clamp255(i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %8
%23 = call i32 @clamp255(i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %9
%25 = call i32 @clamp255(i32 %24)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = ashr i32 %26, 3
%28 = shl i32 %27, 10
%29 = load i32, i32* %8
%30 = ashr i32 %29, 3
%31 = shl i32 %30, 5
%32 = or i32 %28, %31
%33 = load i32, i32* %7
%34 = ashr i32 %33, 3
%35 = or i32 %32, %34
store i32 %35, i32* %10
%36 = load i32, i32* %10
ret i32 %36
}

LLVM IR (-O2):
define i32 @cram_vqenc_rgb2rgb555(i32 %0, i32 %1, i32 %2) {
%4 = add nsw i32 %0, 15
%5 = add nsw i32 %1, 15
%6 = add nsw i32 %2, 15
%7 = tail call i32 @clamp255(i32 %4)
%8 = tail call i32 @clamp255(i32 %5)
%9 = tail call i32 @clamp255(i32 %6)
%10 = shl i32 %9, 7
%11 = and i32 %10, -1024
%12 = shl i32 %8, 2
%13 = and i32 %12, -32
%14 = ashr i32 %7, 3
%15 = or i32 %13, %14
%16 = or i32 %15, %11
ret i32 %16
}