#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*/ A_NORMAL;
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ attrset(int /*<<< orphan*/);
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ getch();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mvprintw(int, int, char *);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ timeout(int);
void with_ncurses(void (*action)(int, int)) {
  int nrow, ncol;
  initscr();
  getmaxyx(stdscr, nrow, ncol);
  cbreak();
  keypad(stdscr, TRUE);
  noecho();
  action(nrow, ncol);
  timeout(-1);
  attrset(A_NORMAL);
  mvprintw(nrow - 2, 1, "Press any key...");
  getch();
  endwin();
}


x86 assembly (clang, -O0):
<with_ncurses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <initscr@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <getmaxyx@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
mov    $0x0,%al
call   10b0 <noecho@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   *%rax
mov    $0xffffffff,%edi
call   1060 <timeout@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   10a0 <attrset@plt>
mov    -0xc(%rbp),%edi
sub    $0x2,%edi
mov    $0x1,%esi
lea    0xdde(%rip),%rdx
call   10c0 <mvprintw@plt>
mov    $0x0,%al
call   1080 <getch@plt>
mov    $0x0,%al
call   1090 <endwin@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<with_ncurses>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <initscr@plt>
mov    0x2e2b(%rip),%rbx
mov    (%rbx),%edi
call   1070 <getmaxyx@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
mov    (%rbx),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
xor    %eax,%eax
call   10b0 <noecho@plt>
call   *%r14
mov    $0xffffffff,%edi
call   1060 <timeout@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   10a0 <attrset@plt>
lea    0xe04(%rip),%rdx
mov    $0x1,%esi
call   10c0 <mvprintw@plt>
xor    %eax,%eax
call   1080 <getch@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <endwin@plt>

LLVM IR (-O0):
@stdscr = global i32 0
@TRUE = global i32 0
@A_NORMAL = global i32 0
@.str = [17 x i8] c"Press any key...\00"
define void @with_ncurses(void (i32, i32)* %0) {
%2 = alloca void (i32, i32)*
%3 = alloca i32
%4 = alloca i32
store void (i32, i32)* %0, void (i32, i32)** %2
%5 = call i32 (...) @initscr()
%6 = load i32, i32* @stdscr
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = call i32 @getmaxyx(i32 %6, i32 %7, i32 %8)
%10 = call i32 (...) @cbreak()
%11 = load i32, i32* @stdscr
%12 = load i32, i32* @TRUE
%13 = call i32 @keypad(i32 %11, i32 %12)
%14 = call i32 (...) @noecho()
%15 = load void (i32, i32)*, void (i32, i32)** %2
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 @timeout(i32 -1)
%19 = load i32, i32* @A_NORMAL
%20 = call i32 @attrset(i32 %19)
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 2
%23 = call i32 @mvprintw(i32 %22, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%24 = call i32 (...) @getch()
%25 = call i32 (...) @endwin()
ret void
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
@A_NORMAL = global i32 0
@.str = [17 x i8] c"Press any key...\00"
define void @with_ncurses(void (i32, i32)* nocapture %0) {
%2 = tail call i32 (...) @initscr()
%3 = load i32, i32* @stdscr
%4 = tail call i32 @getmaxyx(i32 %3, i32 undef, i32 undef)
%5 = tail call i32 (...) @cbreak()
%6 = load i32, i32* @stdscr
%7 = load i32, i32* @TRUE
%8 = tail call i32 @keypad(i32 %6, i32 %7)
%9 = tail call i32 (...) @noecho()
tail call void %0(i32 undef, i32 undef)
%10 = tail call i32 @timeout(i32 -1)
%11 = load i32, i32* @A_NORMAL
%12 = tail call i32 @attrset(i32 %11)
%13 = tail call i32 @mvprintw(i32 undef, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 (...) @getch()
%15 = tail call i32 (...) @endwin()
ret void
}