#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 */
#define KEY_DOWN 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ clear();
int /*<<< orphan*/ curs_set(int /*<<< orphan*/);
int /*<<< orphan*/ endwin();
int getch();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mvaddch(int, int, char);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int main() {
  int ch;
  int x = 5, y = 5;
  initscr();
  noecho();
  keypad(stdscr, TRUE);
  curs_set(0);
  mvaddch(y, x, 'A');
  while (1) {
    ch = getch();
    clear();
    switch (ch) {
    case KEY_UP:
      y--;
      break;
    case KEY_DOWN:
      y++;
      break;
    case KEY_LEFT:
      x--;
      break;
    case KEY_RIGHT:
      x++;
      break;
    }
    mvaddch(y, x, 'A');
    refresh();
  }
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0xc(%rbp)
movl   $0x5,-0x10(%rbp)
mov    $0x0,%al
call   1040 <initscr@plt>
mov    $0x0,%al
call   1070 <noecho@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
call   1030 <keypad@plt>
xor    %edi,%edi
call   10a0 <curs_set@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x41,%edx
call   1080 <mvaddch@plt>
xor    %eax,%eax
mov    %al,-0x19(%rbp)
call   1060 <getch@plt>
mov    %eax,%ecx
mov    -0x19(%rbp),%al
mov    %ecx,-0x8(%rbp)
call   1090 <clear@plt>
mov    -0x8(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     124c <main+0xcc>
mov    -0x18(%rbp),%rax
lea    0xdf0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    124c <main+0xcc>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    124c <main+0xcc>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    124c <main+0xcc>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x41,%edx
call   1080 <mvaddch@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
jmp    11d9 <main+0x59>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <initscr@plt>
xor    %eax,%eax
call   1070 <noecho@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1030 <keypad@plt>
xor    %edi,%edi
call   10a0 <curs_set@plt>
mov    $0x5,%r14d
mov    $0x5,%edi
mov    $0x5,%esi
mov    $0x41,%edx
call   1080 <mvaddch@plt>
lea    0xe2c(%rip),%r15
mov    $0x5,%ebp
jmp    1206 <main+0x86>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r14d,%esi
mov    $0x41,%edx
call   1080 <mvaddch@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
xor    %eax,%eax
call   1060 <getch@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <clear@plt>
add    $0xffffff80,%ebx
cmp    $0x3,%ebx
ja     11f0 <main+0x70>
movslq (%r15,%rbx,4),%rax
add    %r15,%rax
jmp    *%rax
add    $0xffffffff,%ebp
jmp    11f0 <main+0x70>
nopl   0x0(%rax)
add    $0xffffffff,%r14d
jmp    11f0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
jmp    11f0 <main+0x70>

LLVM IR (-O0):
@stdscr = global i32 0
@TRUE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %3
store i32 5, i32* %4
%5 = call i32 (...) @initscr()
%6 = call i32 (...) @noecho()
%7 = load i32, i32* @stdscr
%8 = load i32, i32* @TRUE
%9 = call i32 @keypad(i32 %7, i32 %8)
%10 = call i32 @curs_set(i32 0)
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = call i32 @mvaddch(i32 %11, i32 %12, i8 signext 65)
br label %14
14: ; preds = %0, %30
%15 = call i32 (...) @getch()
store i32 %15, i32* %2
%16 = call i32 (...) @clear()
%17 = load i32, i32* %2
switch i32 %17, label %30 [
i32 128, label %18
i32 131, label %21
i32 130, label %24
i32 129, label %27
]
18: ; preds = %14
%19 = load i32, i32* %4
%20 = add nsw i32 %19, -1
store i32 %20, i32* %4
br label %30
21: ; preds = %14
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %30
24: ; preds = %14
%25 = load i32, i32* %3
%26 = add nsw i32 %25, -1
store i32 %26, i32* %3
br label %30
27: ; preds = %14
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %30
30: ; preds = %14, %27, %24, %21, %18
%31 = load i32, i32* %4
%32 = load i32, i32* %3
%33 = call i32 @mvaddch(i32 %31, i32 %32, i8 signext 65)
%34 = call i32 (...) @refresh()
br label %14
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @initscr()
%2 = tail call i32 (...) @noecho()
%3 = load i32, i32* @stdscr
%4 = load i32, i32* @TRUE
%5 = tail call i32 @keypad(i32 %3, i32 %4)
%6 = tail call i32 @curs_set(i32 0)
%7 = tail call i32 @mvaddch(i32 5, i32 5, i8 signext 65)
br label %8
8: ; preds = %21, %0
%9 = phi i32 [ 5, %0 ], [ %22, %21 ]
%10 = phi i32 [ 5, %0 ], [ %23, %21 ]
%11 = tail call i32 (...) @getch()
%12 = tail call i32 (...) @clear()
switch i32 %11, label %21 [
i32 128, label %13
i32 131, label %15
i32 130, label %17
i32 129, label %19
]
13: ; preds = %8
%14 = add nsw i32 %10, -1
br label %21
15: ; preds = %8
%16 = add nsw i32 %10, 1
br label %21
17: ; preds = %8
%18 = add nsw i32 %9, -1
br label %21
19: ; preds = %8
%20 = add nsw i32 %9, 1
br label %21
21: ; preds = %8, %19, %17, %15, %13
%22 = phi i32 [ %9, %8 ], [ %20, %19 ], [ %18, %17 ], [ %9, %15 ], [ %9, %13 ]
%23 = phi i32 [ %10, %8 ], [ %10, %19 ], [ %10, %17 ], [ %16, %15 ], [ %14, %13 ]
%24 = tail call i32 @mvaddch(i32 %23, i32 %22, i8 signext 65)
%25 = tail call i32 (...) @refresh()
br label %8
}