#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 /*<<< orphan*/ display_clear(int);
int /*<<< orphan*/ display_rectangle(int, int, int, int, int);
int keyboard_get_scancode();
int /*<<< orphan*/ uart_init();
int /*<<< orphan*/ uart_puts(char *);
void main(void) {
  uart_init();
  uart_puts("Hello, keyboard_display.");
  display_clear(0x0000);
  while (1) {
    switch (keyboard_get_scancode()) {
    case 0xf01d:
      uart_puts("Change color: WHITE");
      display_rectangle(100, 100, 100, 100, 0xffff);
      break;
    case 0xf01c:
      uart_puts("Change color: RED");
      display_rectangle(100, 100, 100, 100, 0xf800);
      break;
    case 0xf01b:
      uart_puts("Change color: GREEN");
      display_rectangle(100, 100, 100, 100, 0x07e0);
      break;
    case 0xf023:
      uart_puts("Change color: BLUE");
      display_rectangle(100, 100, 100, 100, 0x001f);
      break;
    default:
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <uart_init@plt>
lea    0xebe(%rip),%rdi
call   1070 <uart_puts@plt>
xor    %edi,%edi
call   1040 <display_clear@plt>
xor    %eax,%eax
call   1050 <keyboard_get_scancode@plt>
add    $0xffff0fe5,%eax
mov    %eax,%ecx
mov    %rcx,-0x8(%rbp)
sub    $0x8,%eax
ja     123d <main+0xed>
mov    -0x8(%rbp),%rax
lea    0xe68(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe95(%rip),%rdi
call   1070 <uart_puts@plt>
mov    $0x64,%ecx
mov    $0xffff,%r8d
mov    %ecx,%edi
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <display_rectangle@plt>
jmp    1242 <main+0xf2>
lea    0xe82(%rip),%rdi
call   1070 <uart_puts@plt>
mov    $0x64,%ecx
mov    $0xf800,%r8d
mov    %ecx,%edi
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <display_rectangle@plt>
jmp    1242 <main+0xf2>
lea    0xe6d(%rip),%rdi
call   1070 <uart_puts@plt>
mov    $0x64,%ecx
mov    $0x7e0,%r8d
mov    %ecx,%edi
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <display_rectangle@plt>
jmp    1242 <main+0xf2>
lea    0xe5a(%rip),%rdi
call   1070 <uart_puts@plt>
mov    $0x64,%ecx
mov    $0x1f,%r8d
mov    %ecx,%edi
mov    %ecx,%esi
mov    %ecx,%edx
call   1060 <display_rectangle@plt>
jmp    1242 <main+0xf2>
jmp    1242 <main+0xf2>
jmp    1172 <main+0x22>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <uart_init@plt>
lea    0xe9b(%rip),%rdi
call   1070 <uart_puts@plt>
xor    %edi,%edi
call   1040 <display_clear@plt>
mov    $0x107,%r14d
lea    0xeea(%rip),%rbp
lea    0xf07(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <keyboard_get_scancode@plt>
add    $0xffff0fe5,%eax
cmp    $0x8,%eax
ja     1190 <main+0x40>
bt     %eax,%r14d
jae    1190 <main+0x40>
cltq
movslq 0x0(%rbp,%rax,4),%rdi
add    %rbp,%rdi
mov    (%r15,%rax,4),%ebx
call   1070 <uart_puts@plt>
mov    $0x64,%edi
mov    $0x64,%esi
mov    $0x64,%edx
mov    $0x64,%ecx
mov    %ebx,%r8d
call   1060 <display_rectangle@plt>
jmp    1190 <main+0x40>

LLVM IR (-O0):
@.str = [25 x i8] c"Hello, keyboard_display.\00"
@.str.1 = [20 x i8] c"Change color: WHITE\00"
@.str.2 = [18 x i8] c"Change color: RED\00"
@.str.3 = [20 x i8] c"Change color: GREEN\00"
@.str.4 = [19 x i8] c"Change color: BLUE\00"
define void @main() {
%1 = call i32 (...) @uart_init()
%2 = call i32 @uart_puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @display_clear(i32 0)
br label %4
4: ; preds = %0, %19
%5 = call i32 (...) @keyboard_get_scancode()
switch i32 %5, label %18 [
i32 61469, label %6
i32 61468, label %9
i32 61467, label %12
i32 61475, label %15
]
6: ; preds = %4
%7 = call i32 @uart_puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @display_rectangle(i32 100, i32 100, i32 100, i32 100, i32 65535)
br label %19
9: ; preds = %4
%10 = call i32 @uart_puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @display_rectangle(i32 100, i32 100, i32 100, i32 100, i32 63488)
br label %19
12: ; preds = %4
%13 = call i32 @uart_puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @display_rectangle(i32 100, i32 100, i32 100, i32 100, i32 2016)
br label %19
15: ; preds = %4
%16 = call i32 @uart_puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @display_rectangle(i32 100, i32 100, i32 100, i32 100, i32 31)
br label %19
18: ; preds = %4
br label %19
19: ; preds = %18, %15, %12, %9, %6
br label %4
}

LLVM IR (-O2):
@.str = [25 x i8] c"Hello, keyboard_display.\00"
@.str.1 = [20 x i8] c"Change color: WHITE\00"
@.str.2 = [18 x i8] c"Change color: RED\00"
@.str.3 = [20 x i8] c"Change color: GREEN\00"
@.str.4 = [19 x i8] c"Change color: BLUE\00"
@reltable.main = [9 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.3 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.2 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.4 to i64), i64 ptrtoint ([9 x i32]* @reltable.main to i64)) to i32)]
@switch.table.main.5 = [9 x i32] [i32 2016, i32 63488, i32 65535, i32 65535, i32 65535, i32 65535, i32 65535, i32 65535, i32 31]
define void @main() {
%1 = tail call i32 (...) @uart_init()
%2 = tail call i32 @uart_puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @display_clear(i32 0)
br label %4
4: ; preds = %13, %0
%5 = tail call i32 (...) @keyboard_get_scancode()
%6 = add i32 %5, -61467
%7 = icmp ult i32 %6, 9
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = trunc i32 %6 to i16
%10 = lshr i16 263, %9
%11 = and i16 %10, 1
%12 = icmp eq i16 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8, %4, %14
br label %4
14: ; preds = %8
%15 = sext i32 %6 to i64
%16 = shl i64 %15, 2
%17 = call i8* @llvm.load.relative.i64(i8* bitcast ([9 x i32]* @reltable.main to i8*), i64 %16)
%18 = sext i32 %6 to i64
%19 = getelementptr inbounds [9 x i32], [9 x i32]* @switch.table.main.5, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = tail call i32 @uart_puts(i8* %17)
%22 = tail call i32 @display_rectangle(i32 100, i32 100, i32 100, i32 100, i32 %20)
br label %13
}