#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() {
  char ch;
  do {
    ch = getchar();
    if (ch == 65)
      printf("You pressed UP key\n");
    else if (ch == 66)
      printf("You pressed DOWN key\n");
    else if (ch == 67)
      printf("You pressed RIGHT key\n");
    else if (ch == 68)
      printf("You pressed LEFT key\n");
  } while (ch != 'e');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jne    1157 <main+0x37>
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
jmp    11bb <main+0x9b>
movsbl -0x5(%rbp),%eax
cmp    $0x42,%eax
jne    1175 <main+0x55>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
jmp    11b6 <main+0x96>
movsbl -0x5(%rbp),%eax
cmp    $0x43,%eax
jne    1193 <main+0x73>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <main+0x91>
movsbl -0x5(%rbp),%eax
cmp    $0x44,%eax
jne    11ac <main+0x8c>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <main+0x91>
jmp    11b6 <main+0x96>
jmp    11bb <main+0x9b>
jmp    11c0 <main+0xa0>
movsbl -0x5(%rbp),%eax
cmp    $0x65,%eax
jne    112f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xfa4(%rip),%r14
lea    0xec9(%rip),%rbx
lea    0xf81(%rip),%r15
lea    0xf64(%rip),%r12
lea    0xf48(%rip),%r13
jmp    1156 <main+0x36>
mov    %r13,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0xbf,%al
cmp    $0x24,%al
ja     1156 <main+0x36>
movzbl %al,%eax
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
mov    %r14,%rdi
jmp    *%rax
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    1156 <main+0x36>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1156 <main+0x36>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"You pressed UP key\0A\00"
@.str.1 = [22 x i8] c"You pressed DOWN key\0A\00"
@.str.2 = [23 x i8] c"You pressed RIGHT key\0A\00"
@.str.3 = [22 x i8] c"You pressed LEFT key\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
br label %3
3: ; preds = %32, %0
%4 = call signext i8 (...) @getchar()
store i8 %4, i8* %2
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp eq i32 %6, 65
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %31
10: ; preds = %3
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 66
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %30
16: ; preds = %10
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 67
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %29
22: ; preds = %16
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 68
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
br label %29
29: ; preds = %28, %20
br label %30
30: ; preds = %29, %14
br label %31
31: ; preds = %30, %8
br label %32
32: ; preds = %31
%33 = load i8, i8* %2
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 101
br i1 %35, label %3, label %36
36: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
@str = [21 x i8] c"You pressed LEFT key\00"
@str.4 = [22 x i8] c"You pressed RIGHT key\00"
@str.5 = [21 x i8] c"You pressed DOWN key\00"
@str.6 = [19 x i8] c"You pressed UP key\00"
define i32 @main() {
br label %1
1: ; preds = %6, %0
%2 = tail call signext i8 (...) @getchar()
switch i8 %2, label %6 [
i8 65, label %3
i8 66, label %7
i8 67, label %8
i8 68, label %9
i8 101, label %10
]
3: ; preds = %1, %8, %9, %7
%4 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0), %7 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0), %8 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0), %1 ]
%5 = tail call i32 @puts(i8* dereferenceable(1) %4)
br label %6
6: ; preds = %3, %1
br label %1
7: ; preds = %1
br label %3
8: ; preds = %1
br label %3
9: ; preds = %1
br label %3
10: ; preds = %1
ret i32 0
}