#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 EOF;
int getchar();
int /*<<< orphan*/ putchar(unsigned short);
int main() {
  int red, green, blue;
  unsigned short bgr565;
  while (1) {
    red = getchar();
    if (red == EOF)
      return (0);
    green = getchar();
    if (green == EOF)
      return (1);
    blue = getchar();
    if (blue == EOF)
      return (1);
    bgr565 = (unsigned short)(red * 31.0 / 255.0) |
             (unsigned short)(green * 63.0 / 255.0) << 5 |
             (unsigned short)(blue * 31.0 / 255.0) << 11;
    putchar((bgr565 >> 8) & 0xFF);
    putchar(bgr565 & 0xFF);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%eax
jne    1157 <main+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1233 <main+0x113>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%eax
jne    117f <main+0x5f>
movl   $0x1,-0x4(%rbp)
jmp    1233 <main+0x113>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%eax
jne    11a7 <main+0x87>
movl   $0x1,-0x4(%rbp)
jmp    1233 <main+0x113>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xe48(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
movzwl %ax,%eax
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe38(%rip),%xmm3
mulsd  %xmm3,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
movzwl %cx,%ecx
shl    $0x5,%ecx
or     %ecx,%eax
cvtsi2sdl -0x10(%rbp),%xmm0
mulsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
movzwl %cx,%ecx
shl    $0xb,%ecx
or     %ecx,%eax
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
movzwl %ax,%edi
call   1030 <putchar@plt>
movzwl -0x12(%rbp),%eax
and    $0xff,%eax
movzwl %ax,%edi
call   1030 <putchar@plt>
jmp    112f <main+0xf>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eb1(%rip),%r15
cmp    (%r15),%eax
je     11f0 <main+0xd0>
mov    %eax,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    $0x1,%ebp
cmp    (%r15),%eax
je     11f0 <main+0xd0>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r15),%eax
je     11f0 <main+0xd0>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  0xe7d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe79(%rip),%xmm2
divsd  %xmm2,%xmm0
cvttsd2si %xmm0,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xe6a(%rip),%xmm0
divsd  %xmm2,%xmm0
cvttsd2si %xmm0,%ebx
shl    $0x5,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
cvttsd2si %xmm0,%eax
or     %ecx,%ebx
shl    $0xb,%eax
or     %ebx,%eax
movzbl %ah,%edi
call   1030 <putchar@plt>
movzbl %bl,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%r14d
cmp    (%r15),%eax
jne    1150 <main+0x30>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i16
store i32 0, i32* %1
br label %6
6: ; preds = %0, %24
%7 = call i32 (...) @getchar()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %6
store i32 0, i32* %1
br label %59
12: ; preds = %6
%13 = call i32 (...) @getchar()
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 1, i32* %1
br label %59
18: ; preds = %12
%19 = call i32 (...) @getchar()
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %1
br label %59
24: ; preds = %18
%25 = load i32, i32* %2
%26 = sitofp i32 %25 to double
%27 = fmul double %26, 3.100000e+01
%28 = fdiv double %27, 2.550000e+02
%29 = fptoui double %28 to i16
%30 = zext i16 %29 to i32
%31 = load i32, i32* %3
%32 = sitofp i32 %31 to double
%33 = fmul double %32, 6.300000e+01
%34 = fdiv double %33, 2.550000e+02
%35 = fptoui double %34 to i16
%36 = zext i16 %35 to i32
%37 = shl i32 %36, 5
%38 = or i32 %30, %37
%39 = load i32, i32* %4
%40 = sitofp i32 %39 to double
%41 = fmul double %40, 3.100000e+01
%42 = fdiv double %41, 2.550000e+02
%43 = fptoui double %42 to i16
%44 = zext i16 %43 to i32
%45 = shl i32 %44, 11
%46 = or i32 %38, %45
%47 = trunc i32 %46 to i16
store i16 %47, i16* %5
%48 = load i16, i16* %5
%49 = zext i16 %48 to i32
%50 = ashr i32 %49, 8
%51 = and i32 %50, 255
%52 = trunc i32 %51 to i16
%53 = call i32 @putchar(i16 zeroext %52)
%54 = load i16, i16* %5
%55 = zext i16 %54 to i32
%56 = and i32 %55, 255
%57 = trunc i32 %56 to i16
%58 = call i32 @putchar(i16 zeroext %57)
br label %6
59: ; preds = %23, %17, %11
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %37, label %4
4: ; preds = %0, %13
%5 = phi i32 [ %34, %13 ], [ %1, %0 ]
%6 = tail call i32 (...) @getchar()
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %37, label %9
9: ; preds = %4
%10 = tail call i32 (...) @getchar()
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %37, label %13
13: ; preds = %9
%14 = sitofp i32 %5 to double
%15 = fmul double %14, 3.100000e+01
%16 = fdiv double %15, 2.550000e+02
%17 = fptoui double %16 to i16
%18 = sitofp i32 %6 to double
%19 = fmul double %18, 6.300000e+01
%20 = fdiv double %19, 2.550000e+02
%21 = fptoui double %20 to i16
%22 = shl i16 %21, 5
%23 = or i16 %22, %17
%24 = sitofp i32 %10 to double
%25 = fmul double %24, 3.100000e+01
%26 = fdiv double %25, 2.550000e+02
%27 = fptoui double %26 to i16
%28 = shl i16 %27, 11
%29 = or i16 %28, %23
%30 = lshr i16 %29, 8
%31 = tail call i32 @putchar(i16 zeroext %30)
%32 = and i16 %23, 255
%33 = tail call i32 @putchar(i16 zeroext %32)
%34 = tail call i32 (...) @getchar()
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %4
37: ; preds = %13, %4, %9, %0
%38 = phi i32 [ 0, %0 ], [ 1, %9 ], [ 1, %4 ], [ 0, %13 ]
ret i32 %38
}