#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();
char readKey() {
  char input;
  input = getch();
  if (input == '\033') {
    getch();
    switch (getch()) {
    case 'A':
      return 'U';
    case 'B':
      return 'D';
    case 'C':
      return 'R';
    case 'D':
      return 'L';
    }
  } else {
    if (input == '\n')
      return 'E';
    else if (input == ' ')
      return 'S';
    else if (input == 'q' || input == 'Q')
      return 'Q';
  }
  return '0';
}


x86 assembly (clang, -O0):
<readKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <getch@plt>
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x1b,%eax
jne    1193 <readKey+0x83>
xor    %eax,%eax
mov    %al,-0x11(%rbp)
call   1030 <getch@plt>
mov    -0x11(%rbp),%al
call   1030 <getch@plt>
movsbl %al,%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     118e <readKey+0x7e>
mov    -0x10(%rbp),%rax
lea    0xe9f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x55,-0x1(%rbp)
jmp    11f5 <readKey+0xe5>
movb   $0x44,-0x1(%rbp)
jmp    11f5 <readKey+0xe5>
movb   $0x52,-0x1(%rbp)
jmp    11f5 <readKey+0xe5>
movb   $0x4c,-0x1(%rbp)
jmp    11f5 <readKey+0xe5>
jmp    11f1 <readKey+0xe1>
movsbl -0x2(%rbp),%eax
cmp    $0xa,%eax
jne    11a9 <readKey+0x99>
movb   $0x45,-0x1(%rbp)
jmp    11f5 <readKey+0xe5>
movsbl -0x2(%rbp),%eax
cmp    $0x20,%eax
jne    11bf <readKey+0xaf>
movb   $0x53,-0x1(%rbp)
jmp    11f5 <readKey+0xe5>
movsbl -0x2(%rbp),%eax
cmp    $0x71,%eax
je     11d9 <readKey+0xc9>
movsbl -0x2(%rbp),%eax
cmp    $0x51,%eax
jne    11e2 <readKey+0xd2>
movb   $0x51,-0x1(%rbp)
jmp    11f5 <readKey+0xe5>
jmp    11e7 <readKey+0xd7>
jmp    11ec <readKey+0xdc>
jmp    11f1 <readKey+0xe1>
movb   $0x30,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readKey>:
push   %rax
xor    %eax,%eax
call   1030 <getch@plt>
cmp    $0xa,%al
je     114c <readKey+0x3c>
mov    %eax,%ecx
cmp    $0x20,%al
je     1150 <readKey+0x40>
cmp    $0x1b,%cl
jne    1154 <readKey+0x44>
xor    %eax,%eax
call   1030 <getch@plt>
xor    %eax,%eax
call   1030 <getch@plt>
movsbl %al,%ecx
add    $0xffffffbf,%ecx
cmp    $0x4,%ecx
jae    115e <readKey+0x4e>
shl    $0x3,%ecx
mov    $0x4c524455,%eax
shr    %cl,%eax
pop    %rcx
ret
mov    $0x45,%al
pop    %rcx
ret
mov    $0x53,%al
pop    %rcx
ret
and    $0xdf,%cl
mov    $0x51,%al
cmp    $0x51,%cl
je     114a <readKey+0x3a>
mov    $0x30,%al
pop    %rcx
ret

LLVM IR (-O0):
define signext i8 @readKey() {
%1 = alloca i8
%2 = alloca i8
%3 = call signext i8 (...) @getch()
store i8 %3, i8* %2
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = icmp eq i32 %5, 27
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = call signext i8 (...) @getch()
%9 = call signext i8 (...) @getch()
%10 = sext i8 %9 to i32
switch i32 %10, label %15 [
i32 65, label %11
i32 66, label %12
i32 67, label %13
i32 68, label %14
]
11: ; preds = %7
store i8 85, i8* %1
br label %39
12: ; preds = %7
store i8 68, i8* %1
br label %39
13: ; preds = %7
store i8 82, i8* %1
br label %39
14: ; preds = %7
store i8 76, i8* %1
br label %39
15: ; preds = %7
br label %38
16: ; preds = %0
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %21
20: ; preds = %16
store i8 69, i8* %1
br label %39
21: ; preds = %16
%22 = load i8, i8* %2
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 32
br i1 %24, label %25, label %26
25: ; preds = %21
store i8 83, i8* %1
br label %39
26: ; preds = %21
%27 = load i8, i8* %2
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 113
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i8, i8* %2
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 81
br i1 %33, label %34, label %35
34: ; preds = %30, %26
store i8 81, i8* %1
br label %39
35: ; preds = %30
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37, %15
store i8 48, i8* %1
br label %39
39: ; preds = %38, %34, %25, %20, %14, %13, %12, %11
%40 = load i8, i8* %1
ret i8 %40
}

LLVM IR (-O2):
define signext i8 @readKey() {
%1 = tail call signext i8 (...) @getch()
switch i8 %1, label %9 [
i8 27, label %2
i8 10, label %17
i8 32, label %8
]
2: ; preds = %0
%3 = tail call signext i8 (...) @getch()
%4 = tail call signext i8 (...) @getch()
%5 = sext i8 %4 to i32
%6 = add nsw i32 %5, -65
%7 = icmp ult i32 %6, 4
br i1 %7, label %13, label %12
8: ; preds = %0
br label %17
9: ; preds = %0
%10 = and i8 %1, -33
%11 = icmp eq i8 %10, 81
br i1 %11, label %17, label %12
12: ; preds = %2, %9
br label %17
13: ; preds = %2
%14 = shl nsw i32 %6, 3
%15 = lshr i32 1280459861, %14
%16 = trunc i32 %15 to i8
br label %17
17: ; preds = %13, %9, %0, %12, %8
%18 = phi i8 [ 48, %12 ], [ 83, %8 ], [ 69, %0 ], [ 81, %9 ], [ %16, %13 ]
ret i8 %18
}