#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 /*<<< orphan*/ stdscr;
int wgetch(int /*<<< orphan*/);
int getkey(void) {
  int ch = wgetch(stdscr);
  if (0x1b == ch) {
    ch = wgetch(stdscr);
    if ('[' == ch) {
      ch = wgetch(stdscr);
      switch (ch) {
      case 'A':
        ch = (256 + 'A');
        break;
      case 'B':
        ch = (256 + 'B');
        break;
      case 'C':
        ch = (256 + 'C');
        break;
      case 'D':
        ch = (256 + 'D');
        break;
      case 'H':
        ch = (256 + 'H');
        break;
      }
    }
  }
  return ch;
}


x86 assembly (clang, -O0):
<getkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
call   1030 <wgetch@plt>
mov    %eax,-0x4(%rbp)
mov    $0x1b,%eax
cmp    -0x4(%rbp),%eax
jne    11d1 <getkey+0xc1>
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
call   1030 <wgetch@plt>
mov    %eax,-0x4(%rbp)
mov    $0x5b,%eax
cmp    -0x4(%rbp),%eax
jne    11cc <getkey+0xbc>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1030 <wgetch@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x7,%eax
ja     11c7 <getkey+0xb7>
mov    -0x10(%rbp),%rax
lea    0xe79(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x141,-0x4(%rbp)
jmp    11c7 <getkey+0xb7>
movl   $0x142,-0x4(%rbp)
jmp    11c7 <getkey+0xb7>
movl   $0x143,-0x4(%rbp)
jmp    11c7 <getkey+0xb7>
movl   $0x144,-0x4(%rbp)
jmp    11c7 <getkey+0xb7>
movl   $0x148,-0x4(%rbp)
jmp    11cc <getkey+0xbc>
jmp    11d1 <getkey+0xc1>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getkey>:
push   %rbx
mov    0x2ed0(%rip),%rbx
mov    (%rbx),%edi
call   1030 <wgetch@plt>
cmp    $0x1b,%eax
jne    1158 <getkey+0x48>
mov    (%rbx),%edi
call   1030 <wgetch@plt>
cmp    $0x5b,%eax
jne    1158 <getkey+0x48>
mov    (%rbx),%edi
call   1030 <wgetch@plt>
mov    %eax,%ecx
add    $0xffffffbf,%ecx
cmp    $0x7,%ecx
ja     1158 <getkey+0x48>
mov    $0x8f,%edx
bt     %ecx,%edx
jae    1158 <getkey+0x48>
movslq %ecx,%rax
lea    0xeab(%rip),%rcx
mov    (%rcx,%rax,4),%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdscr = global i32 0
define i32 @getkey() {
%1 = alloca i32
%2 = load i32, i32* @stdscr
%3 = call i32 @wgetch(i32 %2)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp eq i32 27, %4
br i1 %5, label %6, label %22
6: ; preds = %0
%7 = load i32, i32* @stdscr
%8 = call i32 @wgetch(i32 %7)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = icmp eq i32 91, %9
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = load i32, i32* @stdscr
%13 = call i32 @wgetch(i32 %12)
store i32 %13, i32* %1
%14 = load i32, i32* %1
switch i32 %14, label %20 [
i32 65, label %15
i32 66, label %16
i32 67, label %17
i32 68, label %18
i32 72, label %19
]
15: ; preds = %11
store i32 321, i32* %1
br label %20
16: ; preds = %11
store i32 322, i32* %1
br label %20
17: ; preds = %11
store i32 323, i32* %1
br label %20
18: ; preds = %11
store i32 324, i32* %1
br label %20
19: ; preds = %11
store i32 328, i32* %1
br label %20
20: ; preds = %11, %19, %18, %17, %16, %15
br label %21
21: ; preds = %20, %6
br label %22
22: ; preds = %21, %0
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@stdscr = global i32 0
@switch.table.getkey = [8 x i32] [i32 321, i32 322, i32 323, i32 324, i32 321, i32 321, i32 321, i32 328]
define i32 @getkey() {
%1 = load i32, i32* @stdscr
%2 = tail call i32 @wgetch(i32 %1)
%3 = icmp eq i32 %2, 27
br i1 %3, label %4, label %22
4: ; preds = %0
%5 = load i32, i32* @stdscr
%6 = tail call i32 @wgetch(i32 %5)
%7 = icmp eq i32 %6, 91
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = load i32, i32* @stdscr
%10 = tail call i32 @wgetch(i32 %9)
%11 = add i32 %10, -65
%12 = icmp ult i32 %11, 8
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = trunc i32 %11 to i8
%15 = lshr i8 -113, %14
%16 = and i8 %15, 1
%17 = icmp eq i8 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = sext i32 %11 to i64
%20 = getelementptr inbounds [8 x i32], [8 x i32]* @switch.table.getkey, i64 0, i64 %19
%21 = load i32, i32* %20
br label %22
22: ; preds = %18, %13, %8, %4, %0
%23 = phi i32 [ %10, %8 ], [ %6, %4 ], [ %2, %0 ], [ %10, %13 ], [ %21, %18 ]
ret i32 %23
}