#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 uint8_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ clear();
int /*<<< orphan*/ drawMap();
int /*<<< orphan*/ drawstackDraw();
int /*<<< orphan*/ getPlayerPos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ getch();
scalar_t__ mapCount(int);
int /*<<< orphan*/ moveTile(int /*<<< orphan*/, int /*<<< orphan*/, int, int);
int tolower(int /*<<< orphan*/);
uint16_t gameloop() {
  uint8_t over = 0;
  uint16_t px, py, cnt = 0;
  clear();
  drawMap();
  while (!over) {
    getPlayerPos(&px, &py);
    drawstackDraw();
    if (mapCount(3) == 0)
      return cnt;
    switch (tolower(getch())) {
    case 'a':
      cnt += moveTile(px, py, -1, 0);
      break;
    case 'd':
      cnt += moveTile(px, py, 1, 0);
      break;
    case 'w':
      cnt += moveTile(px, py, 0, -1);
      break;
    case 's':
      cnt += moveTile(px, py, 0, 1);
      break;
    case 'q':
      over = 1;
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<gameloop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   10a0 <clear@plt>
mov    $0x0,%al
call   1080 <drawMap@plt>
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ba <gameloop+0x3a>
jmp    12a1 <gameloop+0x121>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1090 <getPlayerPos@plt>
mov    $0x0,%al
call   1040 <drawstackDraw@plt>
mov    $0x3,%edi
call   1030 <mapCount@plt>
cmp    $0x0,%rax
jne    11ed <gameloop+0x6d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a8 <gameloop+0x128>
xor    %eax,%eax
call   1070 <getch@plt>
mov    %eax,%edi
call   1060 <tolower@plt>
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x16,%eax
ja     129c <gameloop+0x11c>
mov    -0x20(%rbp),%rax
lea    0xde8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1050 <moveTile@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    129c <gameloop+0x11c>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1050 <moveTile@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    129c <gameloop+0x11c>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
xor    %edx,%edx
mov    $0xffffffff,%ecx
call   1050 <moveTile@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    129c <gameloop+0x11c>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1050 <moveTile@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    129c <gameloop+0x11c>
movl   $0x1,-0x8(%rbp)
jmp    11a4 <gameloop+0x24>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gameloop>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <clear@plt>
xor    %eax,%eax
call   1080 <drawMap@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1090 <getPlayerPos@plt>
xor    %eax,%eax
call   1040 <drawstackDraw@plt>
mov    $0x3,%edi
call   1030 <mapCount@plt>
test   %rax,%rax
je     1284 <gameloop+0x104>
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0xe2a(%rip),%r12
xor    %ebx,%ebx
jmp    1219 <gameloop+0x99>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1050 <moveTile@plt>
add    %eax,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <getPlayerPos@plt>
xor    %eax,%eax
call   1040 <drawstackDraw@plt>
mov    $0x3,%edi
call   1030 <mapCount@plt>
mov    %ebx,%ebp
test   %rax,%rax
je     1284 <gameloop+0x104>
xor    %eax,%eax
call   1070 <getch@plt>
mov    %eax,%edi
call   1060 <tolower@plt>
add    $0xffffff9f,%eax
cmp    $0x16,%eax
ja     11f6 <gameloop+0x76>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
xor    %ebp,%ebp
jmp    *%rax
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
jmp    11ef <gameloop+0x6f>
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    $0x1,%edx
xor    %ecx,%ecx
jmp    11ef <gameloop+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
xor    %edx,%edx
mov    $0xffffffff,%ecx
jmp    11ef <gameloop+0x6f>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gameloop() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %5
%6 = call i32 (...) @clear()
%7 = call i32 (...) @drawMap()
br label %8
8: ; preds = %47, %0
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %48
12: ; preds = %8
%13 = call i32 @getPlayerPos(i32* %3, i32* %4)
%14 = call i32 (...) @drawstackDraw()
%15 = call i64 @mapCount(i32 3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i32, i32* %5
store i32 %18, i32* %1
br label %49
19: ; preds = %12
%20 = call i32 (...) @getch()
%21 = call i32 @tolower(i32 %20)
switch i32 %21, label %47 [
i32 97, label %22
i32 100, label %28
i32 119, label %34
i32 115, label %40
i32 113, label %46
]
22: ; preds = %19
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i32 @moveTile(i32 %23, i32 %24, i32 -1, i32 0)
%26 = load i32, i32* %5
%27 = add nsw i32 %26, %25
store i32 %27, i32* %5
br label %47
28: ; preds = %19
%29 = load i32, i32* %3
%30 = load i32, i32* %4
%31 = call i32 @moveTile(i32 %29, i32 %30, i32 1, i32 0)
%32 = load i32, i32* %5
%33 = add nsw i32 %32, %31
store i32 %33, i32* %5
br label %47
34: ; preds = %19
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = call i32 @moveTile(i32 %35, i32 %36, i32 0, i32 -1)
%38 = load i32, i32* %5
%39 = add nsw i32 %38, %37
store i32 %39, i32* %5
br label %47
40: ; preds = %19
%41 = load i32, i32* %3
%42 = load i32, i32* %4
%43 = call i32 @moveTile(i32 %41, i32 %42, i32 0, i32 1)
%44 = load i32, i32* %5
%45 = add nsw i32 %44, %43
store i32 %45, i32* %5
br label %47
46: ; preds = %19
store i32 1, i32* %2
br label %47
47: ; preds = %19, %46, %40, %34, %28, %22
br label %8
48: ; preds = %8
store i32 0, i32* %1
br label %49
49: ; preds = %48, %17
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
define i32 @gameloop() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (...) @clear()
%6 = tail call i32 (...) @drawMap()
%7 = call i32 @getPlayerPos(i32* %1, i32* %2)
%8 = call i32 (...) @drawstackDraw()
%9 = call i64 @mapCount(i32 3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %41, label %11
11: ; preds = %0, %35
%12 = phi i32 [ %36, %35 ], [ 0, %0 ]
%13 = call i32 (...) @getch()
%14 = call i32 @tolower(i32 %13)
switch i32 %14, label %35 [
i32 97, label %15
i32 100, label %20
i32 119, label %25
i32 115, label %30
i32 113, label %41
]
15: ; preds = %11
%16 = load i32, i32* %1
%17 = load i32, i32* %2
%18 = call i32 @moveTile(i32 %16, i32 %17, i32 -1, i32 0)
%19 = add nsw i32 %18, %12
br label %35
20: ; preds = %11
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = call i32 @moveTile(i32 %21, i32 %22, i32 1, i32 0)
%24 = add nsw i32 %23, %12
br label %35
25: ; preds = %11
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call i32 @moveTile(i32 %26, i32 %27, i32 0, i32 -1)
%29 = add nsw i32 %28, %12
br label %35
30: ; preds = %11
%31 = load i32, i32* %1
%32 = load i32, i32* %2
%33 = call i32 @moveTile(i32 %31, i32 %32, i32 0, i32 1)
%34 = add nsw i32 %33, %12
br label %35
35: ; preds = %11, %30, %25, %20, %15
%36 = phi i32 [ %12, %11 ], [ %34, %30 ], [ %29, %25 ], [ %24, %20 ], [ %19, %15 ]
%37 = call i32 @getPlayerPos(i32* %1, i32* %2)
%38 = call i32 (...) @drawstackDraw()
%39 = call i64 @mapCount(i32 3)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %11
41: ; preds = %35, %11, %0
%42 = phi i32 [ 0, %0 ], [ %36, %35 ], [ 0, %11 ]
ret i32 %42
}