#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 A_BOLD;
int /*<<< orphan*/ COLOR_BLACK;
int /*<<< orphan*/ COLOR_GREEN;
int COLOR_PAIR(int);
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*/ attron(int);
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ *create_newwin(int, int, int, int);
int /*<<< orphan*/ destroy_win(int /*<<< orphan*/ *);
int /*<<< orphan*/ endwin();
int getch();
int /*<<< orphan*/ init_pair(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printw(char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stdscr;
int main() {
  WINDOW *my_win;
  int startx, starty, width, height;
  int ch;
  initscr();
  start_color();
  cbreak();
  keypad(stdscr, TRUE);
  height = 3;
  width = 10;
  init_pair(1, COLOR_GREEN, COLOR_BLACK);
  attron(A_BOLD | COLOR_PAIR(1));
  starty = (LINES - height) / 2;
  startx = (COLS - width) / 2;
  printw("Press F1 to exit");
  refresh();
  my_win = create_newwin(height, width, starty, startx);
  while ((ch = getch()) != 'x') {
    switch (ch) {
    case KEY_LEFT:
      destroy_win(my_win);
      my_win = create_newwin(height, width, starty, --startx);
      break;
    case KEY_RIGHT:
      destroy_win(my_win);
      my_win = create_newwin(height, width, starty, ++startx);
      break;
    case KEY_UP:
      destroy_win(my_win);
      my_win = create_newwin(height, width, --starty, startx);
      break;
    case KEY_DOWN:
      destroy_win(my_win);
      my_win = create_newwin(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   1060 <initscr@plt>
mov    $0x0,%al
call   1070 <start_color@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
call   1050 <keypad@plt>
movl   $0x3,-0x20(%rbp)
movl   $0xa,-0x1c(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x1,%edi
call   10a0 <COLOR_PAIR@plt>
mov    -0x28(%rbp),%edi
or     %eax,%edi
call   1080 <attron@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
sub    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
sub    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
lea    0xd86(%rip),%rdi
call   1090 <printw@plt>
mov    $0x0,%al
call   10b0 <refresh@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   10f0 <create_newwin@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <getch@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x78,%eax
je     138b <main+0x1bb>
mov    -0x24(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     1386 <main+0x1b6>
mov    -0x30(%rbp),%rax
lea    0xd22(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
call   10e0 <destroy_win@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
call   10f0 <create_newwin@plt>
mov    %rax,-0x10(%rbp)
jmp    1386 <main+0x1b6>
mov    -0x10(%rbp),%rdi
call   10e0 <destroy_win@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
call   10f0 <create_newwin@plt>
mov    %rax,-0x10(%rbp)
jmp    1386 <main+0x1b6>
mov    -0x10(%rbp),%rdi
call   10e0 <destroy_win@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
call   10f0 <create_newwin@plt>
mov    %rax,-0x10(%rbp)
jmp    1386 <main+0x1b6>
mov    -0x10(%rbp),%rdi
call   10e0 <destroy_win@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
call   10f0 <create_newwin@plt>
mov    %rax,-0x10(%rbp)
jmp    12ab <main+0xdb>
mov    $0x0,%al
call   10d0 <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   1060 <initscr@plt>
xor    %eax,%eax
call   1070 <start_color@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
call   1050 <keypad@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%ebx
mov    $0x1,%edi
call   10a0 <COLOR_PAIR@plt>
or     %eax,%ebx
mov    %ebx,%edi
call   1080 <attron@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
add    $0xfffffffd,%ecx
shr    $0x1f,%ecx
lea    (%rax,%rcx,1),%r14d
add    $0xfffffffd,%r14d
sar    %r14d
mov    0x2d62(%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    0xdb6(%rip),%rdi
call   1090 <printw@plt>
xor    %eax,%eax
call   10b0 <refresh@plt>
mov    $0x3,%edi
mov    $0xa,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   10f0 <create_newwin@plt>
mov    %rax,%rbx
lea    0xd5b(%rip),%rbp
jmp    12d0 <main+0x100>
mov    %rbx,%rdi
call   10e0 <destroy_win@plt>
add    $0xffffffff,%r15d
mov    $0x3,%edi
mov    $0xa,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   10f0 <create_newwin@plt>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10c0 <getch@plt>
add    $0xffffff88,%eax
cmp    $0xb,%eax
ja     12d0 <main+0x100>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    %rbx,%rdi
call   10e0 <destroy_win@plt>
add    $0xffffffff,%r14d
jmp    12b3 <main+0xe3>
mov    %rbx,%rdi
call   10e0 <destroy_win@plt>
add    $0x1,%r15d
jmp    12b3 <main+0xe3>
mov    %rbx,%rdi
call   10e0 <destroy_win@plt>
add    $0x1,%r14d
jmp    12b3 <main+0xe3>
xor    %eax,%eax
call   10d0 <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
@COLOR_GREEN = global i32 0
@COLOR_BLACK = global i32 0
@A_BOLD = global i32 0
@LINES = global i32 0
@COLS = global i32 0
@.str = [17 x i8] c"Press F1 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 (...) @start_color()
%10 = call i32 (...) @cbreak()
%11 = load i32, i32* @stdscr
%12 = load i32, i32* @TRUE
%13 = call i32 @keypad(i32 %11, i32 %12)
store i32 3, i32* %6
store i32 10, i32* %5
%14 = load i32, i32* @COLOR_GREEN
%15 = load i32, i32* @COLOR_BLACK
%16 = call i32 @init_pair(i32 1, i32 %14, i32 %15)
%17 = load i32, i32* @A_BOLD
%18 = call i32 @COLOR_PAIR(i32 1)
%19 = or i32 %17, %18
%20 = call i32 @attron(i32 %19)
%21 = load i32, i32* @LINES
%22 = load i32, i32* %6
%23 = sub nsw i32 %21, %22
%24 = sdiv i32 %23, 2
store i32 %24, i32* %4
%25 = load i32, i32* @COLS
%26 = load i32, i32* %5
%27 = sub nsw i32 %25, %26
%28 = sdiv i32 %27, 2
store i32 %28, i32* %3
%29 = call i32 @printw(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%30 = call i32 (...) @refresh()
%31 = load i32, i32* %6
%32 = load i32, i32* %5
%33 = load i32, i32* %4
%34 = load i32, i32* %3
%35 = call i32* @create_newwin(i32 %31, i32 %32, i32 %33, i32 %34)
store i32* %35, i32** %2
br label %36
36: ; preds = %77, %0
%37 = call i32 (...) @getch()
store i32 %37, i32* %7
%38 = icmp ne i32 %37, 120
br i1 %38, label %39, label %78
39: ; preds = %36
%40 = load i32, i32* %7
switch i32 %40, label %77 [
i32 130, label %41
i32 129, label %50
i32 128, label %59
i32 131, label %68
]
41: ; preds = %39
%42 = load i32*, i32** %2
%43 = call i32 @destroy_win(i32* %42)
%44 = load i32, i32* %6
%45 = load i32, i32* %5
%46 = load i32, i32* %4
%47 = load i32, i32* %3
%48 = add nsw i32 %47, -1
store i32 %48, i32* %3
%49 = call i32* @create_newwin(i32 %44, i32 %45, i32 %46, i32 %48)
store i32* %49, i32** %2
br label %77
50: ; preds = %39
%51 = load i32*, i32** %2
%52 = call i32 @destroy_win(i32* %51)
%53 = load i32, i32* %6
%54 = load i32, i32* %5
%55 = load i32, i32* %4
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
%58 = call i32* @create_newwin(i32 %53, i32 %54, i32 %55, i32 %57)
store i32* %58, i32** %2
br label %77
59: ; preds = %39
%60 = load i32*, i32** %2
%61 = call i32 @destroy_win(i32* %60)
%62 = load i32, i32* %6
%63 = load i32, i32* %5
%64 = load i32, i32* %4
%65 = add nsw i32 %64, -1
store i32 %65, i32* %4
%66 = load i32, i32* %3
%67 = call i32* @create_newwin(i32 %62, i32 %63, i32 %65, i32 %66)
store i32* %67, i32** %2
br label %77
68: ; preds = %39
%69 = load i32*, i32** %2
%70 = call i32 @destroy_win(i32* %69)
%71 = load i32, i32* %6
%72 = load i32, i32* %5
%73 = load i32, i32* %4
%74 = add nsw i32 %73, 1
store i32 %74, i32* %4
%75 = load i32, i32* %3
%76 = call i32* @create_newwin(i32 %71, i32 %72, i32 %74, i32 %75)
store i32* %76, i32** %2
br label %77
77: ; preds = %39, %68, %59, %50, %41
br label %36
78: ; preds = %36
%79 = call i32 (...) @endwin()
ret i32 0
}

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