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

/* Variables and functions */
int read(int /*<<< orphan*/, unsigned short *, int);
int /*<<< orphan*/ write(int, unsigned short *, int);
void from_565_raw(void) {
  unsigned short out;
  unsigned short in;
  while (read(0, &in, 2) == 2) {
    out = ((((in) >> 11) & 0x1f) * 255 / 31);
    write(1, &out, 1);
    out = ((((in) >> 5) & 0x3f) * 255 / 63);
    write(1, &out, 1);
    out = (((in)&0x1f) * 255 / 31);
    write(1, &out, 1);
  }
  return;
}


x86 assembly (clang, -O0):
<from_565_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
lea    -0x4(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
jne    11c7 <from_565_raw+0xa7>
movzwl -0x4(%rbp),%eax
sar    $0xb,%eax
and    $0x1f,%eax
imul   $0xff,%eax,%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
mov    %ax,-0x2(%rbp)
mov    $0x1,%edx
lea    -0x2(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
movzwl -0x4(%rbp),%eax
sar    $0x5,%eax
and    $0x3f,%eax
imul   $0xff,%eax,%eax
mov    $0x3f,%ecx
cltd
idiv   %ecx
mov    %ax,-0x2(%rbp)
mov    $0x1,%edx
lea    -0x2(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
movzwl -0x4(%rbp),%eax
and    $0x1f,%eax
imul   $0xff,%eax,%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
mov    %ax,-0x2(%rbp)
mov    $0x1,%edx
lea    -0x2(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    1128 <from_565_raw+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<from_565_raw>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe(%rsp),%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
jne    121f <from_565_raw+0xff>
lea    0xc(%rsp),%rbx
lea    0xe(%rsp),%r14
nopl   0x0(%rax)
movzwl 0xe(%rsp),%ebp
mov    %ebp,%eax
shr    $0xb,%eax
mov    %eax,%ecx
shl    $0x8,%ecx
sub    %eax,%ecx
movzwl %cx,%eax
imul   $0x843,%eax,%eax
shr    $0x10,%eax
sub    %eax,%ecx
movzwl %cx,%ecx
shr    %ecx
add    %eax,%ecx
shr    $0x4,%ecx
mov    %cx,0xc(%rsp)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebp,%eax
shr    $0x5,%eax
and    $0x3f,%eax
mov    %eax,%ecx
shl    $0x8,%ecx
sub    %eax,%ecx
movzwl %cx,%eax
imul   $0x411,%eax,%eax
shr    $0x10,%eax
sub    %eax,%ecx
movzwl %cx,%ecx
shr    %ecx
add    %eax,%ecx
shr    $0x5,%ecx
mov    %cx,0xc(%rsp)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
and    $0x1f,%ebp
mov    %ebp,%eax
shl    $0x8,%eax
sub    %ebp,%eax
movzwl %ax,%ecx
imul   $0x843,%ecx,%ecx
shr    $0x10,%ecx
sub    %ecx,%eax
movzwl %ax,%eax
shr    %eax
add    %ecx,%eax
shr    $0x4,%eax
mov    %ax,0xc(%rsp)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
je     1150 <from_565_raw+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @from_565_raw() {
%1 = alloca i16
%2 = alloca i16
br label %3
3: ; preds = %6, %0
%4 = call i32 @read(i32 0, i16* %2, i32 2)
%5 = icmp eq i32 %4, 2
br i1 %5, label %6, label %30
6: ; preds = %3
%7 = load i16, i16* %2
%8 = zext i16 %7 to i32
%9 = ashr i32 %8, 11
%10 = and i32 %9, 31
%11 = mul nsw i32 %10, 255
%12 = sdiv i32 %11, 31
%13 = trunc i32 %12 to i16
store i16 %13, i16* %1
%14 = call i32 @write(i32 1, i16* %1, i32 1)
%15 = load i16, i16* %2
%16 = zext i16 %15 to i32
%17 = ashr i32 %16, 5
%18 = and i32 %17, 63
%19 = mul nsw i32 %18, 255
%20 = sdiv i32 %19, 63
%21 = trunc i32 %20 to i16
store i16 %21, i16* %1
%22 = call i32 @write(i32 1, i16* %1, i32 1)
%23 = load i16, i16* %2
%24 = zext i16 %23 to i32
%25 = and i32 %24, 31
%26 = mul nsw i32 %25, 255
%27 = sdiv i32 %26, 31
%28 = trunc i32 %27 to i16
store i16 %28, i16* %1
%29 = call i32 @write(i32 1, i16* %1, i32 1)
br label %3
30: ; preds = %3
ret void
}

LLVM IR (-O2):
define void @from_565_raw() {
%1 = alloca i16
%2 = alloca i16
%3 = bitcast i16* %1 to i8*
%4 = bitcast i16* %2 to i8*
%5 = call i32 @read(i32 0, i16* %2, i32 2)
%6 = icmp eq i32 %5, 2
br i1 %6, label %7, label %24
7: ; preds = %0, %7
%8 = load i16, i16* %2
%9 = lshr i16 %8, 11
%10 = mul nuw nsw i16 %9, 255
%11 = udiv i16 %10, 31
store i16 %11, i16* %1
%12 = call i32 @write(i32 1, i16* %1, i32 1)
%13 = lshr i16 %8, 5
%14 = and i16 %13, 63
%15 = mul nuw nsw i16 %14, 255
%16 = udiv i16 %15, 63
store i16 %16, i16* %1
%17 = call i32 @write(i32 1, i16* %1, i32 1)
%18 = and i16 %8, 31
%19 = mul nuw nsw i16 %18, 255
%20 = udiv i16 %19, 31
store i16 %20, i16* %1
%21 = call i32 @write(i32 1, i16* %1, i32 1)
%22 = call i32 @read(i32 0, i16* %2, i32 2)
%23 = icmp eq i32 %22, 2
br i1 %23, label %7, label %24
24: ; preds = %7, %0
ret void
}