#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 */
int getch_();
int /*<<< orphan*/ puts(char *);
void isarrow(void) {
  int key = getch_();
  if (key == 10) {
    puts("You pressed ENTER! \n");
  }
  if (key == 27) {
    key = getch_();
    if (key == 91)
      key = getch_();
    if (key == 65) {
      puts("You pressed up arrow! \n");
    } else if (key == 66) {
      puts("You pressed down arrow! \n");
    } else if (key == 67) {
      puts("You pressed right arrow! \n");
    } else if (key == 68) {
      puts("You pressed left arrow! \n");
    }
  }
}


x86 assembly (clang, -O0):
<isarrow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <getch_@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jne    1148 <isarrow+0x28>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x1b,-0x4(%rbp)
jne    11eb <isarrow+0xcb>
mov    $0x0,%al
call   1040 <getch_@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x5b,-0x4(%rbp)
jne    1170 <isarrow+0x50>
mov    $0x0,%al
call   1040 <getch_@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x41,-0x4(%rbp)
jne    118b <isarrow+0x6b>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
jmp    11e6 <isarrow+0xc6>
cmpl   $0x42,-0x4(%rbp)
jne    11a6 <isarrow+0x86>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
jmp    11e1 <isarrow+0xc1>
cmpl   $0x43,-0x4(%rbp)
jne    11c1 <isarrow+0xa1>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
jmp    11dc <isarrow+0xbc>
cmpl   $0x44,-0x4(%rbp)
jne    11d7 <isarrow+0xb7>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
jmp    11dc <isarrow+0xbc>
jmp    11e1 <isarrow+0xc1>
jmp    11e6 <isarrow+0xc6>
jmp    11eb <isarrow+0xcb>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isarrow>:
push   %rax
xor    %eax,%eax
call   1040 <getch_@plt>
cmp    $0xa,%eax
je     1165 <isarrow+0x45>
cmp    $0x1b,%eax
jne    1163 <isarrow+0x43>
xor    %eax,%eax
call   1040 <getch_@plt>
cmp    $0x5b,%eax
jne    1145 <isarrow+0x25>
xor    %eax,%eax
call   1040 <getch_@plt>
add    $0xffffffbf,%eax
cmp    $0x3,%eax
ja     1163 <isarrow+0x43>
cltq
lea    0xf26(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
pop    %rax
jmp    1030 <puts@plt>
pop    %rax
ret
lea    0xe94(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"You pressed ENTER! \0A\00"
@.str.1 = [24 x i8] c"You pressed up arrow! \0A\00"
@.str.2 = [26 x i8] c"You pressed down arrow! \0A\00"
@.str.3 = [27 x i8] c"You pressed right arrow! \0A\00"
@.str.4 = [26 x i8] c"You pressed left arrow! \0A\00"
define void @isarrow() {
%1 = alloca i32
%2 = call i32 (...) @getch_()
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = icmp eq i32 %3, 10
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 27
br i1 %9, label %10, label %40
10: ; preds = %7
%11 = call i32 (...) @getch_()
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 91
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (...) @getch_()
store i32 %15, i32* %1
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 65
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %39
21: ; preds = %16
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 66
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %38
26: ; preds = %21
%27 = load i32, i32* %1
%28 = icmp eq i32 %27, 67
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %37
31: ; preds = %26
%32 = load i32, i32* %1
%33 = icmp eq i32 %32, 68
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
br label %37
37: ; preds = %36, %29
br label %38
38: ; preds = %37, %24
br label %39
39: ; preds = %38, %19
br label %40
40: ; preds = %39, %7
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"You pressed ENTER! \0A\00"
@.str.1 = [24 x i8] c"You pressed up arrow! \0A\00"
@.str.2 = [26 x i8] c"You pressed down arrow! \0A\00"
@.str.3 = [27 x i8] c"You pressed right arrow! \0A\00"
@.str.4 = [26 x i8] c"You pressed left arrow! \0A\00"
@reltable.isarrow = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([24 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.isarrow to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.isarrow to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.isarrow to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.isarrow to i64)) to i32)]
define void @isarrow() {
%1 = tail call i32 (...) @getch_()
switch i32 %1, label %18 [
i32 10, label %15
i32 27, label %2
]
2: ; preds = %0
%3 = tail call i32 (...) @getch_()
%4 = icmp eq i32 %3, 91
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (...) @getch_()
br label %7
7: ; preds = %5, %2
%8 = phi i32 [ %6, %5 ], [ %3, %2 ]
%9 = add i32 %8, -65
%10 = icmp ult i32 %9, 4
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = sext i32 %9 to i64
%13 = shl i64 %12, 2
%14 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.isarrow to i8*), i64 %13)
br label %15
15: ; preds = %11, %0
%16 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %0 ], [ %14, %11 ]
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
br label %18
18: ; preds = %7, %15, %0
ret void
}