#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 */
char getch();
int /*<<< orphan*/ keyb_in_buff(int, char);
void read_key() {
  char c = 0;
  c = getch();
  switch (c) {
  case 8:
    keyb_in_buff(2, 1);
    break;
  case 13:
    keyb_in_buff(2, 4);
    break;
  case 27:
    keyb_in_buff(2, 5);
    break;
  case -32:
    c = getch();
    switch (c) {
    case 83:
      keyb_in_buff(2, 6);
      break;
    case 72:
      keyb_in_buff(2, 7);
      break;
    case 80:
      keyb_in_buff(2, 8);
      break;
    case 75:
      keyb_in_buff(2, 9);
      break;
    case 77:
      keyb_in_buff(2, 10);
      break;
    case -123:
      keyb_in_buff(2, 21);
      break;
    case -122:
      keyb_in_buff(2, 22);
      break;
    default:
      break;
    }
    break;
  case 0:
    c = getch();
    switch (c) {
    case 59:
      keyb_in_buff(2, 11);
      break;
    case 60:
      keyb_in_buff(2, 12);
      break;
    case 61:
      keyb_in_buff(2, 13);
      break;
    case 62:
      keyb_in_buff(2, 14);
      break;
    case 63:
      keyb_in_buff(2, 15);
      break;
    case 64:
      keyb_in_buff(2, 16);
      break;
    case 65:
      keyb_in_buff(2, 17);
      break;
    case 66:
      keyb_in_buff(2, 18);
      break;
    case 67:
      keyb_in_buff(2, 19);
      break;
    case 68:
      keyb_in_buff(2, 20);
      break;
    }
    break;
  default:
    keyb_in_buff(1, c);
    break;
  }
}


