#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 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int getch();
int capture_keyboard() {
  int key = 0;
  switch (getch()) {
  case KEY_LEFT:
  case 'a':
    key = 'a';
    break;
  case KEY_DOWN:
  case 's':
    key = 's';
    break;
  case KEY_UP:
  case 'w':
    key = 'w';
    break;
  case KEY_RIGHT:
  case 'd':
    key = 'd';
    break;
  case 'x':
    key = 'x';
    break;
  default:
    break;
  }
  return key;
}


x86 assembly (clang, -O0):
<capture_keyboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1030 <getch@plt>
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x22,%eax
ja     1188 <capture_keyboard+0x78>
mov    -0x10(%rbp),%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x61,-0x4(%rbp)
jmp    118d <capture_keyboard+0x7d>
movl   $0x73,-0x4(%rbp)
jmp    118d <capture_keyboard+0x7d>
movl   $0x77,-0x4(%rbp)
jmp    118d <capture_keyboard+0x7d>
movl   $0x64,-0x4(%rbp)
jmp    118d <capture_keyboard+0x7d>
movl   $0x78,-0x4(%rbp)
jmp    118d <capture_keyboard+0x7d>
jmp    118d <capture_keyboard+0x7d>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<capture_keyboard>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getch@plt>
add    $0xffffff9f,%eax
cmp    $0x22,%eax
ja     1153 <capture_keyboard+0x43>
lea    0xed7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x61,%ebx
jmp    1153 <capture_keyboard+0x43>
mov    $0x64,%ebx
jmp    1153 <capture_keyboard+0x43>
mov    $0x73,%ebx
jmp    1153 <capture_keyboard+0x43>
mov    $0x77,%ebx
jmp    1153 <capture_keyboard+0x43>
mov    $0x78,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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