#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 getchar();
int /*<<< orphan*/ printf(char *);
int main(void) {
  if (getchar() == '\033') {
    getchar();
    switch (getchar()) {
    case 'A':
      printf("up arrow\n");
      break;
    case 'B':
      printf("down arrow\n");
      break;
    case 'C':
      printf("right arrow\n");
      break;
    case 'D':
      printf("left arrow\n");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0x1b,%eax
jne    11c1 <main+0xa1>
xor    %eax,%eax
mov    %al,-0x11(%rbp)
call   1040 <getchar@plt>
mov    -0x11(%rbp),%al
call   1040 <getchar@plt>
movsbl %al,%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11bc <main+0x9c>
mov    -0x10(%rbp),%rax
lea    0xe8c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <main+0x9c>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <main+0x9c>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <main+0x9c>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
jmp    11c1 <main+0xa1>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x1b,%al
jne    115a <main+0x3a>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
movsbl %al,%eax
add    $0xffffffbf,%eax
cmp    $0x3,%eax
ja     115a <main+0x3a>
cltq
lea    0xede(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"up arrow\0A\00"
@.str.1 = [12 x i8] c"down arrow\0A\00"
@.str.2 = [13 x i8] c"right arrow\0A\00"
@.str.3 = [12 x i8] c"left arrow\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call signext i8 (...) @getchar()
%3 = sext i8 %2 to i32
%4 = icmp eq i32 %3, 27
br i1 %4, label %5, label %18
5: ; preds = %0
%6 = call signext i8 (...) @getchar()
%7 = call signext i8 (...) @getchar()
%8 = sext i8 %7 to i32
switch i32 %8, label %17 [
i32 65, label %9
i32 66, label %11
i32 67, label %13
i32 68, label %15
]
9: ; preds = %5
%10 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %17
11: ; preds = %5
%12 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %17
13: ; preds = %5
%14 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %17
15: ; preds = %5
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %5, %15, %13, %11, %9
br label %18
18: ; preds = %17, %0
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@str = [11 x i8] c"left arrow\00"
@str.4 = [12 x i8] c"right arrow\00"
@str.5 = [11 x i8] c"down arrow\00"
@str.6 = [9 x i8] c"up arrow\00"
@reltable.main = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = tail call signext i8 (...) @getchar()
%2 = icmp eq i8 %1, 27
br i1 %2, label %3, label %14
3: ; preds = %0
%4 = tail call signext i8 (...) @getchar()
%5 = tail call signext i8 (...) @getchar()
%6 = sext i8 %5 to i32
%7 = add nsw i32 %6, -65
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = sext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.main to i8*), i64 %11)
%13 = tail call i32 @puts(i8* dereferenceable(1) %12)
br label %14
14: ; preds = %3, %9, %0
ret i32 0
}