#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_BACKSPACE 137
#define KEY_DC 136
#define KEY_DOWN 135
#define KEY_END 134
#define KEY_HOME 133
#define KEY_LEFT 132
#define KEY_NPAGE 131
#define KEY_PPAGE 130
#define KEY_RIGHT 129
#define KEY_UP 128
int getch();
int curs_getch() {
  int rc;
  rc = getch();
  switch (rc) {
  case KEY_HOME:
    rc = (256 + 7);
    break;
  case KEY_END:
    rc = (256 + 8);
    break;
  case KEY_LEFT:
    rc = (256 + 1);
    break;
  case KEY_RIGHT:
    rc = (256 + 2);
    break;
  case KEY_UP:
    rc = (256 + 3);
    break;
  case KEY_DOWN:
    rc = (256 + 4);
    break;
  case KEY_NPAGE:
    rc = (256 + 6);
    break;
  case KEY_PPAGE:
    rc = (256 + 5);
    break;
  case KEY_BACKSPACE:
  case KEY_DC:
    rc = '\b';
    break;
  }
  return rc;
}


x86 assembly (clang, -O0):
<curs_getch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <getch@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x9,%eax
ja     11b2 <curs_getch+0xa2>
mov    -0x10(%rbp),%rax
lea    0xebe(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x107,-0x4(%rbp)
jmp    11b2 <curs_getch+0xa2>
movl   $0x108,-0x4(%rbp)
jmp    11b2 <curs_getch+0xa2>
movl   $0x101,-0x4(%rbp)
jmp    11b2 <curs_getch+0xa2>
movl   $0x102,-0x4(%rbp)
jmp    11b2 <curs_getch+0xa2>
movl   $0x103,-0x4(%rbp)
jmp    11b2 <curs_getch+0xa2>
movl   $0x104,-0x4(%rbp)
jmp    11b2 <curs_getch+0xa2>
movl   $0x106,-0x4(%rbp)
jmp    11b2 <curs_getch+0xa2>
movl   $0x105,-0x4(%rbp)
jmp    11b2 <curs_getch+0xa2>
movl   $0x8,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<curs_getch>:
push   %rax
xor    %eax,%eax
call   1030 <getch@plt>
mov    %eax,%ecx
add    $0xffffff80,%ecx
cmp    $0x9,%ecx
ja     112f <curs_getch+0x1f>
movslq %ecx,%rax
lea    0xed4(%rip),%rcx
mov    (%rcx,%rax,4),%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @curs_getch() {
%1 = alloca i32
%2 = call i32 (...) @getch()
store i32 %2, i32* %1
%3 = load i32, i32* %1
switch i32 %3, label %13 [
i32 133, label %4
i32 134, label %5
i32 132, label %6
i32 129, label %7
i32 128, label %8
i32 135, label %9
i32 131, label %10
i32 130, label %11
i32 137, label %12
i32 136, label %12
]
4: ; preds = %0
store i32 263, i32* %1
br label %13
5: ; preds = %0
store i32 264, i32* %1
br label %13
6: ; preds = %0
store i32 257, i32* %1
br label %13
7: ; preds = %0
store i32 258, i32* %1
br label %13
8: ; preds = %0
store i32 259, i32* %1
br label %13
9: ; preds = %0
store i32 260, i32* %1
br label %13
10: ; preds = %0
store i32 262, i32* %1
br label %13
11: ; preds = %0
store i32 261, i32* %1
br label %13
12: ; preds = %0, %0
store i32 8, i32* %1
br label %13
13: ; preds = %0, %12, %11, %10, %9, %8, %7, %6, %5, %4
%14 = load i32, i32* %1
ret i32 %14
}

LLVM IR (-O2):
@switch.table.curs_getch = [10 x i32] [i32 259, i32 258, i32 261, i32 262, i32 257, i32 263, i32 264, i32 260, i32 8, i32 8]
define i32 @curs_getch() {
%1 = tail call i32 (...) @getch()
%2 = add i32 %1, -128
%3 = icmp ult i32 %2, 10
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds [10 x i32], [10 x i32]* @switch.table.curs_getch, i64 0, i64 %5
%7 = load i32, i32* %6
br label %8
8: ; preds = %4, %0
%9 = phi i32 [ %1, %0 ], [ %7, %4 ]
ret i32 %9
}