#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*/ clear();
int /*<<< orphan*/ endwin();
int getch();
int /*<<< orphan*/ initscr();
int keypad(int /*<<< orphan*/, int);
int meta(int /*<<< orphan*/, int);
int /*<<< orphan*/ move(int, int /*<<< orphan*/);
int /*<<< orphan*/ mvprintw(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                            int);
int nodelay(int /*<<< orphan*/, int);
int noecho();
int nonl();
int /*<<< orphan*/ printf(char *);
int raw();
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ usleep(int);
int main() {
  int ch;
  initscr();
  if (raw() == ERR)
    goto fail;
  if (noecho() == ERR)
    goto fail;
  if (nodelay(stdscr, true) == ERR)
    goto fail;
  if (keypad(stdscr, true) == ERR)
    goto fail;
  if (nonl() == ERR)
    goto fail;
  if (meta(stdscr, true) == ERR)
    goto fail;
  while ((ch = getch()) != 'q') {
    if (ch == ERR) {
      usleep(100000);
      continue;
    }
    clear();
    mvprintw(0, 0, "0x%x", ch);
    move(1, 0);
    refresh();
  }
  endwin();
  return 0;
fail:
  endwin();
  printf("error\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <initscr@plt>
mov    $0x0,%al
call   1060 <raw@plt>
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%eax
jne    1221 <main+0x31>
jmp    134a <main+0x15a>
mov    $0x0,%al
call   10d0 <noecho@plt>
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%eax
jne    123c <main+0x4c>
jmp    134a <main+0x15a>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1080 <nodelay@plt>
mov    0x2d92(%rip),%rcx
cmp    (%rcx),%eax
jne    1263 <main+0x73>
jmp    134a <main+0x15a>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1040 <keypad@plt>
mov    0x2d6b(%rip),%rcx
cmp    (%rcx),%eax
jne    128a <main+0x9a>
jmp    134a <main+0x15a>
mov    $0x0,%al
call   1070 <nonl@plt>
mov    0x2d50(%rip),%rcx
cmp    (%rcx),%eax
jne    12a5 <main+0xb5>
jmp    134a <main+0x15a>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   10a0 <meta@plt>
mov    0x2d29(%rip),%rcx
cmp    (%rcx),%eax
jne    12cc <main+0xdc>
jmp    134a <main+0x15a>
jmp    12d1 <main+0xe1>
mov    $0x0,%al
call   10b0 <getch@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x71,%eax
je     1337 <main+0x147>
mov    -0x8(%rbp),%eax
mov    0x2cfa(%rip),%rcx
cmp    (%rcx),%eax
jne    1305 <main+0x115>
mov    $0x186a0,%edi
call   1100 <usleep@plt>
jmp    12d1 <main+0xe1>
mov    $0x0,%al
call   10e0 <clear@plt>
mov    -0x8(%rbp),%ecx
xor    %esi,%esi
lea    0xce8(%rip),%rdx
mov    %esi,%edi
call   10f0 <mvprintw@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1110 <move@plt>
mov    $0x0,%al
call   1090 <refresh@plt>
jmp    12d1 <main+0xe1>
mov    $0x0,%al
call   10c0 <endwin@plt>
movl   $0x0,-0x4(%rbp)
jmp    1364 <main+0x174>
mov    $0x0,%al
call   10c0 <endwin@plt>
lea    0xcad(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <initscr@plt>
xor    %eax,%eax
call   1060 <raw@plt>
mov    0x2ddc(%rip),%r15
cmp    (%r15),%eax
je     1263 <main+0x73>
xor    %eax,%eax
call   10d0 <noecho@plt>
cmp    (%r15),%eax
je     1263 <main+0x73>
mov    0x2dbc(%rip),%rbx
mov    (%rbx),%edi
mov    $0x1,%esi
call   1080 <nodelay@plt>
cmp    (%r15),%eax
je     1263 <main+0x73>
mov    (%rbx),%edi
mov    $0x1,%esi
call   1040 <keypad@plt>
cmp    (%r15),%eax
je     1263 <main+0x73>
xor    %eax,%eax
call   1070 <nonl@plt>
cmp    (%r15),%eax
je     1263 <main+0x73>
mov    (%rbx),%edi
mov    $0x1,%esi
call   10a0 <meta@plt>
cmp    (%r15),%eax
jne    1288 <main+0x98>
xor    %eax,%eax
call   10c0 <endwin@plt>
lea    0xd94(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <getch@plt>
cmp    $0x71,%eax
jne    129f <main+0xaf>
xor    %eax,%eax
call   10c0 <endwin@plt>
jmp    127b <main+0x8b>
mov    %eax,%ebp
lea    0xd58(%rip),%r14
jmp    12c2 <main+0xd2>
mov    $0x186a0,%edi
call   1100 <usleep@plt>
xor    %eax,%eax
call   10b0 <getch@plt>
mov    %eax,%ebp
cmp    $0x71,%eax
je     1296 <main+0xa6>
cmp    (%r15),%ebp
je     12aa <main+0xba>
xor    %eax,%eax
call   10e0 <clear@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   10f0 <mvprintw@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1110 <move@plt>
xor    %eax,%eax
call   1090 <refresh@plt>
jmp    12b4 <main+0xc4>

LLVM IR (-O0):
@ERR = global i32 0
@stdscr = global i32 0
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [7 x i8] c"error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @initscr()
%4 = call i32 (...) @raw()
%5 = load i32, i32* @ERR
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %8
7: ; preds = %0
br label %54
8: ; preds = %0
%9 = call i32 (...) @noecho()
%10 = load i32, i32* @ERR
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
br label %54
13: ; preds = %8
%14 = load i32, i32* @stdscr
%15 = call i32 @nodelay(i32 %14, i32 1)
%16 = load i32, i32* @ERR
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %13
br label %54
19: ; preds = %13
%20 = load i32, i32* @stdscr
%21 = call i32 @keypad(i32 %20, i32 1)
%22 = load i32, i32* @ERR
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %19
br label %54
25: ; preds = %19
%26 = call i32 (...) @nonl()
%27 = load i32, i32* @ERR
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
br label %54
30: ; preds = %25
%31 = load i32, i32* @stdscr
%32 = call i32 @meta(i32 %31, i32 1)
%33 = load i32, i32* @ERR
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %30
br label %54
36: ; preds = %30
br label %37
37: ; preds = %46, %44, %36
%38 = call i32 (...) @getch()
store i32 %38, i32* %2
%39 = icmp ne i32 %38, 113
br i1 %39, label %40, label %52
40: ; preds = %37
%41 = load i32, i32* %2
%42 = load i32, i32* @ERR
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @usleep(i32 100000)
br label %37
46: ; preds = %40
%47 = call i32 (...) @clear()
%48 = load i32, i32* %2
%49 = call i32 @mvprintw(i32 0, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %48)
%50 = call i32 @move(i32 1, i32 0)
%51 = call i32 (...) @refresh()
br label %37
52: ; preds = %37
%53 = call i32 (...) @endwin()
store i32 0, i32* %1
br label %57
54: ; preds = %35, %29, %24, %18, %12, %7
%55 = call i32 (...) @endwin()
%56 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %57
57: ; preds = %54, %52
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@ERR = global i32 0
@stdscr = global i32 0
@.str = [5 x i8] c"0x%x\00"
@str = [6 x i8] c"error\00"
define i32 @main() {
%1 = tail call i32 (...) @initscr()
%2 = tail call i32 (...) @raw()
%3 = load i32, i32* @ERR
%4 = icmp eq i32 %2, %3
br i1 %4, label %47, label %5
5: ; preds = %0
%6 = tail call i32 (...) @noecho()
%7 = load i32, i32* @ERR
%8 = icmp eq i32 %6, %7
br i1 %8, label %47, label %9
9: ; preds = %5
%10 = load i32, i32* @stdscr
%11 = tail call i32 @nodelay(i32 %10, i32 1)
%12 = load i32, i32* @ERR
%13 = icmp eq i32 %11, %12
br i1 %13, label %47, label %14
14: ; preds = %9
%15 = load i32, i32* @stdscr
%16 = tail call i32 @keypad(i32 %15, i32 1)
%17 = load i32, i32* @ERR
%18 = icmp eq i32 %16, %17
br i1 %18, label %47, label %19
19: ; preds = %14
%20 = tail call i32 (...) @nonl()
%21 = load i32, i32* @ERR
%22 = icmp eq i32 %20, %21
br i1 %22, label %47, label %23
23: ; preds = %19
%24 = load i32, i32* @stdscr
%25 = tail call i32 @meta(i32 %24, i32 1)
%26 = load i32, i32* @ERR
%27 = icmp eq i32 %25, %26
br i1 %27, label %47, label %28
28: ; preds = %23
%29 = tail call i32 (...) @getch()
%30 = icmp eq i32 %29, 113
br i1 %30, label %45, label %31
31: ; preds = %28, %37
%32 = phi i32 [ %38, %37 ], [ %29, %28 ]
%33 = load i32, i32* @ERR
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = tail call i32 @usleep(i32 100000)
br label %37
37: ; preds = %35, %40
%38 = tail call i32 (...) @getch()
%39 = icmp eq i32 %38, 113
br i1 %39, label %45, label %31
40: ; preds = %31
%41 = tail call i32 (...) @clear()
%42 = tail call i32 @mvprintw(i32 0, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %32)
%43 = tail call i32 @move(i32 1, i32 0)
%44 = tail call i32 (...) @refresh()
br label %37
45: ; preds = %37, %28
%46 = tail call i32 (...) @endwin()
br label %50
47: ; preds = %23, %19, %14, %9, %5, %0
%48 = tail call i32 (...) @endwin()
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %50
50: ; preds = %47, %45
%51 = phi i32 [ 1, %47 ], [ 0, %45 ]
ret i32 %51
}