#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 ECANCELED;
int ERR;
#define KEY_RESIZE 128
int /*<<< orphan*/ accel_toggle();
int /*<<< orphan*/ bboard_toggle();
int /*<<< orphan*/ classic_toggle();
int /*<<< orphan*/ drums_toggle();
int /*<<< orphan*/ freeze_toggle();
int getch();
int /*<<< orphan*/ guit_toggle();
int /*<<< orphan*/ handle_resize();
int /*<<< orphan*/ ir_toggle();
int /*<<< orphan*/ key_toggle();
int /*<<< orphan*/ led_toggle(int);
int /*<<< orphan*/ mp_normalization_toggle();
int /*<<< orphan*/ mp_toggle();
int /*<<< orphan*/ nunchuk_toggle();
int /*<<< orphan*/ pro_toggle();
int /*<<< orphan*/ refresh_all();
int /*<<< orphan*/ rumble_toggle();
int keyboard(void) {
  int key;
  key = getch();
  if (key == ERR)
    return 0;
  switch (key) {
  case KEY_RESIZE:
    handle_resize();
    break;
  case 'k':
    key_toggle();
    break;
  case 'a':
    accel_toggle();
    break;
  case 'i':
    ir_toggle();
    break;
  case 'm':
    mp_toggle();
    break;
  case 'n':
    mp_normalization_toggle();
    break;
  case 'N':
    nunchuk_toggle();
    break;
  case 'c':
    classic_toggle();
    break;
  case 'b':
    bboard_toggle();
    break;
  case 'p':
    pro_toggle();
    break;
  case 'g':
    guit_toggle();
    break;
  case 'd':
    drums_toggle();
    break;
  case 'r':
    rumble_toggle();
    break;
  case '1':
    led_toggle(0);
    break;
  case '2':
    led_toggle(1);
    break;
  case '3':
    led_toggle(2);
    break;
  case '4':
    led_toggle(3);
    break;
  case 'f':
    freeze_toggle();
    break;
  case 's':
    refresh_all();
    break;
  case 'q':
    return -ECANCELED;
  }
  return 0;
}


