#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*/ InitTiles();
int /*<<< orphan*/ MergeDown();
int /*<<< orphan*/ MergeLeft();
int /*<<< orphan*/ MergeRight();
int /*<<< orphan*/ MergeUp();
int /*<<< orphan*/ NextStep();
int /*<<< orphan*/ PrintTiles();
int /*<<< orphan*/ ShiftDown();
int /*<<< orphan*/ ShiftLeft();
int /*<<< orphan*/ ShiftRight();
int /*<<< orphan*/ ShiftUp();
int /*<<< orphan*/ clear();
char getch();
scalar_t__ isSpaceAvailable();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ refresh();
void PlayGame() {
  char userChoice = 'k';
  printf("Going to start game. Use AD for left, right. WS for up, down.\n");
  printf("k to kill game.\n");
  InitTiles();
  NextStep();
  do {
    if (!NextStep()) {
      break;
    }
    PrintTiles();
    refresh();
    userChoice = getch();
    switch (userChoice) {
    case 'a':
    case 'A':
      MergeLeft();
      ShiftLeft();
      break;
    case 'd':
    case 'D':
      MergeRight();
      ShiftRight();
      break;
    case 'w':
    case 'W':
      MergeUp();
      ShiftUp();
      break;
    case 's':
    case 'S':
      MergeDown();
      ShiftDown();
      break;
    }
    clear();
  } while (isSpaceAvailable() && userChoice != 'k');
  printf("\nGame over.\n");
}


