#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*/ endwin();
char getch();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ raw();
int /*<<< orphan*/ stdscr;
int main(int argc, char **argv) {
  initscr();
  raw();
  noecho();
  int row, col;
  getmaxyx(stdscr, row, col);
  int x = 0, y = 0;
  bool run = true;
  while (run) {
    char c = getch();
    switch (c) {
    case 'w':
      if (x > 0)
        x--;
      break;
    case 's':
      if (x < (row - 1))
        x++;
      break;
    case 'a':
      if (y > 0)
        y--;
      break;
    case 'd':
      if (y < (col - 1))
        y++;
      break;
    case 'x':
      run = false;
      break;
    }
    move(x, y);
  }
  endwin();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <initscr@plt>
mov    $0x0,%al
call   1040 <raw@plt>
mov    $0x0,%al
call   1080 <noecho@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <getmaxyx@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1287 <main+0x117>
xor    %eax,%eax
call   1060 <getch@plt>
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x17,%eax
ja     1277 <main+0x107>
mov    -0x30(%rbp),%rax
lea    0xe07(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x1c(%rbp)
jle    1215 <main+0xa5>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1277 <main+0x107>
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1234 <main+0xc4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1277 <main+0x107>
cmpl   $0x0,-0x20(%rbp)
jle    124c <main+0xdc>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1277 <main+0x107>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    126b <main+0xfb>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1277 <main+0x107>
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1090 <move@plt>
jmp    11c4 <main+0x54>
mov    $0x0,%al
call   1070 <endwin@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <initscr@plt>
xor    %eax,%eax
call   1040 <raw@plt>
xor    %eax,%eax
call   1080 <noecho@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1050 <getmaxyx@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <getch@plt>
mov    %eax,%ebx
xor    %edi,%edi
xor    %esi,%esi
call   1090 <move@plt>
cmp    $0x78,%bl
jne    11a0 <main+0x30>
xor    %eax,%eax
call   1070 <endwin@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdscr = global i32 0
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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (...) @initscr()
%13 = call i32 (...) @raw()
%14 = call i32 (...) @noecho()
%15 = load i32, i32* @stdscr
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = call i32 @getmaxyx(i32 %15, i32 %16, i32 %17)
store i32 0, i32* %8
store i32 0, i32* %9
store i32 1, i32* %10
br label %19
19: ; preds = %59, %2
%20 = load i32, i32* %10
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %63
22: ; preds = %19
%23 = call signext i8 (...) @getch()
store i8 %23, i8* %11
%24 = load i8, i8* %11
%25 = sext i8 %24 to i32
switch i32 %25, label %59 [
i32 119, label %26
i32 115, label %33
i32 97, label %42
i32 100, label %49
i32 120, label %58
]
26: ; preds = %22
%27 = load i32, i32* %8
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %8
%31 = add nsw i32 %30, -1
store i32 %31, i32* %8
br label %32
32: ; preds = %29, %26
br label %59
33: ; preds = %22
%34 = load i32, i32* %8
%35 = load i32, i32* %6
%36 = sub nsw i32 %35, 1
%37 = icmp slt i32 %34, %36
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %41
41: ; preds = %38, %33
br label %59
42: ; preds = %22
%43 = load i32, i32* %9
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* %9
%47 = add nsw i32 %46, -1
store i32 %47, i32* %9
br label %48
48: ; preds = %45, %42
br label %59
49: ; preds = %22
%50 = load i32, i32* %9
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, 1
%53 = icmp slt i32 %50, %52
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %57
57: ; preds = %54, %49
br label %59
58: ; preds = %22
store i32 0, i32* %10
br label %59
59: ; preds = %22, %58, %57, %48, %41, %32
%60 = load i32, i32* %8
%61 = load i32, i32* %9
%62 = call i32 @move(i32 %60, i32 %61)
br label %19
63: ; preds = %19
%64 = call i32 (...) @endwin()
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@stdscr = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @initscr()
%4 = tail call i32 (...) @raw()
%5 = tail call i32 (...) @noecho()
%6 = load i32, i32* @stdscr
%7 = tail call i32 @getmaxyx(i32 %6, i32 undef, i32 undef)
br label %8
8: ; preds = %2, %8
%9 = tail call signext i8 (...) @getch()
%10 = icmp eq i8 %9, 120
%11 = tail call i32 @move(i32 0, i32 0)
br i1 %10, label %12, label %8
12: ; preds = %8
%13 = tail call i32 (...) @endwin()
ret i32 0
}