#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
int KEY_F(int);
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int LINES;
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ *create_newwin(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*/ printw(char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int main(int argc, char *argv[]) {
  WINDOW *my_win;
  int startx, starty, width, height;
  int ch;
  initscr();
  cbreak();
  keypad(stdscr, TRUE);
  height = 3;
  width = 10;
  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()) != KEY_F(1)) {
    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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <initscr@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
movl   $0x3,-0x28(%rbp)
movl   $0xa,-0x24(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
sub    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
sub    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
lea    0xdf2(%rip),%rdi
call   1070 <printw@plt>
mov    $0x0,%al
call   1080 <refresh@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   10c0 <create_newwin@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1090 <getch@plt>
mov    %eax,-0x30(%rbp)
mov    %eax,-0x2c(%rbp)
mov    $0x1,%edi
call   1060 <KEY_F@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
je     1330 <main+0x190>
mov    -0x2c(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x3,%eax
ja     132b <main+0x18b>
mov    -0x38(%rbp),%rax
lea    0xd7d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
call   10b0 <destroy_win@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
call   10c0 <create_newwin@plt>
mov    %rax,-0x18(%rbp)
jmp    132b <main+0x18b>
mov    -0x18(%rbp),%rdi
call   10b0 <destroy_win@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
call   10c0 <create_newwin@plt>
mov    %rax,-0x18(%rbp)
jmp    132b <main+0x18b>
mov    -0x18(%rbp),%rdi
call   10b0 <destroy_win@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
call   10c0 <create_newwin@plt>
mov    %rax,-0x18(%rbp)
jmp    132b <main+0x18b>
mov    -0x18(%rbp),%rdi
call   10b0 <destroy_win@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
call   10c0 <create_newwin@plt>
mov    %rax,-0x18(%rbp)
jmp    123f <main+0x9f>
mov    $0x0,%al
call   10a0 <endwin@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1050 <initscr@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   1040 <keypad@plt>
mov    0x2e14(%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    0x2de0(%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    0xe04(%rip),%rdi
call   1070 <printw@plt>
xor    %eax,%eax
call   1080 <refresh@plt>
mov    $0x3,%edi
mov    $0xa,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   10c0 <create_newwin@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <getch@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   1060 <KEY_F@plt>
cmp    %eax,%ebp
jne    1259 <main+0xb9>
xor    %eax,%eax
call   10a0 <endwin@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda0(%rip),%r12
jmp    12ab <main+0x10b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   10b0 <destroy_win@plt>
add    $0x1,%r14d
mov    $0x3,%edi
mov    $0xa,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   10c0 <create_newwin@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <getch@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   1060 <KEY_F@plt>
cmp    %eax,%ebp
je     1247 <main+0xa7>
add    $0xffffff80,%ebp
cmp    $0x3,%ebp
ja     1294 <main+0xf4>
movslq (%r12,%rbp,4),%rax
add    %r12,%rax
jmp    *%rax
mov    %rbx,%rdi
call   10b0 <destroy_win@plt>
add    $0xffffffff,%r14d
jmp    127c <main+0xdc>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10b0 <destroy_win@plt>
add    $0x1,%r15d
jmp    127c <main+0xdc>
xchg   %ax,%ax
mov    %rbx,%rdi
call   10b0 <destroy_win@plt>
add    $0xffffffff,%r15d
jmp    127c <main+0xdc>

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