#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*/ add(int **);
int check(int **);
int move(int **, char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ reset(int **);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ system(char *);
char toupper(char);
int /*<<< orphan*/ view(int **);
void play(int a[][4]) {
  char c;
  int stat = -1;
  reset(a);
  int bad = 1;
  int x = 1;
  while (stat == -1) {
    system("cls");
    view(a);
    int stat = check(a);
    if (!stat) {
      printf("you lose!");
      break;
    } else if (stat == 1) {
      printf("you win!");
      break;
    }
    if (!bad && x)
      add(a);
    else
      bad = 0;
    printf("Type one of 'WASD' to push the board in that direction\n");
    printf("Type 'R' to reset the game or type 'Q' to ragequit\n\n\n   input:");
    scanf("%c", &c);
    if (toupper(c) == 'W' || toupper(c) == 'A' || toupper(c) == 'S' ||
        toupper(c) == 'D')
      x = move(a, toupper(c));
    else if (toupper(c) == 'Q')
      return;
    else if (toupper(c) == 'R') {
      reset(a);
      bad = 1;
    } else
      bad = 1;
  }
}


x86 assembly (clang, -O0):
<play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <reset@plt>
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1344 <play+0x1b4>
lea    0xe35(%rip),%rdi
call   1050 <system@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <view@plt>
mov    -0x8(%rbp),%rdi
call   1090 <check@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1200 <play+0x70>
lea    0xe0e(%rip),%rdi
call   1060 <printf@plt>
jmp    1344 <play+0x1b4>
cmpl   $0x1,-0x1c(%rbp)
jne    121b <play+0x8b>
lea    0xdfd(%rip),%rdi
call   1060 <printf@plt>
jmp    1344 <play+0x1b4>
jmp    1220 <play+0x90>
cmpl   $0x0,-0x14(%rbp)
jne    1242 <play+0xb2>
cmpl   $0x0,-0x18(%rbp)
je     1242 <play+0xb2>
mov    -0x8(%rbp),%rdi
call   1030 <add@plt>
jmp    1249 <play+0xb9>
movl   $0x0,-0x14(%rbp)
lea    0xdc7(%rip),%rdi
call   1060 <printf@plt>
lea    0xdf3(%rip),%rdi
call   1060 <printf@plt>
lea    0xe26(%rip),%rdi
lea    -0x9(%rbp),%rsi
call   1080 <scanf@plt>
movsbl -0x9(%rbp),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x57,%eax
je     12c5 <play+0x135>
movsbl -0x9(%rbp),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x41,%eax
je     12c5 <play+0x135>
movsbl -0x9(%rbp),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x53,%eax
je     12c5 <play+0x135>
movsbl -0x9(%rbp),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x44,%eax
jne    12ea <play+0x15a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsbl -0x9(%rbp),%edi
call   1040 <toupper@plt>
mov    -0x28(%rbp),%rdi
movsbl %al,%esi
call   10b0 <move@plt>
mov    %eax,-0x18(%rbp)
jmp    133f <play+0x1af>
movsbl -0x9(%rbp),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x51,%eax
jne    1304 <play+0x174>
jmp    1344 <play+0x1b4>
movsbl -0x9(%rbp),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x52,%eax
jne    132e <play+0x19e>
mov    -0x8(%rbp),%rdi
call   1070 <reset@plt>
movl   $0x1,-0x14(%rbp)
jmp    1335 <play+0x1a5>
movl   $0x1,-0x14(%rbp)
jmp    133a <play+0x1aa>
jmp    133f <play+0x1af>
jmp    11ba <play+0x2a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<play>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1080 <reset@plt>
mov    $0x1,%r15d
xor    %r12d,%r12d
lea    0xe3d(%rip),%r14
lea    0xe8c(%rip),%r13
lea    0x7(%rsp),%rbp
jmp    11f0 <play+0x50>
movsbl 0x7(%rsp),%edi
call   1040 <toupper@plt>
movsbl %al,%esi
mov    %rbx,%rdi
call   10c0 <move@plt>
mov    %eax,%r15d
mov    $0x1,%r12b
nopl   0x0(%rax)
mov    %r14,%rdi
call   1060 <system@plt>
mov    %rbx,%rdi
call   10b0 <view@plt>
mov    %rbx,%rdi
call   10a0 <check@plt>
test   %eax,%eax
je     12ce <play+0x12e>
cmp    $0x1,%eax
je     12d7 <play+0x137>
test   %r15d,%r15d
setne  %al
and    %al,%r12b
cmp    $0x1,%r12b
jne    1230 <play+0x90>
mov    %rbx,%rdi
call   1030 <add@plt>
lea    0xe22(%rip),%rdi
call   1050 <puts@plt>
lea    0xdd4(%rip),%rdi
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1090 <scanf@plt>
movsbl 0x7(%rsp),%edi
call   1040 <toupper@plt>
cmp    $0x57,%al
je     11d1 <play+0x31>
movsbl 0x7(%rsp),%edi
call   1040 <toupper@plt>
cmp    $0x41,%al
je     11d1 <play+0x31>
movsbl 0x7(%rsp),%edi
call   1040 <toupper@plt>
cmp    $0x53,%al
je     11d1 <play+0x31>
movsbl 0x7(%rsp),%edi
call   1040 <toupper@plt>
cmp    $0x44,%al
je     11d1 <play+0x31>
movsbl 0x7(%rsp),%edi
call   1040 <toupper@plt>
cmp    $0x51,%al
je     12e3 <play+0x143>
movsbl 0x7(%rsp),%edi
call   1040 <toupper@plt>
xor    %r12d,%r12d
cmp    $0x52,%al
jne    11f0 <play+0x50>
mov    %rbx,%rdi
call   1080 <reset@plt>
xor    %r12d,%r12d
jmp    11f0 <play+0x50>
lea    0xd2f(%rip),%rdi
jmp    12de <play+0x13e>
lea    0xd30(%rip),%rdi
call   1070 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"cls\00"
@.str.1 = [10 x i8] c"you lose!\00"
@.str.2 = [9 x i8] c"you win!\00"
@.str.3 = [56 x i8] c"Type one of 'WASD' to push the board in that direction\0A\00"
@.str.4 = [63 x i8] c"Type 'R' to reset the game or type 'Q' to ragequit\0A\0A\0A input:\00"
@.str.5 = [3 x i8] c"%c\00"
define void @play([4 x i32]* %0) {
%2 = alloca [4 x i32]*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store [4 x i32]* %0, [4 x i32]** %2
store i32 -1, i32* %4
%8 = load [4 x i32]*, [4 x i32]** %2
%9 = bitcast [4 x i32]* %8 to i32**
%10 = call i32 @reset(i32** %9)
store i32 1, i32* %5
store i32 1, i32* %6
br label %11
11: ; preds = %90, %1
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %91
14: ; preds = %11
%15 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = load [4 x i32]*, [4 x i32]** %2
%17 = bitcast [4 x i32]* %16 to i32**
%18 = call i32 @view(i32** %17)
%19 = load [4 x i32]*, [4 x i32]** %2
%20 = bitcast [4 x i32]* %19 to i32**
%21 = call i32 @check(i32** %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %14
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %91
26: ; preds = %14
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %91
31: ; preds = %26
br label %32
32: ; preds = %31
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %32
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load [4 x i32]*, [4 x i32]** %2
%40 = bitcast [4 x i32]* %39 to i32**
%41 = call i32 @add(i32** %40)
br label %43
42: ; preds = %35, %32
store i32 0, i32* %5
br label %43
43: ; preds = %42, %38
%44 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%47 = load i8, i8* %3
%48 = call signext i8 @toupper(i8 signext %47)
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 87
br i1 %50, label %66, label %51
51: ; preds = %43
%52 = load i8, i8* %3
%53 = call signext i8 @toupper(i8 signext %52)
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 65
br i1 %55, label %66, label %56
56: ; preds = %51
%57 = load i8, i8* %3
%58 = call signext i8 @toupper(i8 signext %57)
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 83
br i1 %60, label %66, label %61
61: ; preds = %56
%62 = load i8, i8* %3
%63 = call signext i8 @toupper(i8 signext %62)
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 68
br i1 %65, label %66, label %72
66: ; preds = %61, %56, %51, %43
%67 = load [4 x i32]*, [4 x i32]** %2
%68 = bitcast [4 x i32]* %67 to i32**
%69 = load i8, i8* %3
%70 = call signext i8 @toupper(i8 signext %69)
%71 = call i32 @move(i32** %68, i8 signext %70)
store i32 %71, i32* %6
br label %90
72: ; preds = %61
%73 = load i8, i8* %3
%74 = call signext i8 @toupper(i8 signext %73)
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 81
br i1 %76, label %77, label %78
77: ; preds = %72
br label %91
78: ; preds = %72
%79 = load i8, i8* %3
%80 = call signext i8 @toupper(i8 signext %79)
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 82
br i1 %82, label %83, label %87
83: ; preds = %78
%84 = load [4 x i32]*, [4 x i32]** %2
%85 = bitcast [4 x i32]* %84 to i32**
%86 = call i32 @reset(i32** %85)
store i32 1, i32* %5
br label %88
87: ; preds = %78
store i32 1, i32* %5
br label %88
88: ; preds = %87, %83
br label %89
89: ; preds = %88
br label %90
90: ; preds = %89, %66
br label %11
91: ; preds = %77, %29, %24, %11
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"cls\00"
@.str.1 = [10 x i8] c"you lose!\00"
@.str.2 = [9 x i8] c"you win!\00"
@.str.4 = [63 x i8] c"Type 'R' to reset the game or type 'Q' to ragequit\0A\0A\0A input:\00"
@.str.5 = [3 x i8] c"%c\00"
@str = [55 x i8] c"Type one of 'WASD' to push the board in that direction\00"
define void @play([4 x i32]* %0) {
%2 = alloca i8
%3 = bitcast [4 x i32]* %0 to i32**
%4 = tail call i32 @reset(i32** %3)
br label %5
5: ; preds = %37, %1
%6 = phi i32 [ %40, %37 ], [ 1, %1 ]
%7 = phi i1 [ true, %37 ], [ false, %1 ]
%8 = icmp ne i32 %6, 0
br label %9
9: ; preds = %51, %5
%10 = phi i1 [ %7, %5 ], [ false, %51 ]
%11 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @view(i32** %3)
%13 = call i32 @check(i32** %3)
switch i32 %13, label %14 [
i32 0, label %53
i32 1, label %52
]
14: ; preds = %9
%15 = select i1 %10, i1 %8, i1 false
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = call i32 @add(i32** %3)
br label %18
18: ; preds = %14, %16
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%22 = load i8, i8* %2
%23 = call signext i8 @toupper(i8 signext %22)
%24 = icmp eq i8 %23, 87
br i1 %24, label %37, label %25
25: ; preds = %18
%26 = load i8, i8* %2
%27 = call signext i8 @toupper(i8 signext %26)
%28 = icmp eq i8 %27, 65
br i1 %28, label %37, label %29
29: ; preds = %25
%30 = load i8, i8* %2
%31 = call signext i8 @toupper(i8 signext %30)
%32 = icmp eq i8 %31, 83
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i8, i8* %2
%35 = call signext i8 @toupper(i8 signext %34)
%36 = icmp eq i8 %35, 68
br i1 %36, label %37, label %41
37: ; preds = %33, %29, %25, %18
%38 = load i8, i8* %2
%39 = call signext i8 @toupper(i8 signext %38)
%40 = call i32 @move(i32** %3, i8 signext %39)
br label %5
41: ; preds = %33
%42 = load i8, i8* %2
%43 = call signext i8 @toupper(i8 signext %42)
%44 = icmp eq i8 %43, 81
br i1 %44, label %56, label %45
45: ; preds = %41
%46 = load i8, i8* %2
%47 = call signext i8 @toupper(i8 signext %46)
%48 = icmp eq i8 %47, 82
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @reset(i32** %3)
br label %51
51: ; preds = %49, %45
br label %9
52: ; preds = %9
br label %53
53: ; preds = %9, %52
%54 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %52 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %9 ]
%55 = call i32 @printf(i8* dereferenceable(1) %54)
br label %56
56: ; preds = %41, %53
ret void
}