#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 */
#define KEY_DOWN 132
#define KEY_ENTER 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int getch();
int io_getkey() {
  int c;
  switch (c = getch()) {
  case KEY_LEFT:
    return 0;
    break;
  case KEY_RIGHT:
    return 1;
    break;
  case KEY_UP:
    return 2;
    break;
  case KEY_DOWN:
    return 3;
    break;
  case KEY_ENTER:
  case '\n':
  case '\r':
    return 4;
    break;
  default:
    return c;
    break;
  }
}


x86 assembly (clang, -O0):
<io_getkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <getch@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
sub    $0xa,%eax
je     11d5 <io_getkey+0xc5>
jmp    1135 <io_getkey+0x25>
mov    -0xc(%rbp),%eax
sub    $0xd,%eax
je     11d5 <io_getkey+0xc5>
jmp    1146 <io_getkey+0x36>
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
je     11bd <io_getkey+0xad>
jmp    1159 <io_getkey+0x49>
mov    -0xc(%rbp),%eax
sub    $0x81,%eax
je     11b1 <io_getkey+0xa1>
jmp    116c <io_getkey+0x5c>
mov    -0xc(%rbp),%eax
sub    $0x82,%eax
je     11a5 <io_getkey+0x95>
jmp    117f <io_getkey+0x6f>
mov    -0xc(%rbp),%eax
sub    $0x83,%eax
je     11d5 <io_getkey+0xc5>
jmp    1192 <io_getkey+0x82>
mov    -0xc(%rbp),%eax
sub    $0x84,%eax
je     11c9 <io_getkey+0xb9>
jmp    11e1 <io_getkey+0xd1>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <io_getkey+0xd7>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <io_getkey+0xd7>
movl   $0x2,-0x4(%rbp)
jmp    11e7 <io_getkey+0xd7>
movl   $0x3,-0x4(%rbp)
jmp    11e7 <io_getkey+0xd7>
movl   $0x4,-0x4(%rbp)
jmp    11e7 <io_getkey+0xd7>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_getkey>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getch@plt>
lea    -0x80(%rax),%ecx
cmp    $0x4,%ecx
ja     1139 <io_getkey+0x29>
lea    0xed7(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0x2,%ebx
jmp    115a <io_getkey+0x4a>
cmp    $0xa,%eax
je     1143 <io_getkey+0x33>
cmp    $0xd,%eax
jne    1158 <io_getkey+0x48>
mov    $0x4,%ebx
jmp    115a <io_getkey+0x4a>
mov    $0x3,%ebx
jmp    115a <io_getkey+0x4a>
mov    $0x1,%ebx
jmp    115a <io_getkey+0x4a>
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @io_getkey() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @getch()
store i32 %3, i32* %2
switch i32 %3, label %9 [
i32 130, label %4
i32 129, label %5
i32 128, label %6
i32 132, label %7
i32 131, label %8
i32 10, label %8
i32 13, label %8
]
4: ; preds = %0
store i32 0, i32* %1
br label %11
5: ; preds = %0
store i32 1, i32* %1
br label %11
6: ; preds = %0
store i32 2, i32* %1
br label %11
7: ; preds = %0
store i32 3, i32* %1
br label %11
8: ; preds = %0, %0, %0
store i32 4, i32* %1
br label %11
9: ; preds = %0
%10 = load i32, i32* %2
store i32 %10, i32* %1
br label %11
11: ; preds = %9, %8, %7, %6, %5, %4
%12 = load i32, i32* %1
ret i32 %12
}

LLVM IR (-O2):
define i32 @io_getkey() {
%1 = tail call i32 (...) @getch()
switch i32 %1, label %6 [
i32 130, label %7
i32 129, label %2
i32 128, label %3
i32 132, label %4
i32 131, label %5
i32 10, label %5
i32 13, label %5
]
2: ; preds = %0
br label %7
3: ; preds = %0
br label %7
4: ; preds = %0
br label %7
5: ; preds = %0, %0, %0
br label %7
6: ; preds = %0
br label %7
7: ; preds = %0, %6, %5, %4, %3, %2
%8 = phi i32 [ %1, %6 ], [ 4, %5 ], [ 3, %4 ], [ 2, %3 ], [ 1, %2 ], [ 0, %0 ]
ret i32 %8
}