#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 ERR;
int /*<<< orphan*/ EXIT_SUCCESS;
#define KEY_BEG 133
#define KEY_DOWN 132
#define KEY_END 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ clear();
int /*<<< orphan*/ clrtoeol();
int /*<<< orphan*/ crmode();
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getch();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ mvprintw(int, int, char *);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printw(char *, ...);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int main() {
  int key;
  initscr();
  crmode();
  keypad(stdscr, TRUE);
  noecho();
  clear();
  mvprintw(5, 5, "Key pad demonstration. Press 'q' to quit");
  move(7, 5);
  refresh();
  key = getch();
  while (key != ERR && key != 'q') {
    move(7, 5);
    clrtoeol();
    if ((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')) {
      printw("Key was %c", (char)key);
    } else {
      switch (key) {
      case 27:
        printw("%s", "Escape key");
        break;
      case KEY_END:
        printw("%s", "END key");
        break;
      case KEY_BEG:
        printw("%s", "BEGINNING key");
        break;
      case KEY_RIGHT:
        printw("%s", "RIGHT key");
        break;
      case KEY_LEFT:
        printw("%s", "LEFT key");
        break;
      case KEY_UP:
        printw("%s", "UP key");
        break;
      case KEY_DOWN:
        printw("%s", "DOWN key");
        break;
      default:
        printw("Unmatched - %d", key);
        break;
      }
    }
    refresh();
    key = getch();
  }
  endwin();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <initscr@plt>
mov    $0x0,%al
call   10c0 <crmode@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
call   1030 <keypad@plt>
mov    $0x0,%al
call   10a0 <noecho@plt>
mov    $0x0,%al
call   10d0 <clear@plt>
mov    $0x5,%esi
lea    0xde2(%rip),%rdx
mov    %esi,%edi
call   10e0 <mvprintw@plt>
mov    $0x7,%edi
mov    $0x5,%esi
call   10f0 <move@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
mov    0x2d97(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x9(%rbp)
je     1266 <main+0x96>
cmpl   $0x71,-0x8(%rbp)
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1276 <main+0xa6>
jmp    1435 <main+0x265>
mov    $0x7,%edi
mov    $0x5,%esi
call   10f0 <move@plt>
mov    $0x0,%al
call   1090 <clrtoeol@plt>
cmpl   $0x41,-0x8(%rbp)
jl     12a0 <main+0xd0>
cmpl   $0x5a,-0x8(%rbp)
jle    12b4 <main+0xe4>
cmpl   $0x61,-0x8(%rbp)
jl     12cd <main+0xfd>
cmpl   $0x7a,-0x8(%rbp)
jg     12cd <main+0xfd>
mov    -0x8(%rbp),%eax
movsbl %al,%esi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141f <main+0x24f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1b,%eax
je     1353 <main+0x183>
jmp    12e1 <main+0x111>
mov    -0x10(%rbp),%eax
sub    $0x80,%eax
je     13d5 <main+0x205>
jmp    12f4 <main+0x124>
mov    -0x10(%rbp),%eax
sub    $0x81,%eax
je     13a1 <main+0x1d1>
jmp    1307 <main+0x137>
mov    -0x10(%rbp),%eax
sub    $0x82,%eax
je     13bb <main+0x1eb>
jmp    131a <main+0x14a>
mov    -0x10(%rbp),%eax
sub    $0x83,%eax
je     136d <main+0x19d>
jmp    132d <main+0x15d>
mov    -0x10(%rbp),%eax
sub    $0x84,%eax
je     13ef <main+0x21f>
jmp    1340 <main+0x170>
mov    -0x10(%rbp),%eax
sub    $0x85,%eax
je     1387 <main+0x1b7>
jmp    1409 <main+0x239>
lea    0xcda(%rip),%rdi
lea    0xcd6(%rip),%rsi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141a <main+0x24a>
lea    0xcc0(%rip),%rdi
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141a <main+0x24a>
lea    0xca6(%rip),%rdi
lea    0xcb5(%rip),%rsi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141a <main+0x24a>
lea    0xc8c(%rip),%rdi
lea    0xca9(%rip),%rsi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141a <main+0x24a>
lea    0xc72(%rip),%rdi
lea    0xc99(%rip),%rsi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141a <main+0x24a>
lea    0xc58(%rip),%rdi
lea    0xc88(%rip),%rsi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141a <main+0x24a>
lea    0xc3e(%rip),%rdi
lea    0xc75(%rip),%rsi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141a <main+0x24a>
mov    -0x8(%rbp),%esi
lea    0xc68(%rip),%rdi
mov    $0x0,%al
call   1050 <printw@plt>
jmp    141f <main+0x24f>
mov    $0x0,%al
call   1060 <refresh@plt>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0x8(%rbp)
jmp    1245 <main+0x75>
mov    $0x0,%al
call   1080 <endwin@plt>
mov    0x2b85(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <initscr@plt>
xor    %eax,%eax
call   10c0 <crmode@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
call   1030 <keypad@plt>
xor    %eax,%eax
call   10a0 <noecho@plt>
xor    %eax,%eax
call   10d0 <clear@plt>
lea    0xe03(%rip),%rdx
mov    $0x5,%edi
mov    $0x5,%esi
call   10e0 <mvprintw@plt>
mov    $0x7,%edi
mov    $0x5,%esi
call   10f0 <move@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
xor    %eax,%eax
call   1070 <getch@plt>
cmp    $0x71,%eax
je     1365 <main+0x195>
mov    %eax,%r15d
mov    0x2d94(%rip),%r12
cmp    (%r12),%eax
je     1365 <main+0x195>
lea    0xddc(%rip),%rbx
lea    0xde0(%rip),%r14
lea    0xd8d(%rip),%r13
lea    0xde8(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    $0x7,%edi
mov    $0x5,%esi
call   10f0 <move@plt>
xor    %eax,%eax
call   1090 <clrtoeol@plt>
mov    %r15d,%eax
and    $0xffffffdf,%eax
add    $0xffffffbf,%eax
cmp    $0x19,%eax
ja     12c0 <main+0xf0>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printw@plt>
jmp    1337 <main+0x167>
cs nopw 0x0(%rax,%rax,1)
lea    -0x80(%r15),%eax
cmp    $0x5,%eax
ja     12df <main+0x10f>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %r14,%rdi
lea    0xda6(%rip),%rsi
jmp    1330 <main+0x160>
cmp    $0x1b,%r15d
jne    1359 <main+0x189>
mov    %r14,%rdi
lea    0xd60(%rip),%rsi
jmp    1330 <main+0x160>
mov    %r14,%rdi
lea    0xd75(%rip),%rsi
jmp    1330 <main+0x160>
mov    %r14,%rdi
lea    0xd73(%rip),%rsi
jmp    1330 <main+0x160>
mov    %r14,%rdi
lea    0xd47(%rip),%rsi
jmp    1330 <main+0x160>
mov    %r14,%rdi
lea    0xd6b(%rip),%rsi
jmp    1330 <main+0x160>
mov    %r14,%rdi
mov    %rbp,%rsi
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <printw@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
xor    %eax,%eax
call   1070 <getch@plt>
cmp    $0x71,%eax
je     1365 <main+0x195>
mov    %eax,%r15d
cmp    (%r12),%eax
jne    1280 <main+0xb0>
jmp    1365 <main+0x195>
lea    0xd33(%rip),%rdi
jmp    12a7 <main+0xd7>
xor    %eax,%eax
call   1080 <endwin@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stdscr = global i32 0
@TRUE = global i32 0
@.str = [41 x i8] c"Key pad demonstration. Press 'q' to quit\00"
@ERR = global i32 0
@.str.1 = [11 x i8] c"Key was %c\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [11 x i8] c"Escape key\00"
@.str.4 = [8 x i8] c"END key\00"
@.str.5 = [14 x i8] c"BEGINNING key\00"
@.str.6 = [10 x i8] c"RIGHT key\00"
@.str.7 = [9 x i8] c"LEFT key\00"
@.str.8 = [7 x i8] c"UP key\00"
@.str.9 = [9 x i8] c"DOWN key\00"
@.str.10 = [15 x i8] c"Unmatched - %d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @initscr()
%4 = call i32 (...) @crmode()
%5 = load i32, i32* @stdscr
%6 = load i32, i32* @TRUE
%7 = call i32 @keypad(i32 %5, i32 %6)
%8 = call i32 (...) @noecho()
%9 = call i32 (...) @clear()
%10 = call i32 @mvprintw(i32 5, i32 5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @move(i32 7, i32 5)
%12 = call i32 (...) @refresh()
%13 = call i32 (...) @getch()
store i32 %13, i32* %2
br label %14
14: ; preds = %62, %0
%15 = load i32, i32* %2
%16 = load i32, i32* @ERR
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 113
br label %21
21: ; preds = %18, %14
%22 = phi i1 [ false, %14 ], [ %20, %18 ]
br i1 %22, label %23, label %65
23: ; preds = %21
%24 = call i32 @move(i32 7, i32 5)
%25 = call i32 (...) @clrtoeol()
%26 = load i32, i32* %2
%27 = icmp sge i32 %26, 65
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* %2
%30 = icmp sle i32 %29, 90
br i1 %30, label %37, label %31
31: ; preds = %28, %23
%32 = load i32, i32* %2
%33 = icmp sge i32 %32, 97
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = load i32, i32* %2
%36 = icmp sle i32 %35, 122
br i1 %36, label %37, label %42
37: ; preds = %34, %28
%38 = load i32, i32* %2
%39 = trunc i32 %38 to i8
%40 = sext i8 %39 to i32
%41 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %62
42: ; preds = %34, %31
%43 = load i32, i32* %2
switch i32 %43, label %58 [
i32 27, label %44
i32 131, label %46
i32 133, label %48
i32 129, label %50
i32 130, label %52
i32 128, label %54
i32 132, label %56
]
44: ; preds = %42
%45 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %61
46: ; preds = %42
%47 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %61
48: ; preds = %42
%49 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %61
50: ; preds = %42
%51 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %61
52: ; preds = %42
%53 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %61
54: ; preds = %42
%55 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %61
56: ; preds = %42
%57 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
br label %61
58: ; preds = %42
%59 = load i32, i32* %2
%60 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %58, %56, %54, %52, %50, %48, %46, %44
br label %62
62: ; preds = %61, %37
%63 = call i32 (...) @refresh()
%64 = call i32 (...) @getch()
store i32 %64, i32* %2
br label %14
65: ; preds = %21
%66 = call i32 (...) @endwin()
%67 = load i32, i32* @EXIT_SUCCESS
%68 = call i32 @exit(i32 %67)
unreachable
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
@.str = [41 x i8] c"Key pad demonstration. Press 'q' to quit\00"
@ERR = global i32 0
@.str.1 = [11 x i8] c"Key was %c\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [11 x i8] c"Escape key\00"
@.str.4 = [8 x i8] c"END key\00"
@.str.5 = [14 x i8] c"BEGINNING key\00"
@.str.6 = [10 x i8] c"RIGHT key\00"
@.str.7 = [9 x i8] c"LEFT key\00"
@.str.8 = [7 x i8] c"UP key\00"
@.str.9 = [9 x i8] c"DOWN key\00"
@.str.10 = [15 x i8] c"Unmatched - %d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @initscr()
%2 = tail call i32 (...) @crmode()
%3 = load i32, i32* @stdscr
%4 = load i32, i32* @TRUE
%5 = tail call i32 @keypad(i32 %3, i32 %4)
%6 = tail call i32 (...) @noecho()
%7 = tail call i32 (...) @clear()
%8 = tail call i32 @mvprintw(i32 5, i32 5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @move(i32 7, i32 5)
%10 = tail call i32 (...) @refresh()
%11 = tail call i32 (...) @getch()
%12 = load i32, i32* @ERR
%13 = icmp ne i32 %11, %12
%14 = icmp ne i32 %11, 113
%15 = and i1 %14, %13
br i1 %15, label %16, label %49
16: ; preds = %0, %42
%17 = phi i32 [ %44, %42 ], [ %11, %0 ]
%18 = tail call i32 @move(i32 7, i32 5)
%19 = tail call i32 (...) @clrtoeol()
%20 = and i32 %17, -33
%21 = add i32 %20, -65
%22 = icmp ult i32 %21, 26
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %42
25: ; preds = %16
switch i32 %17, label %40 [
i32 27, label %26
i32 131, label %28
i32 133, label %30
i32 129, label %32
i32 130, label %34
i32 128, label %36
i32 132, label %38
]
26: ; preds = %25
%27 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %42
28: ; preds = %25
%29 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %42
30: ; preds = %25
%31 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %42
32: ; preds = %25
%33 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %42
34: ; preds = %25
%35 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %42
36: ; preds = %25
%37 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %42
38: ; preds = %25
%39 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
br label %42
40: ; preds = %25
%41 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %17)
br label %42
42: ; preds = %26, %28, %30, %32, %34, %36, %38, %40, %23
%43 = tail call i32 (...) @refresh()
%44 = tail call i32 (...) @getch()
%45 = load i32, i32* @ERR
%46 = icmp ne i32 %44, %45
%47 = icmp ne i32 %44, 113
%48 = and i1 %47, %46
br i1 %48, label %16, label %49
49: ; preds = %42, %0
%50 = tail call i32 (...) @endwin()
%51 = load i32, i32* @EXIT_SUCCESS
%52 = tail call i32 @exit(i32 %51)
unreachable
}