x86 assembly (clang, -O0):
<read_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movb   $0x0,-0x1(%rbp)
xor    %eax,%eax
call   1030 <getch@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0xffffffe0,%eax
je     11ca <read_key+0xaa>
jmp    114b <read_key+0x2b>
mov    -0x8(%rbp),%eax
test   %eax,%eax
je     12e5 <read_key+0x1c5>
jmp    115b <read_key+0x3b>
mov    -0x8(%rbp),%eax
sub    $0x8,%eax
je     118e <read_key+0x6e>
jmp    116c <read_key+0x4c>
mov    -0x8(%rbp),%eax
sub    $0xd,%eax
je     11a2 <read_key+0x82>
jmp    117d <read_key+0x5d>
mov    -0x8(%rbp),%eax
sub    $0x1b,%eax
je     11b6 <read_key+0x96>
jmp    13e1 <read_key+0x2c1>
mov    $0x2,%edi
mov    $0x1,%esi
call   1040 <keyb_in_buff@plt>
jmp    13ef <read_key+0x2cf>
mov    $0x2,%edi
mov    $0x4,%esi
call   1040 <keyb_in_buff@plt>
jmp    13ef <read_key+0x2cf>
mov    $0x2,%edi
mov    $0x5,%esi
call   1040 <keyb_in_buff@plt>
jmp    13ef <read_key+0x2cf>
xor    %eax,%eax
call   1030 <getch@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0xffffff85,%eax
je     12b3 <read_key+0x193>
jmp    11e9 <read_key+0xc9>
mov    -0xc(%rbp),%eax
sub    $0xffffff86,%eax
je     12c7 <read_key+0x1a7>
jmp    11fa <read_key+0xda>
mov    -0xc(%rbp),%eax
sub    $0x48,%eax
je     1263 <read_key+0x143>
jmp    120b <read_key+0xeb>
mov    -0xc(%rbp),%eax
sub    $0x4b,%eax
je     128b <read_key+0x16b>
jmp    121c <read_key+0xfc>
mov    -0xc(%rbp),%eax
sub    $0x4d,%eax
je     129f <read_key+0x17f>
jmp    122d <read_key+0x10d>
mov    -0xc(%rbp),%eax
sub    $0x50,%eax
je     1277 <read_key+0x157>
jmp    123e <read_key+0x11e>
mov    -0xc(%rbp),%eax
sub    $0x53,%eax
jne    12db <read_key+0x1bb>
jmp    124f <read_key+0x12f>
mov    $0x2,%edi
mov    $0x6,%esi
call   1040 <keyb_in_buff@plt>
jmp    12e0 <read_key+0x1c0>
mov    $0x2,%edi
mov    $0x7,%esi
call   1040 <keyb_in_buff@plt>
jmp    12e0 <read_key+0x1c0>
mov    $0x2,%edi
mov    $0x8,%esi
call   1040 <keyb_in_buff@plt>
jmp    12e0 <read_key+0x1c0>
mov    $0x2,%edi
mov    $0x9,%esi
call   1040 <keyb_in_buff@plt>
jmp    12e0 <read_key+0x1c0>
mov    $0x2,%edi
mov    $0xa,%esi
call   1040 <keyb_in_buff@plt>
jmp    12e0 <read_key+0x1c0>
mov    $0x2,%edi
mov    $0x15,%esi
call   1040 <keyb_in_buff@plt>
jmp    12e0 <read_key+0x1c0>
mov    $0x2,%edi
mov    $0x16,%esi
call   1040 <keyb_in_buff@plt>
jmp    12e0 <read_key+0x1c0>
jmp    12e0 <read_key+0x1c0>
jmp    13ef <read_key+0x2cf>
xor    %eax,%eax
call   1030 <getch@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0xffffffc5,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x9,%eax
ja     13dc <read_key+0x2bc>
mov    -0x18(%rbp),%rax
lea    0xcf0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x2,%edi
mov    $0xb,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0xc,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0xd,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0xe,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0xf,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0x10,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0x11,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0x12,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0x13,%esi
call   1040 <keyb_in_buff@plt>
jmp    13dc <read_key+0x2bc>
mov    $0x2,%edi
mov    $0x14,%esi
call   1040 <keyb_in_buff@plt>
jmp    13ef <read_key+0x2cf>
mov    $0x1,%edi
movsbl -0x1(%rbp),%esi
call   1040 <keyb_in_buff@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_key>:
push   %rax
xor    %eax,%eax
call   1030 <getch@plt>
movsbl %al,%esi
cmp    $0x1b,%esi
ja     1176 <read_key+0x56>
lea    0xec9(%rip),%rax
movslq (%rax,%rsi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %eax,%eax
call   1030 <getch@plt>
movsbl %al,%eax
add    $0xffffffc5,%eax
cmp    $0x9,%eax
ja     1206 <read_key+0xe6>
lea    0xf13(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x2,%edi
mov    $0xb,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
cmp    $0xffffffe0,%esi
jne    11ad <read_key+0x8d>
xor    %eax,%eax
call   1030 <getch@plt>
movsbl %al,%eax
lea    -0x48(%rax),%ecx
cmp    $0xb,%ecx
ja     11e8 <read_key+0xc8>
lea    0xf04(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0x2,%edi
mov    $0x7,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x1,%edi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x1,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x4,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x5,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
cmp    $0xffffff85,%eax
je     12d8 <read_key+0x1b8>
cmp    $0xffffff86,%eax
jne    1206 <read_key+0xe6>
mov    $0x2,%edi
mov    $0x16,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
pop    %rax
ret
mov    $0x2,%edi
mov    $0xc,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0xd,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0xe,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0xf,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x10,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x11,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x12,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x13,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x14,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x9,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0xa,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x8,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x6,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>
mov    $0x2,%edi
mov    $0x15,%esi
pop    %rax
jmp    1040 <keyb_in_buff@plt>

LLVM IR (-O0):
define void @read_key() {
%1 = alloca i8
store i8 0, i8* %1
%2 = call signext i8 (...) @getch()
store i8 %2, i8* %1
%3 = load i8, i8* %1
%4 = sext i8 %3 to i32
switch i32 %4, label %56 [
i32 8, label %5
i32 13, label %7
i32 27, label %9
i32 -32, label %11
i32 0, label %31
]
5: ; preds = %0
%6 = call i32 @keyb_in_buff(i32 2, i8 signext 1)
br label %59
7: ; preds = %0
%8 = call i32 @keyb_in_buff(i32 2, i8 signext 4)
br label %59
9: ; preds = %0
%10 = call i32 @keyb_in_buff(i32 2, i8 signext 5)
br label %59
11: ; preds = %0
%12 = call signext i8 (...) @getch()
store i8 %12, i8* %1
%13 = load i8, i8* %1
%14 = sext i8 %13 to i32
switch i32 %14, label %29 [
i32 83, label %15
i32 72, label %17
i32 80, label %19
i32 75, label %21
i32 77, label %23
i32 -123, label %25
i32 -122, label %27
]
15: ; preds = %11
%16 = call i32 @keyb_in_buff(i32 2, i8 signext 6)
br label %30
17: ; preds = %11
%18 = call i32 @keyb_in_buff(i32 2, i8 signext 7)
br label %30
19: ; preds = %11
%20 = call i32 @keyb_in_buff(i32 2, i8 signext 8)
br label %30
21: ; preds = %11
%22 = call i32 @keyb_in_buff(i32 2, i8 signext 9)
br label %30
23: ; preds = %11
%24 = call i32 @keyb_in_buff(i32 2, i8 signext 10)
br label %30
25: ; preds = %11
%26 = call i32 @keyb_in_buff(i32 2, i8 signext 21)
br label %30
27: ; preds = %11
%28 = call i32 @keyb_in_buff(i32 2, i8 signext 22)
br label %30
29: ; preds = %11
br label %30
30: ; preds = %29, %27, %25, %23, %21, %19, %17, %15
br label %59
31: ; preds = %0
%32 = call signext i8 (...) @getch()
store i8 %32, i8* %1
%33 = load i8, i8* %1
%34 = sext i8 %33 to i32
switch i32 %34, label %55 [
i32 59, label %35
i32 60, label %37
i32 61, label %39
i32 62, label %41
i32 63, label %43
i32 64, label %45
i32 65, label %47
i32 66, label %49
i32 67, label %51
i32 68, label %53
]
35: ; preds = %31
%36 = call i32 @keyb_in_buff(i32 2, i8 signext 11)
br label %55
37: ; preds = %31
%38 = call i32 @keyb_in_buff(i32 2, i8 signext 12)
br label %55
39: ; preds = %31
%40 = call i32 @keyb_in_buff(i32 2, i8 signext 13)
br label %55
41: ; preds = %31
%42 = call i32 @keyb_in_buff(i32 2, i8 signext 14)
br label %55
43: ; preds = %31
%44 = call i32 @keyb_in_buff(i32 2, i8 signext 15)
br label %55
45: ; preds = %31
%46 = call i32 @keyb_in_buff(i32 2, i8 signext 16)
br label %55
47: ; preds = %31
%48 = call i32 @keyb_in_buff(i32 2, i8 signext 17)
br label %55
49: ; preds = %31
%50 = call i32 @keyb_in_buff(i32 2, i8 signext 18)
br label %55
51: ; preds = %31
%52 = call i32 @keyb_in_buff(i32 2, i8 signext 19)
br label %55
53: ; preds = %31
%54 = call i32 @keyb_in_buff(i32 2, i8 signext 20)
br label %55
55: ; preds = %31, %53, %51, %49, %47, %45, %43, %41, %39, %37, %35
br label %59
56: ; preds = %0
%57 = load i8, i8* %1
%58 = call i32 @keyb_in_buff(i32 1, i8 signext %57)
br label %59
59: ; preds = %56, %55, %30, %9, %7, %5
ret void
}

LLVM IR (-O2):
define void @read_key() {
%1 = tail call signext i8 (...) @getch()
%2 = sext i8 %1 to i32
switch i32 %2, label %49 [
i32 8, label %3
i32 13, label %5
i32 27, label %7
i32 -32, label %9
i32 0, label %26
]
3: ; preds = %0
%4 = tail call i32 @keyb_in_buff(i32 2, i8 signext 1)
br label %51
5: ; preds = %0
%6 = tail call i32 @keyb_in_buff(i32 2, i8 signext 4)
br label %51
7: ; preds = %0
%8 = tail call i32 @keyb_in_buff(i32 2, i8 signext 5)
br label %51
9: ; preds = %0
%10 = tail call signext i8 (...) @getch()
%11 = sext i8 %10 to i32
switch i32 %11, label %51 [
i32 83, label %12
i32 72, label %14
i32 80, label %16
i32 75, label %18
i32 77, label %20
i32 -123, label %22
i32 -122, label %24
]
12: ; preds = %9
%13 = tail call i32 @keyb_in_buff(i32 2, i8 signext 6)
br label %51
14: ; preds = %9
%15 = tail call i32 @keyb_in_buff(i32 2, i8 signext 7)
br label %51
16: ; preds = %9
%17 = tail call i32 @keyb_in_buff(i32 2, i8 signext 8)
br label %51
18: ; preds = %9
%19 = tail call i32 @keyb_in_buff(i32 2, i8 signext 9)
br label %51
20: ; preds = %9
%21 = tail call i32 @keyb_in_buff(i32 2, i8 signext 10)
br label %51
22: ; preds = %9
%23 = tail call i32 @keyb_in_buff(i32 2, i8 signext 21)
br label %51
24: ; preds = %9
%25 = tail call i32 @keyb_in_buff(i32 2, i8 signext 22)
br label %51
26: ; preds = %0
%27 = tail call signext i8 (...) @getch()
%28 = sext i8 %27 to i32
switch i32 %28, label %51 [
i32 59, label %29
i32 60, label %31
i32 61, label %33
i32 62, label %35
i32 63, label %37
i32 64, label %39
i32 65, label %41
i32 66, label %43
i32 67, label %45
i32 68, label %47
]
29: ; preds = %26
%30 = tail call i32 @keyb_in_buff(i32 2, i8 signext 11)
br label %51
31: ; preds = %26
%32 = tail call i32 @keyb_in_buff(i32 2, i8 signext 12)
br label %51
33: ; preds = %26
%34 = tail call i32 @keyb_in_buff(i32 2, i8 signext 13)
br label %51
35: ; preds = %26
%36 = tail call i32 @keyb_in_buff(i32 2, i8 signext 14)
br label %51
37: ; preds = %26
%38 = tail call i32 @keyb_in_buff(i32 2, i8 signext 15)
br label %51
39: ; preds = %26
%40 = tail call i32 @keyb_in_buff(i32 2, i8 signext 16)
br label %51
41: ; preds = %26
%42 = tail call i32 @keyb_in_buff(i32 2, i8 signext 17)
br label %51
43: ; preds = %26
%44 = tail call i32 @keyb_in_buff(i32 2, i8 signext 18)
br label %51
45: ; preds = %26
%46 = tail call i32 @keyb_in_buff(i32 2, i8 signext 19)
br label %51
47: ; preds = %26
%48 = tail call i32 @keyb_in_buff(i32 2, i8 signext 20)
br label %51
49: ; preds = %0
%50 = tail call i32 @keyb_in_buff(i32 1, i8 signext %1)
br label %51
51: ; preds = %29, %31, %33, %35, %37, %39, %41, %43, %45, %47, %26, %12, %14, %16, %18, %20, %22, %24, %9, %49, %7, %5, %3
ret void
}