#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 */
struct event_handler {
  int dummy;
};

/* Variables and functions */
#define KEY_DOWN 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int /*<<< orphan*/ board_down();
int /*<<< orphan*/ board_left();
int /*<<< orphan*/ board_right();
int /*<<< orphan*/ board_up();
int getch();
int event_handler_stdin_in(struct event_handler *handler) {
  (void)handler;
  switch (getch()) {
  case 'h':
  case KEY_LEFT:
    board_left();
    break;
  case KEY_DOWN:
  case 'j':
    board_down();
    break;
  case KEY_UP:
  case 'k':
    board_up();
    break;
  case KEY_RIGHT:
  case 'l':
    board_right();
    break;
  case 'q':
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<event_handler_stdin_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
call   1050 <getch@plt>
add    $0xffffff98,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x1b,%eax
ja     11c5 <event_handler_stdin_in+0x75>
mov    -0x18(%rbp),%rax
lea    0xe80(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1060 <board_left@plt>
jmp    11c5 <event_handler_stdin_in+0x75>
mov    $0x0,%al
call   1070 <board_down@plt>
jmp    11c5 <event_handler_stdin_in+0x75>
mov    $0x0,%al
call   1040 <board_up@plt>
jmp    11c5 <event_handler_stdin_in+0x75>
mov    $0x0,%al
call   1030 <board_right@plt>
jmp    11c5 <event_handler_stdin_in+0x75>
movl   $0x0,-0x4(%rbp)
jmp    11cc <event_handler_stdin_in+0x7c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<event_handler_stdin_in>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getch@plt>
add    $0xffffff98,%eax
cmp    $0x1b,%eax
ja     1194 <event_handler_stdin_in+0x44>
lea    0xe97(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   1060 <board_left@plt>
jmp    1194 <event_handler_stdin_in+0x44>
xor    %eax,%eax
call   1070 <board_down@plt>
jmp    1194 <event_handler_stdin_in+0x44>
xor    %eax,%eax
call   1040 <board_up@plt>
jmp    1194 <event_handler_stdin_in+0x44>
xor    %eax,%eax
call   1030 <board_right@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.event_handler = type { i32 }
define i32 @event_handler_stdin_in(%struct.event_handler* %0) {
%2 = alloca i32
%3 = alloca %struct.event_handler*
store %struct.event_handler* %0, %struct.event_handler** %3
%4 = load %struct.event_handler*, %struct.event_handler** %3
%5 = call i32 (...) @getch()
switch i32 %5, label %15 [
i32 104, label %6
i32 130, label %6
i32 131, label %8
i32 106, label %8
i32 128, label %10
i32 107, label %10
i32 129, label %12
i32 108, label %12
i32 113, label %14
]
6: ; preds = %1, %1
%7 = call i32 (...) @board_left()
br label %15
8: ; preds = %1, %1
%9 = call i32 (...) @board_down()
br label %15
10: ; preds = %1, %1
%11 = call i32 (...) @board_up()
br label %15
12: ; preds = %1, %1
%13 = call i32 (...) @board_right()
br label %15
14: ; preds = %1
store i32 0, i32* %2
br label %16
15: ; preds = %1, %12, %10, %8, %6
store i32 -1, i32* %2
br label %16
16: ; preds = %15, %14
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
%struct.event_handler = type { i32 }
define i32 @event_handler_stdin_in(%struct.event_handler* nocapture readnone %0) {
%2 = tail call i32 (...) @getch()
switch i32 %2, label %11 [
i32 104, label %3
i32 130, label %3
i32 131, label %5
i32 106, label %5
i32 128, label %7
i32 107, label %7
i32 129, label %9
i32 108, label %9
i32 113, label %12
]
3: ; preds = %1, %1
%4 = tail call i32 (...) @board_left()
br label %11
5: ; preds = %1, %1
%6 = tail call i32 (...) @board_down()
br label %11
7: ; preds = %1, %1
%8 = tail call i32 (...) @board_up()
br label %11
9: ; preds = %1, %1
%10 = tail call i32 (...) @board_right()
br label %11
11: ; preds = %1, %9, %7, %5, %3
br label %12
12: ; preds = %1, %11
%13 = phi i32 [ -1, %11 ], [ 0, %1 ]
ret i32 %13
}