x86 assembly (clang, -O0):
<PlayGame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movb   $0x6b,-0x1(%rbp)
lea    0xec9(%rip),%rdi
call   1070 <printf@plt>
lea    0xefc(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   1110 <InitTiles@plt>
mov    $0x0,%al
call   1060 <NextStep@plt>
mov    $0x0,%al
call   1060 <NextStep@plt>
cmp    $0x0,%eax
jne    1247 <PlayGame+0x47>
jmp    130d <PlayGame+0x10d>
xor    %eax,%eax
mov    %al,-0x11(%rbp)
call   1050 <PrintTiles@plt>
mov    -0x11(%rbp),%al
call   10c0 <refresh@plt>
mov    -0x11(%rbp),%al
call   10d0 <getch@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x36,%eax
ja     12d5 <PlayGame+0xd5>
mov    -0x10(%rbp),%rax
lea    0xd7b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   10f0 <MergeLeft@plt>
mov    $0x0,%al
call   10b0 <ShiftLeft@plt>
jmp    12d5 <PlayGame+0xd5>
mov    $0x0,%al
call   1030 <MergeRight@plt>
mov    $0x0,%al
call   10a0 <ShiftRight@plt>
jmp    12d5 <PlayGame+0xd5>
mov    $0x0,%al
call   1090 <MergeUp@plt>
mov    $0x0,%al
call   10e0 <ShiftUp@plt>
jmp    12d5 <PlayGame+0xd5>
mov    $0x0,%al
call   1080 <MergeDown@plt>
mov    $0x0,%al
call   1100 <ShiftDown@plt>
mov    $0x0,%al
call   1120 <clear@plt>
mov    $0x0,%al
call   1040 <isSpaceAvailable@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x12(%rbp)
je     1302 <PlayGame+0x102>
movsbl -0x1(%rbp),%eax
cmp    $0x6b,%eax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    1232 <PlayGame+0x32>
lea    0xe18(%rip),%rdi
call   1070 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PlayGame>:
push   %r14
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
call   1060 <puts@plt>
lea    0xf03(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1110 <InitTiles@plt>
xor    %eax,%eax
call   1070 <NextStep@plt>
lea    0xdcf(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <NextStep@plt>
test   %eax,%eax
je     12da <PlayGame+0xda>
xor    %eax,%eax
call   1050 <PrintTiles@plt>
xor    %eax,%eax
call   10c0 <refresh@plt>
xor    %eax,%eax
call   10d0 <getch@plt>
mov    %eax,%ebx
movsbl %al,%eax
add    $0xffffffbf,%eax
cmp    $0x36,%eax
ja     12be <PlayGame+0xbe>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
xor    %eax,%eax
call   10f0 <MergeLeft@plt>
xor    %eax,%eax
call   10b0 <ShiftLeft@plt>
jmp    12be <PlayGame+0xbe>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <MergeRight@plt>
xor    %eax,%eax
call   10a0 <ShiftRight@plt>
jmp    12be <PlayGame+0xbe>
xor    %eax,%eax
call   1080 <MergeDown@plt>
xor    %eax,%eax
call   1100 <ShiftDown@plt>
jmp    12be <PlayGame+0xbe>
xor    %eax,%eax
call   1090 <MergeUp@plt>
xor    %eax,%eax
call   10e0 <ShiftUp@plt>
xor    %eax,%eax
call   1120 <clear@plt>
xor    %eax,%eax
call   1040 <isSpaceAvailable@plt>
test   %rax,%rax
je     12da <PlayGame+0xda>
cmp    $0x6b,%bl
jne    1240 <PlayGame+0x40>
lea    0xe49(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <puts@plt>

LLVM IR (-O0):
@.str = [63 x i8] c"Going to start game. Use AD for left, right. WS for up, down.\0A\00"
@.str.1 = [17 x i8] c"k to kill game.\0A\00"
@.str.2 = [13 x i8] c"\0AGame over.\0A\00"
define void @PlayGame() {
%1 = alloca i8
store i8 107, i8* %1
%2 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 (...) @InitTiles()
%5 = call i32 (...) @NextStep()
br label %6
6: ; preds = %37, %0
%7 = call i32 (...) @NextStep()
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %6
br label %39
10: ; preds = %6
%11 = call i32 (...) @PrintTiles()
%12 = call i32 (...) @refresh()
%13 = call signext i8 (...) @getch()
store i8 %13, i8* %1
%14 = load i8, i8* %1
%15 = sext i8 %14 to i32
switch i32 %15, label %28 [
i32 97, label %16
i32 65, label %16
i32 100, label %19
i32 68, label %19
i32 119, label %22
i32 87, label %22
i32 115, label %25
i32 83, label %25
]
16: ; preds = %10, %10
%17 = call i32 (...) @MergeLeft()
%18 = call i32 (...) @ShiftLeft()
br label %28
19: ; preds = %10, %10
%20 = call i32 (...) @MergeRight()
%21 = call i32 (...) @ShiftRight()
br label %28
22: ; preds = %10, %10
%23 = call i32 (...) @MergeUp()
%24 = call i32 (...) @ShiftUp()
br label %28
25: ; preds = %10, %10
%26 = call i32 (...) @MergeDown()
%27 = call i32 (...) @ShiftDown()
br label %28
28: ; preds = %10, %25, %22, %19, %16
%29 = call i32 (...) @clear()
br label %30
30: ; preds = %28
%31 = call i64 (...) @isSpaceAvailable()
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i8, i8* %1
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 107
br label %37
37: ; preds = %33, %30
%38 = phi i1 [ false, %30 ], [ %36, %33 ]
br i1 %38, label %6, label %39
39: ; preds = %37, %9
%40 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@str = [62 x i8] c"Going to start game. Use AD for left, right. WS for up, down.\00"
@str.3 = [16 x i8] c"k to kill game.\00"
@str.4 = [12 x i8] c"\0AGame over.\00"
define void @PlayGame() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.3, i64 0, i64 0))
%3 = tail call i32 (...) @InitTiles()
%4 = tail call i32 (...) @NextStep()
br label %5
5: ; preds = %25, %0
%6 = tail call i32 (...) @NextStep()
%7 = icmp eq i32 %6, 0
br i1 %7, label %31, label %8
8: ; preds = %5
%9 = tail call i32 (...) @PrintTiles()
%10 = tail call i32 (...) @refresh()
%11 = tail call signext i8 (...) @getch()
%12 = sext i8 %11 to i32
switch i32 %12, label %25 [
i32 97, label %13
i32 65, label %13
i32 100, label %16
i32 68, label %16
i32 119, label %19
i32 87, label %19
i32 115, label %22
i32 83, label %22
]
13: ; preds = %8, %8
%14 = tail call i32 (...) @MergeLeft()
%15 = tail call i32 (...) @ShiftLeft()
br label %25
16: ; preds = %8, %8
%17 = tail call i32 (...) @MergeRight()
%18 = tail call i32 (...) @ShiftRight()
br label %25
19: ; preds = %8, %8
%20 = tail call i32 (...) @MergeUp()
%21 = tail call i32 (...) @ShiftUp()
br label %25
22: ; preds = %8, %8
%23 = tail call i32 (...) @MergeDown()
%24 = tail call i32 (...) @ShiftDown()
br label %25
25: ; preds = %8, %22, %19, %16, %13
%26 = tail call i32 (...) @clear()
%27 = tail call i64 (...) @isSpaceAvailable()
%28 = icmp ne i64 %27, 0
%29 = icmp ne i8 %11, 107
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %5, label %31
31: ; preds = %5, %25
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
ret void
}