#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*/ VI_active(int);
unsigned char io_in8(int);
int /*<<< orphan*/ io_out8(int, int);
int /*<<< orphan*/ reset();
int /*<<< orphan*/ select_down();
int /*<<< orphan*/ select_press();
int /*<<< orphan*/ select_up();
void keyboard_handle(void) {
  unsigned char key_val;
  key_val = io_in8(0x60);
  if (key_val == 0x48)
    select_up();
  if (key_val == 0x50)
    select_down();
  if (key_val == 0x3B)
    VI_active(1);
  if (key_val == 0x3C)
    VI_active(2);
  if (key_val == 0x1C)
    select_press();
  if (key_val == 0x1)
    reset();
  io_out8(0x20, 0x20);
  io_out8(0xA0, 0x20);
}


x86 assembly (clang, -O0):
<keyboard_handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x60,%edi
call   1080 <io_in8@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x48,%eax
jne    1199 <keyboard_handle+0x29>
mov    $0x0,%al
call   1090 <select_up@plt>
movzbl -0x1(%rbp),%eax
cmp    $0x50,%eax
jne    11ad <keyboard_handle+0x3d>
mov    $0x0,%al
call   1060 <select_down@plt>
movzbl -0x1(%rbp),%eax
cmp    $0x3b,%eax
jne    11c4 <keyboard_handle+0x54>
mov    $0x1,%edi
call   1040 <VI_active@plt>
movzbl -0x1(%rbp),%eax
cmp    $0x3c,%eax
jne    11db <keyboard_handle+0x6b>
mov    $0x2,%edi
call   1040 <VI_active@plt>
movzbl -0x1(%rbp),%eax
cmp    $0x1c,%eax
jne    11ef <keyboard_handle+0x7f>
mov    $0x0,%al
call   1030 <select_press@plt>
movzbl -0x1(%rbp),%eax
cmp    $0x1,%eax
jne    1203 <keyboard_handle+0x93>
mov    $0x0,%al
call   1050 <reset@plt>
mov    $0x20,%esi
mov    %esi,%edi
call   1070 <io_out8@plt>
mov    $0xa0,%edi
mov    $0x20,%esi
call   1070 <io_out8@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keyboard_handle>:
push   %rax
mov    $0x60,%edi
call   1080 <io_in8@plt>
lea    -0x3b(%rax),%ecx
cmp    $0x15,%cl
ja     11a2 <keyboard_handle+0x32>
movzbl %cl,%eax
lea    0xe73(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x1,%edi
call   1040 <VI_active@plt>
jmp    11d8 <keyboard_handle+0x68>
cmp    $0x1,%al
je     11d1 <keyboard_handle+0x61>
cmp    $0x1c,%al
jne    11d8 <keyboard_handle+0x68>
xor    %eax,%eax
call   1030 <select_press@plt>
jmp    11d8 <keyboard_handle+0x68>
mov    $0x2,%edi
call   1040 <VI_active@plt>
jmp    11d8 <keyboard_handle+0x68>
xor    %eax,%eax
call   1090 <select_up@plt>
jmp    11d8 <keyboard_handle+0x68>
xor    %eax,%eax
call   1060 <select_down@plt>
jmp    11d8 <keyboard_handle+0x68>
xor    %eax,%eax
call   1050 <reset@plt>
mov    $0x20,%edi
mov    $0x20,%esi
call   1070 <io_out8@plt>
mov    $0xa0,%edi
mov    $0x20,%esi
pop    %rax
jmp    1070 <io_out8@plt>

LLVM IR (-O0):
define void @keyboard_handle() {
%1 = alloca i8
%2 = call zeroext i8 @io_in8(i32 96)
store i8 %2, i8* %1
%3 = load i8, i8* %1
%4 = zext i8 %3 to i32
%5 = icmp eq i32 %4, 72
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (...) @select_up()
br label %8
8: ; preds = %6, %0
%9 = load i8, i8* %1
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 80
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 (...) @select_down()
br label %14
14: ; preds = %12, %8
%15 = load i8, i8* %1
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 59
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @VI_active(i32 1)
br label %20
20: ; preds = %18, %14
%21 = load i8, i8* %1
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %22, 60
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @VI_active(i32 2)
br label %26
26: ; preds = %24, %20
%27 = load i8, i8* %1
%28 = zext i8 %27 to i32
%29 = icmp eq i32 %28, 28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (...) @select_press()
br label %32
32: ; preds = %30, %26
%33 = load i8, i8* %1
%34 = zext i8 %33 to i32
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 (...) @reset()
br label %38
38: ; preds = %36, %32
%39 = call i32 @io_out8(i32 32, i32 32)
%40 = call i32 @io_out8(i32 160, i32 32)
ret void
}

LLVM IR (-O2):
define void @keyboard_handle() {
%1 = tail call zeroext i8 @io_in8(i32 96)
switch i8 %1, label %14 [
i8 72, label %2
i8 80, label %4
i8 59, label %6
i8 60, label %8
i8 28, label %10
i8 1, label %12
]
2: ; preds = %0
%3 = tail call i32 (...) @select_up()
br label %14
4: ; preds = %0
%5 = tail call i32 (...) @select_down()
br label %14
6: ; preds = %0
%7 = tail call i32 @VI_active(i32 1)
br label %14
8: ; preds = %0
%9 = tail call i32 @VI_active(i32 2)
br label %14
10: ; preds = %0
%11 = tail call i32 (...) @select_press()
br label %14
12: ; preds = %0
%13 = tail call i32 (...) @reset()
br label %14
14: ; preds = %10, %8, %6, %4, %2, %0, %12
%15 = tail call i32 @io_out8(i32 32, i32 32)
%16 = tail call i32 @io_out8(i32 160, i32 32)
ret void
}