x86 assembly (clang, -O0):
<keyboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   10d0 <getch@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2dbc(%rip),%rcx
cmp    (%rcx),%eax
jne    1240 <keyboard+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1370 <keyboard+0x160>
mov    -0x8(%rbp),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4f,%eax
ja     1369 <keyboard+0x159>
mov    -0x10(%rbp),%rax
lea    0xda0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1060 <handle_resize@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1080 <key_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1040 <accel_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   10c0 <ir_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1130 <mp_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1120 <mp_normalization_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1090 <nunchuk_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   10a0 <classic_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   10e0 <bboard_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1030 <pro_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1070 <guit_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   10b0 <drums_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1110 <rumble_toggle@plt>
jmp    1369 <keyboard+0x159>
xor    %edi,%edi
call   10f0 <led_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x1,%edi
call   10f0 <led_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x2,%edi
call   10f0 <led_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x3,%edi
call   10f0 <led_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1100 <freeze_toggle@plt>
jmp    1369 <keyboard+0x159>
mov    $0x0,%al
call   1050 <refresh_all@plt>
jmp    1369 <keyboard+0x159>
xor    %eax,%eax
mov    0x2c81(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1370 <keyboard+0x160>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keyboard>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   10d0 <getch@plt>
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
jne    1229 <keyboard+0x19>
mov    %ebx,%eax
pop    %rbx
ret
add    $0xffffffcf,%eax
cmp    $0x4f,%eax
ja     1225 <keyboard+0x15>
lea    0xdc8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %ebx,%ebx
xor    %edi,%edi
call   10f0 <led_toggle@plt>
jmp    1225 <keyboard+0x15>
mov    $0x1,%edi
call   10f0 <led_toggle@plt>
jmp    1225 <keyboard+0x15>
mov    $0x2,%edi
call   10f0 <led_toggle@plt>
jmp    1225 <keyboard+0x15>
mov    $0x3,%edi
call   10f0 <led_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <nunchuk_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <accel_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   10e0 <bboard_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <classic_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <drums_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1100 <freeze_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <guit_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <ir_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <key_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1130 <mp_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1120 <mp_normalization_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <pro_toggle@plt>
jmp    1225 <keyboard+0x15>
mov    0x2ccd(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1110 <rumble_toggle@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <refresh_all@plt>
jmp    1225 <keyboard+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <handle_resize@plt>
jmp    1225 <keyboard+0x15>

LLVM IR (-O0):
@ERR = global i32 0
@ECANCELED = global i32 0
define i32 @keyboard() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @getch()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @ERR
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 0, i32* %1
br label %52
8: ; preds = %0
%9 = load i32, i32* %2
switch i32 %9, label %51 [
i32 128, label %10
i32 107, label %12
i32 97, label %14
i32 105, label %16
i32 109, label %18
i32 110, label %20
i32 78, label %22
i32 99, label %24
i32 98, label %26
i32 112, label %28
i32 103, label %30
i32 100, label %32
i32 114, label %34
i32 49, label %36
i32 50, label %38
i32 51, label %40
i32 52, label %42
i32 102, label %44
i32 115, label %46
i32 113, label %48
]
10: ; preds = %8
%11 = call i32 (...) @handle_resize()
br label %51
12: ; preds = %8
%13 = call i32 (...) @key_toggle()
br label %51
14: ; preds = %8
%15 = call i32 (...) @accel_toggle()
br label %51
16: ; preds = %8
%17 = call i32 (...) @ir_toggle()
br label %51
18: ; preds = %8
%19 = call i32 (...) @mp_toggle()
br label %51
20: ; preds = %8
%21 = call i32 (...) @mp_normalization_toggle()
br label %51
22: ; preds = %8
%23 = call i32 (...) @nunchuk_toggle()
br label %51
24: ; preds = %8
%25 = call i32 (...) @classic_toggle()
br label %51
26: ; preds = %8
%27 = call i32 (...) @bboard_toggle()
br label %51
28: ; preds = %8
%29 = call i32 (...) @pro_toggle()
br label %51
30: ; preds = %8
%31 = call i32 (...) @guit_toggle()
br label %51
32: ; preds = %8
%33 = call i32 (...) @drums_toggle()
br label %51
34: ; preds = %8
%35 = call i32 (...) @rumble_toggle()
br label %51
36: ; preds = %8
%37 = call i32 @led_toggle(i32 0)
br label %51
38: ; preds = %8
%39 = call i32 @led_toggle(i32 1)
br label %51
40: ; preds = %8
%41 = call i32 @led_toggle(i32 2)
br label %51
42: ; preds = %8
%43 = call i32 @led_toggle(i32 3)
br label %51
44: ; preds = %8
%45 = call i32 (...) @freeze_toggle()
br label %51
46: ; preds = %8
%47 = call i32 (...) @refresh_all()
br label %51
48: ; preds = %8
%49 = load i32, i32* @ECANCELED
%50 = sub nsw i32 0, %49
store i32 %50, i32* %1
br label %52
51: ; preds = %8, %46, %44, %42, %40, %38, %36, %34, %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10
store i32 0, i32* %1
br label %52
52: ; preds = %51, %48, %7
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
@ERR = global i32 0
@ECANCELED = global i32 0
define i32 @keyboard() {
%1 = tail call i32 (...) @getch()
%2 = load i32, i32* @ERR
%3 = icmp eq i32 %1, %2
br i1 %3, label %46, label %4
4: ; preds = %0
switch i32 %1, label %46 [
i32 128, label %5
i32 107, label %7
i32 97, label %9
i32 105, label %11
i32 109, label %13
i32 110, label %15
i32 78, label %17
i32 99, label %19
i32 98, label %21
i32 112, label %23
i32 103, label %25
i32 100, label %27
i32 114, label %29
i32 49, label %31
i32 50, label %33
i32 51, label %35
i32 52, label %37
i32 102, label %39
i32 115, label %41
i32 113, label %43
]
5: ; preds = %4
%6 = tail call i32 (...) @handle_resize()
br label %46
7: ; preds = %4
%8 = tail call i32 (...) @key_toggle()
br label %46
9: ; preds = %4
%10 = tail call i32 (...) @accel_toggle()
br label %46
11: ; preds = %4
%12 = tail call i32 (...) @ir_toggle()
br label %46
13: ; preds = %4
%14 = tail call i32 (...) @mp_toggle()
br label %46
15: ; preds = %4
%16 = tail call i32 (...) @mp_normalization_toggle()
br label %46
17: ; preds = %4
%18 = tail call i32 (...) @nunchuk_toggle()
br label %46
19: ; preds = %4
%20 = tail call i32 (...) @classic_toggle()
br label %46
21: ; preds = %4
%22 = tail call i32 (...) @bboard_toggle()
br label %46
23: ; preds = %4
%24 = tail call i32 (...) @pro_toggle()
br label %46
25: ; preds = %4
%26 = tail call i32 (...) @guit_toggle()
br label %46
27: ; preds = %4
%28 = tail call i32 (...) @drums_toggle()
br label %46
29: ; preds = %4
%30 = tail call i32 (...) @rumble_toggle()
br label %46
31: ; preds = %4
%32 = tail call i32 @led_toggle(i32 0)
br label %46
33: ; preds = %4
%34 = tail call i32 @led_toggle(i32 1)
br label %46
35: ; preds = %4
%36 = tail call i32 @led_toggle(i32 2)
br label %46
37: ; preds = %4
%38 = tail call i32 @led_toggle(i32 3)
br label %46
39: ; preds = %4
%40 = tail call i32 (...) @freeze_toggle()
br label %46
41: ; preds = %4
%42 = tail call i32 (...) @refresh_all()
br label %46
43: ; preds = %4
%44 = load i32, i32* @ECANCELED
%45 = sub nsw i32 0, %44
br label %46
46: ; preds = %5, %7, %9, %11, %13, %15, %17, %19, %21, %23, %25, %27, %29, %31, %33, %35, %37, %39, %41, %4, %0, %43
%47 = phi i32 [ %45, %43 ], [ 0, %0 ], [ 0, %4 ], [ 0, %41 ], [ 0, %39 ], [ 0, %37 ], [ 0, %35 ], [ 0, %33 ], [ 0, %31 ], [ 0, %29 ], [ 0, %27 ], [ 0, %25 ], [ 0, %23 ], [ 0, %21 ], [ 0, %19 ], [ 0, %17 ], [ 0, %15 ], [ 0, %13 ], [ 0, %11 ], [ 0, %9 ], [ 0, %7 ], [ 0, %5 ]
ret i32 %47
}