#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 */
typedef int uint32_t;
struct pollfd {
  int /*<<< orphan*/ events;
  int /*<<< orphan*/ fd;
};
typedef int /*<<< orphan*/ fds;
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ *initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/ *, int /*<<< orphan*/);
int keystroke_pop(int *);
int /*<<< orphan*/ memset(struct pollfd *, int /*<<< orphan*/, int);
int /*<<< orphan*/ nodelay(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ noecho();
scalar_t__ poll(struct pollfd *, int, int);
int /*<<< orphan*/ printw(char *, ...);
int /*<<< orphan*/ raw();
int /*<<< orphan*/ refresh();
int main(void) {
  uint32_t keystroke;
  WINDOW *window;
  struct pollfd fds;
  int retval = 0;
  window = initscr();
  keypad(window, TRUE);
  nodelay(window, TRUE);
  noecho();
  raw();
  memset(&fds, 0, sizeof(fds));
  fds.fd = STDIN_FILENO;
  fds.events = POLLIN;
  printw("press ESC to exit\n\r");
  refresh();
  do {
    while (poll(&fds, 1, 25000) == 0)
      ;
    keystroke = keystroke_pop(&retval);
    printw("%x\n\r", keystroke);
    refresh();
  } while (keystroke != 0x1b);
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <initscr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1030 <keypad@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
call   1090 <nodelay@plt>
mov    $0x0,%al
call   10d0 <noecho@plt>
mov    $0x0,%al
call   1050 <raw@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1080 <printw@plt>
mov    $0x0,%al
call   10a0 <refresh@plt>
jmp    1245 <main+0x95>
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0x61a8,%edx
call   10b0 <poll@plt>
cmp    $0x0,%rax
jne    1267 <main+0xb7>
jmp    1245 <main+0x95>
lea    -0x1c(%rbp),%rdi
call   1070 <keystroke_pop@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1080 <printw@plt>
mov    $0x0,%al
call   10a0 <refresh@plt>
cmpl   $0x1b,-0x8(%rbp)
jne    1240 <main+0x90>
mov    $0x0,%al
call   10c0 <endwin@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
call   1040 <initscr@plt>
mov    %rax,%rbx
mov    0x2e15(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rax,%rdi
call   1030 <keypad@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1090 <nodelay@plt>
xor    %eax,%eax
call   10d0 <noecho@plt>
xor    %eax,%eax
call   1050 <raw@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0xdd4(%rip),%rdi
xor    %eax,%eax
call   1080 <printw@plt>
xor    %eax,%eax
call   10a0 <refresh@plt>
lea    0xc(%rsp),%r14
lea    0xdce(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x61a8,%edx
call   10b0 <poll@plt>
test   %rax,%rax
je     1250 <main+0xa0>
mov    %r14,%rdi
call   1070 <keystroke_pop@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printw@plt>
xor    %eax,%eax
call   10a0 <refresh@plt>
cmp    $0x1b,%ebp
jne    1250 <main+0xa0>
xor    %eax,%eax
call   10c0 <endwin@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@TRUE = global i32 0
@STDIN_FILENO = global i32 0
@POLLIN = global i32 0
@.str = [20 x i8] c"press ESC to exit\0A\0D\00"
@.str.1 = [5 x i8] c"%x\0A\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.pollfd
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32* (...) @initscr()
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = load i32, i32* @TRUE
%9 = call i32 @keypad(i32* %7, i32 %8)
%10 = load i32*, i32** %3
%11 = load i32, i32* @TRUE
%12 = call i32 @nodelay(i32* %10, i32 %11)
%13 = call i32 (...) @noecho()
%14 = call i32 (...) @raw()
%15 = call i32 @memset(%struct.pollfd* %4, i32 0, i32 8)
%16 = load i32, i32* @STDIN_FILENO
%17 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @POLLIN
%19 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 0
store i32 %18, i32* %19
%20 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%21 = call i32 (...) @refresh()
br label %22
22: ; preds = %32, %0
br label %23
23: ; preds = %26, %22
%24 = call i64 @poll(%struct.pollfd* %4, i32 1, i32 25000)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
br label %23
27: ; preds = %23
%28 = call i32 @keystroke_pop(i32* %5)
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = call i32 (...) @refresh()
br label %32
32: ; preds = %27
%33 = load i32, i32* %2
%34 = icmp ne i32 %33, 27
br i1 %34, label %22, label %35
35: ; preds = %32
%36 = call i32 (...) @endwin()
ret i32 0
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@TRUE = global i32 0
@STDIN_FILENO = global i32 0
@POLLIN = global i32 0
@.str = [20 x i8] c"press ESC to exit\0A\0D\00"
@.str.1 = [5 x i8] c"%x\0A\0D\00"
define i32 @main() {
%1 = alloca %struct.pollfd
%2 = alloca i32
%3 = bitcast %struct.pollfd* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32* (...) @initscr()
%6 = load i32, i32* @TRUE
%7 = tail call i32 @keypad(i32* %5, i32 %6)
%8 = load i32, i32* @TRUE
%9 = tail call i32 @nodelay(i32* %5, i32 %8)
%10 = tail call i32 (...) @noecho()
%11 = tail call i32 (...) @raw()
%12 = call i32 @memset(%struct.pollfd* %1, i32 0, i32 8)
%13 = load i32, i32* @STDIN_FILENO
%14 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @POLLIN
%16 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 0
store i32 %15, i32* %16
%17 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (...) @refresh()
br label %19
19: ; preds = %22, %0
%20 = call i64 @poll(%struct.pollfd* %1, i32 1, i32 25000)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19, %23
br label %19
23: ; preds = %19
%24 = call i32 @keystroke_pop(i32* %2)
%25 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = call i32 (...) @refresh()
%27 = icmp eq i32 %24, 27
br i1 %27, label %28, label %22
28: ; preds = %23
%29 = call i32 (...) @endwin()
ret i32 0
}