#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 /*<<< orphan*/ WINDOW;

/* Variables and functions */
int COLS;
#define KEY_DOWN 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int LINES;
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ *create_new_win(int, int, int, int);
int /*<<< orphan*/ destroy_win(int /*<<< orphan*/ *);
int /*<<< orphan*/ endwin();
int getch();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printw(char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int main() {
  initscr();
  cbreak();
  noecho();
  keypad(stdscr, TRUE);
  int height = 5;
  int width = 10;
  int starty = (LINES - height) / 2;
  int startx = (COLS - width) / 2;
  printw("Press q to exit");
  refresh();
  WINDOW *my_win = create_new_win(height, width, starty, startx);
  int ch;
  while ((ch = getch()) != 'q') {
    switch (ch) {
    case KEY_LEFT:
      destroy_win(my_win);
      my_win = create_new_win(height, width, starty, --startx);
      break;
    case KEY_RIGHT:
      destroy_win(my_win);
      my_win = create_new_win(height, width, starty, ++startx);
      break;
    case KEY_UP:
      destroy_win(my_win);
      my_win = create_new_win(height, width, --starty, startx);
      break;
    case KEY_DOWN:
      destroy_win(my_win);
      my_win = create_new_win(height, width, ++starty, startx);
      break;
    }
  }
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <initscr@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    $0x0,%al
call   10b0 <noecho@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
movl   $0x5,-0x8(%rbp)
movl   $0xa,-0xc(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
sub    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
lea    0xdf2(%rip),%rdi
call   1070 <printw@plt>
mov    $0x0,%al
call   1080 <refresh@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1060 <create_new_win@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1090 <getch@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x71,%eax
je     131f <main+0x17f>
mov    -0x24(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     131a <main+0x17a>
mov    -0x30(%rbp),%rax
lea    0xd8e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rdi
call   10c0 <destroy_win@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
call   1060 <create_new_win@plt>
mov    %rax,-0x20(%rbp)
jmp    131a <main+0x17a>
mov    -0x20(%rbp),%rdi
call   10c0 <destroy_win@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
call   1060 <create_new_win@plt>
mov    %rax,-0x20(%rbp)
jmp    131a <main+0x17a>
mov    -0x20(%rbp),%rdi
call   10c0 <destroy_win@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
call   1060 <create_new_win@plt>
mov    %rax,-0x20(%rbp)
jmp    131a <main+0x17a>
mov    -0x20(%rbp),%rdi
call   10c0 <destroy_win@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
call   1060 <create_new_win@plt>
mov    %rax,-0x20(%rbp)
jmp    123f <main+0x9f>
mov    $0x0,%al
call   10a0 <endwin@plt>
xor    %eax,%eax
add    $0x30,%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   1030 <cbreak@plt>
xor    %eax,%eax
call   10b0 <noecho@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
add    $0xfffffffb,%ecx
shr    $0x1f,%ecx
lea    (%rax,%rcx,1),%r14d
add    $0xfffffffb,%r14d
sar    %r14d
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
add    $0xfffffff6,%ecx
shr    $0x1f,%ecx
lea    (%rax,%rcx,1),%r15d
add    $0xfffffff6,%r15d
sar    %r15d
lea    0xe3a(%rip),%rdi
call   1070 <printw@plt>
xor    %eax,%eax
call   1080 <refresh@plt>
mov    $0x5,%edi
mov    $0xa,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   1060 <create_new_win@plt>
mov    %rax,%rbx
lea    0xdc3(%rip),%rbp
jmp    1270 <main+0xd0>
mov    %rbx,%rdi
call   10c0 <destroy_win@plt>
add    $0xffffffff,%r15d
mov    $0x5,%edi
mov    $0xa,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   1060 <create_new_win@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1090 <getch@plt>
add    $0xffffff8f,%eax
cmp    $0x12,%eax
ja     1270 <main+0xd0>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    %rbx,%rdi
call   10c0 <destroy_win@plt>
add    $0xffffffff,%r14d
jmp    124b <main+0xab>
mov    %rbx,%rdi
call   10c0 <destroy_win@plt>
add    $0x1,%r15d
jmp    124b <main+0xab>
mov    %rbx,%rdi
call   10c0 <destroy_win@plt>
add    $0x1,%r14d
jmp    124b <main+0xab>
xor    %eax,%eax
call   10a0 <endwin@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdscr = global i32 0
@TRUE = global i32 0
@LINES = global i32 0
@COLS = global i32 0
@.str = [16 x i8] c"Press q to exit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (...) @initscr()
%9 = call i32 (...) @cbreak()
%10 = call i32 (...) @noecho()
%11 = load i32, i32* @stdscr
%12 = load i32, i32* @TRUE
%13 = call i32 @keypad(i32 %11, i32 %12)
store i32 5, i32* %2
store i32 10, i32* %3
%14 = load i32, i32* @LINES
%15 = load i32, i32* %2
%16 = sub nsw i32 %14, %15
%17 = sdiv i32 %16, 2
store i32 %17, i32* %4
%18 = load i32, i32* @COLS
%19 = load i32, i32* %3
%20 = sub nsw i32 %18, %19
%21 = sdiv i32 %20, 2
store i32 %21, i32* %5
%22 = call i32 @printw(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%23 = call i32 (...) @refresh()
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = call i32* @create_new_win(i32 %24, i32 %25, i32 %26, i32 %27)
store i32* %28, i32** %6
br label %29
29: ; preds = %70, %0
%30 = call i32 (...) @getch()
store i32 %30, i32* %7
%31 = icmp ne i32 %30, 113
br i1 %31, label %32, label %71
32: ; preds = %29
%33 = load i32, i32* %7
switch i32 %33, label %70 [
i32 130, label %34
i32 129, label %43
i32 128, label %52
i32 131, label %61
]
34: ; preds = %32
%35 = load i32*, i32** %6
%36 = call i32 @destroy_win(i32* %35)
%37 = load i32, i32* %2
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = add nsw i32 %40, -1
store i32 %41, i32* %5
%42 = call i32* @create_new_win(i32 %37, i32 %38, i32 %39, i32 %41)
store i32* %42, i32** %6
br label %70
43: ; preds = %32
%44 = load i32*, i32** %6
%45 = call i32 @destroy_win(i32* %44)
%46 = load i32, i32* %2
%47 = load i32, i32* %3
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
%51 = call i32* @create_new_win(i32 %46, i32 %47, i32 %48, i32 %50)
store i32* %51, i32** %6
br label %70
52: ; preds = %32
%53 = load i32*, i32** %6
%54 = call i32 @destroy_win(i32* %53)
%55 = load i32, i32* %2
%56 = load i32, i32* %3
%57 = load i32, i32* %4
%58 = add nsw i32 %57, -1
store i32 %58, i32* %4
%59 = load i32, i32* %5
%60 = call i32* @create_new_win(i32 %55, i32 %56, i32 %58, i32 %59)
store i32* %60, i32** %6
br label %70
61: ; preds = %32
%62 = load i32*, i32** %6
%63 = call i32 @destroy_win(i32* %62)
%64 = load i32, i32* %2
%65 = load i32, i32* %3
%66 = load i32, i32* %4
%67 = add nsw i32 %66, 1
store i32 %67, i32* %4
%68 = load i32, i32* %5
%69 = call i32* @create_new_win(i32 %64, i32 %65, i32 %67, i32 %68)
store i32* %69, i32** %6
br label %70
70: ; preds = %32, %61, %52, %43, %34
br label %29
71: ; preds = %29
%72 = call i32 (...) @endwin()
ret i32 0
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
@LINES = global i32 0
@COLS = global i32 0
@.str = [16 x i8] c"Press q to exit\00"
define i32 @main() {
%1 = tail call i32 (...) @initscr()
%2 = tail call i32 (...) @cbreak()
%3 = tail call i32 (...) @noecho()
%4 = load i32, i32* @stdscr
%5 = load i32, i32* @TRUE
%6 = tail call i32 @keypad(i32 %4, i32 %5)
%7 = load i32, i32* @LINES
%8 = add nsw i32 %7, -5
%9 = sdiv i32 %8, 2
%10 = load i32, i32* @COLS
%11 = add nsw i32 %10, -10
%12 = sdiv i32 %11, 2
%13 = tail call i32 @printw(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 (...) @refresh()
%15 = tail call i32* @create_new_win(i32 5, i32 10, i32 %9, i32 %12)
br label %16
16: ; preds = %33, %0
%17 = phi i32 [ %12, %0 ], [ %34, %33 ]
%18 = phi i32* [ %15, %0 ], [ %35, %33 ]
%19 = phi i32 [ %9, %0 ], [ %22, %33 ]
br label %20
20: ; preds = %44, %16
%21 = phi i32* [ %18, %16 ], [ %45, %44 ]
%22 = phi i32 [ %19, %16 ], [ %46, %44 ]
br label %23
23: ; preds = %20, %23
%24 = tail call i32 (...) @getch()
switch i32 %24, label %23 [
i32 113, label %47
i32 130, label %25
i32 129, label %29
i32 128, label %36
i32 131, label %40
]
25: ; preds = %23
%26 = tail call i32 @destroy_win(i32* %21)
%27 = add nsw i32 %17, -1
%28 = tail call i32* @create_new_win(i32 5, i32 10, i32 %22, i32 %27)
br label %33
29: ; preds = %23
%30 = tail call i32 @destroy_win(i32* %21)
%31 = add nsw i32 %17, 1
%32 = tail call i32* @create_new_win(i32 5, i32 10, i32 %22, i32 %31)
br label %33
33: ; preds = %29, %25
%34 = phi i32 [ %27, %25 ], [ %31, %29 ]
%35 = phi i32* [ %28, %25 ], [ %32, %29 ]
br label %16
36: ; preds = %23
%37 = tail call i32 @destroy_win(i32* %21)
%38 = add nsw i32 %22, -1
%39 = tail call i32* @create_new_win(i32 5, i32 10, i32 %38, i32 %17)
br label %44
40: ; preds = %23
%41 = tail call i32 @destroy_win(i32* %21)
%42 = add nsw i32 %22, 1
%43 = tail call i32* @create_new_win(i32 5, i32 10, i32 %42, i32 %17)
br label %44
44: ; preds = %40, %36
%45 = phi i32* [ %39, %36 ], [ %43, %40 ]
%46 = phi i32 [ %38, %36 ], [ %42, %40 ]
br label %20
47: ; preds = %23
%48 = tail call i32 (...) @endwin()
ret i32 0
}