#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*/ printf(char *);
int main() {
  char ch;
  do {
    ch = _getch();
    switch (ch) {
    case -32:
      ch = _getch();
      switch (ch) {
      case 75:
        printf("Left\n");
        break;
      case 77:
        printf("Right\n");
        break;
      case 72:
        printf("Up\n");
        break;
      case 80:
        printf("Down\n");
        break;
      }
      break;
    case 13:
      printf("Enter\n");
      break;
    }
  } while (ch != 27);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1040 <_getch@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0xffffffe0,%eax
je     115f <main+0x3f>
jmp    114e <main+0x2e>
mov    -0xc(%rbp),%eax
sub    $0xd,%eax
je     11d7 <main+0xb7>
jmp    11e3 <main+0xc3>
xor    %eax,%eax
call   1040 <_getch@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
add    $0xffffffb8,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x8,%eax
ja     11d2 <main+0xb2>
mov    -0x18(%rbp),%rax
lea    0xe76(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <main+0xb2>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <main+0xb2>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <main+0xb2>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
jmp    11e3 <main+0xc3>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
jmp    11e8 <main+0xc8>
movsbl -0x5(%rbp),%eax
cmp    $0x1b,%eax
jne    112f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xef2(%rip),%r14
lea    0xeff(%rip),%r15
lea    0xec0(%rip),%r12
lea    0xeeb(%rip),%rbp
lea    0xedc(%rip),%r13
jmp    115d <main+0x3d>
mov    %r14,%rdi
call   1030 <puts@plt>
cmp    $0x1b,%bl
je     11a6 <main+0x86>
xor    %eax,%eax
call   1040 <_getch@plt>
mov    %eax,%ebx
movsbl %al,%eax
cmp    $0xd,%eax
je     1150 <main+0x30>
cmp    $0xffffffe0,%eax
jne    1158 <main+0x38>
xor    %eax,%eax
call   1040 <_getch@plt>
mov    %eax,%ebx
movsbl %al,%eax
add    $0xffffffb8,%eax
cmp    $0x8,%eax
ja     1158 <main+0x38>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
mov    %r15,%rdi
jmp    *%rax
lea    0xe95(%rip),%rdi
jmp    1153 <main+0x33>
mov    %rbp,%rdi
jmp    1153 <main+0x33>
mov    %r13,%rdi
jmp    1153 <main+0x33>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Left\0A\00"
@.str.1 = [7 x i8] c"Right\0A\00"
@.str.2 = [4 x i8] c"Up\0A\00"
@.str.3 = [6 x i8] c"Down\0A\00"
@.str.4 = [7 x i8] c"Enter\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
br label %3
3: ; preds = %23, %0
%4 = call signext i8 (...) @_getch()
store i8 %4, i8* %2
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
switch i32 %6, label %22 [
i32 -32, label %7
i32 13, label %20
]
7: ; preds = %3
%8 = call signext i8 (...) @_getch()
store i8 %8, i8* %2
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
switch i32 %10, label %19 [
i32 75, label %11
i32 77, label %13
i32 72, label %15
i32 80, label %17
]
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %19
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %19
15: ; preds = %7
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %7
%18 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %7, %17, %15, %13, %11
br label %22
20: ; preds = %3
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %3, %20, %19
br label %23
23: ; preds = %22
%24 = load i8, i8* %2
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 27
br i1 %26, label %3, label %27
27: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@str = [6 x i8] c"Enter\00"
@str.5 = [5 x i8] c"Down\00"
@str.6 = [3 x i8] c"Up\00"
@str.7 = [6 x i8] c"Right\00"
@str.8 = [5 x i8] c"Left\00"
define i32 @main() {
br label %1
1: ; preds = %14, %0
%2 = tail call signext i8 (...) @_getch()
%3 = sext i8 %2 to i32
switch i32 %3, label %14 [
i32 -32, label %4
i32 13, label %10
]
4: ; preds = %1
%5 = tail call signext i8 (...) @_getch()
%6 = sext i8 %5 to i32
switch i32 %6, label %14 [
i32 75, label %10
i32 77, label %7
i32 72, label %8
i32 80, label %9
]
7: ; preds = %4
br label %10
8: ; preds = %4
br label %10
9: ; preds = %4
br label %10
10: ; preds = %1, %4, %7, %8, %9
%11 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0), %8 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.7, i64 0, i64 0), %7 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.8, i64 0, i64 0), %4 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), %1 ]
%12 = phi i8 [ %5, %9 ], [ %5, %8 ], [ %5, %7 ], [ %5, %4 ], [ %2, %1 ]
%13 = tail call i32 @puts(i8* dereferenceable(1) %11)
br label %14
14: ; preds = %10, %1, %4
%15 = phi i8 [ %2, %1 ], [ %5, %4 ], [ %12, %10 ]
%16 = icmp eq i8 %15, 27
br i1 %16, label %17, label %1
17: ; preds = %14
ret i32 0
}