#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 read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ write(int, unsigned short *, int);
void to_565_raw(void) {
  unsigned char in[3];
  unsigned short out;
  while (read(0, in, 3) == 3) {
    out = ((((in[0]) >> 3) << 11) | (((in[1]) >> 2) << 5) | ((in[2]) >> 3));
    write(1, &out, 2);
  }
  return;
}


x86 assembly (clang, -O0):
<to_565_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x3(%rbp),%rsi
xor    %edi,%edi
mov    $0x3,%edx
call   1040 <read@plt>
cmp    $0x3,%eax
jne    117c <to_565_raw+0x5c>
movzbl -0x3(%rbp),%eax
sar    $0x3,%eax
shl    $0xb,%eax
movzbl -0x2(%rbp),%ecx
sar    $0x2,%ecx
shl    $0x5,%ecx
or     %ecx,%eax
movzbl -0x1(%rbp),%ecx
sar    $0x3,%ecx
or     %ecx,%eax
mov    %ax,-0x6(%rbp)
mov    $0x1,%edi
lea    -0x6(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
jmp    1128 <to_565_raw+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_565_raw>:
push   %r14
push   %rbx
push   %rax
lea    0x3(%rsp),%rsi
xor    %edi,%edi
mov    $0x3,%edx
call   1040 <read@plt>
cmp    $0x3,%eax
jne    119e <to_565_raw+0x7e>
lea    0x6(%rsp),%r14
lea    0x3(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x3(%rsp),%eax
and    $0xfffffff8,%eax
shl    $0x8,%eax
movzbl 0x4(%rsp),%ecx
and    $0xfc,%ecx
lea    (%rax,%rcx,8),%eax
movzbl 0x5(%rsp),%ecx
shr    $0x3,%ecx
or     %eax,%ecx
mov    %cx,0x6(%rsp)
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1040 <read@plt>
cmp    $0x3,%eax
je     1150 <to_565_raw+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @to_565_raw() {
%1 = alloca [3 x i8]
%2 = alloca i16
br label %3
3: ; preds = %7, %0
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 3)
%6 = icmp eq i32 %5, 3
br i1 %6, label %7, label %26
7: ; preds = %3
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = ashr i32 %10, 3
%12 = shl i32 %11, 11
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = ashr i32 %15, 2
%17 = shl i32 %16, 5
%18 = or i32 %12, %17
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = ashr i32 %21, 3
%23 = or i32 %18, %22
%24 = trunc i32 %23 to i16
store i16 %24, i16* %2
%25 = call i32 @write(i32 1, i16* %2, i32 2)
br label %3
26: ; preds = %3
ret void
}

LLVM IR (-O2):
define void @to_565_raw() {
%1 = alloca [3 x i8]
%2 = alloca i16
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%4 = bitcast i16* %2 to i8*
%5 = call i32 @read(i32 0, i8* %3, i32 3)
%6 = icmp eq i32 %5, 3
br i1 %6, label %7, label %27
7: ; preds = %0
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
br label %10
10: ; preds = %7, %10
%11 = load i8, i8* %3
%12 = lshr i8 %11, 3
%13 = zext i8 %12 to i16
%14 = shl nuw i16 %13, 11
%15 = load i8, i8* %8
%16 = lshr i8 %15, 2
%17 = zext i8 %16 to i16
%18 = shl nuw nsw i16 %17, 5
%19 = or i16 %18, %14
%20 = load i8, i8* %9
%21 = lshr i8 %20, 3
%22 = zext i8 %21 to i16
%23 = or i16 %19, %22
store i16 %23, i16* %2
%24 = call i32 @write(i32 1, i16* %2, i32 2)
%25 = call i32 @read(i32 0, i8* %3, i32 3)
%26 = icmp eq i32 %25, 3
br i1 %26, label %10, label %27
27: ; preds = %10, %0
ret void
}