#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_num(int **);
int check_game_end(int **);
char getch();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ put_location(int **);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ start_location(int **);
int /*<<< orphan*/ sum_num_down(int **);
int /*<<< orphan*/ sum_num_left(int **);
int /*<<< orphan*/ sum_num_right(int **);
int /*<<< orphan*/ sum_num_up(int **);
scalar_t__ time(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char ch;
  int num[4][4];
  srand((int)time(0));
  start_location(num);
  put_location(num);
  for (;;) {
    ch = getch();
    switch (ch) {
    case 'w':
      sum_num_up(num);
      goto _NEXT;
      break;
    case 's':
      sum_num_down(num);
      goto _NEXT;
      break;
    case 'a':
      sum_num_left(num);
      goto _NEXT;
      break;
    case 'd':
      sum_num_right(num);
      goto _NEXT;
      break;
    }
    if (0) {
    _NEXT:;
      switch (check_game_end(num)) {
      case 0:
        add_num(num);
        break;
      case 1:
        goto _END;
        break;
      case 2:
        break;
      }
      put_location(num);
    }
  }
_END:;
  printf("game over!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
lea    -0x60(%rbp),%rdi
call   1050 <start_location@plt>
lea    -0x60(%rbp),%rdi
call   10e0 <put_location@plt>
xor    %eax,%eax
call   10c0 <getch@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x68(%rbp)
sub    $0x16,%eax
ja     1262 <main+0xa2>
mov    -0x68(%rbp),%rax
lea    0xddf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x60(%rbp),%rdi
call   10d0 <sum_num_up@plt>
jmp    1276 <main+0xb6>
lea    -0x60(%rbp),%rdi
call   1030 <sum_num_down@plt>
jmp    1276 <main+0xb6>
lea    -0x60(%rbp),%rdi
call   1040 <sum_num_left@plt>
jmp    1276 <main+0xb6>
lea    -0x60(%rbp),%rdi
call   10a0 <sum_num_right@plt>
jmp    1276 <main+0xb6>
xor    %eax,%eax
test   $0x1,%al
jne    1271 <main+0xb1>
jmp    12d4 <main+0x114>
jmp    1276 <main+0xb6>
lea    -0x60(%rbp),%rdi
call   1070 <check_game_end@plt>
mov    %eax,%ecx
mov    %ecx,-0x6c(%rbp)
test   %eax,%eax
je     12b3 <main+0xf3>
jmp    1291 <main+0xd1>
mov    -0x6c(%rbp),%eax
sub    $0x1,%eax
je     12c1 <main+0x101>
jmp    12a2 <main+0xe2>
mov    -0x6c(%rbp),%eax
sub    $0x2,%eax
je     12c6 <main+0x106>
jmp    12cb <main+0x10b>
lea    -0x60(%rbp),%rdi
call   1060 <add_num@plt>
jmp    12cb <main+0x10b>
jmp    12d9 <main+0x119>
jmp    12cb <main+0x10b>
lea    -0x60(%rbp),%rdi
call   10e0 <put_location@plt>
jmp    11f6 <main+0x36>
lea    0xd7c(%rip),%rdi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <start_location@plt>
lea    0xe19(%rip),%rbx
jmp    11f8 <main+0x38>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1060 <add_num@plt>
mov    %r14,%rdi
call   10e0 <put_location@plt>
xor    %eax,%eax
call   10c0 <getch@plt>
movsbl %al,%eax
add    $0xffffff9f,%eax
cmp    $0x16,%eax
ja     1200 <main+0x40>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r14,%rdi
call   1040 <sum_num_left@plt>
jmp    1258 <main+0x98>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <sum_num_down@plt>
jmp    1258 <main+0x98>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10d0 <sum_num_up@plt>
jmp    1258 <main+0x98>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10a0 <sum_num_right@plt>
mov    %r14,%rdi
call   1070 <check_game_end@plt>
test   %eax,%eax
je     11f0 <main+0x30>
cmp    $0x1,%eax
jne    11f8 <main+0x38>
lea    0xdec(%rip),%rdi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"game over!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca [4 x [4 x i32]]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @time(i32 0)
%9 = trunc i64 %8 to i32
%10 = call i32 @srand(i32 %9)
%11 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%12 = bitcast [4 x i32]* %11 to i32**
%13 = call i32 @start_location(i32** %12)
%14 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%15 = bitcast [4 x i32]* %14 to i32**
%16 = call i32 @put_location(i32** %15)
br label %17
17: ; preds = %53, %2
%18 = call signext i8 (...) @getch()
store i8 %18, i8* %6
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
switch i32 %20, label %37 [
i32 119, label %21
i32 115, label %25
i32 97, label %29
i32 100, label %33
]
21: ; preds = %17
%22 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%23 = bitcast [4 x i32]* %22 to i32**
%24 = call i32 @sum_num_up(i32** %23)
br label %39
25: ; preds = %17
%26 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%27 = bitcast [4 x i32]* %26 to i32**
%28 = call i32 @sum_num_down(i32** %27)
br label %39
29: ; preds = %17
%30 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%31 = bitcast [4 x i32]* %30 to i32**
%32 = call i32 @sum_num_left(i32** %31)
br label %39
33: ; preds = %17
%34 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%35 = bitcast [4 x i32]* %34 to i32**
%36 = call i32 @sum_num_right(i32** %35)
br label %39
37: ; preds = %17
br i1 false, label %38, label %53
38: ; preds = %37
br label %39
39: ; preds = %38, %33, %29, %25, %21
%40 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%41 = bitcast [4 x i32]* %40 to i32**
%42 = call i32 @check_game_end(i32** %41)
switch i32 %42, label %49 [
i32 0, label %43
i32 1, label %47
i32 2, label %48
]
43: ; preds = %39
%44 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%45 = bitcast [4 x i32]* %44 to i32**
%46 = call i32 @add_num(i32** %45)
br label %49
47: ; preds = %39
br label %54
48: ; preds = %39
br label %49
49: ; preds = %39, %48, %43
%50 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %7, i64 0, i64 0
%51 = bitcast [4 x i32]* %50 to i32**
%52 = call i32 @put_location(i32** %51)
br label %53
53: ; preds = %49, %37
br label %17
54: ; preds = %47
%55 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"game over!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x [4 x i32]]
%4 = bitcast [4 x [4 x i32]]* %3 to i8*
%5 = tail call i64 @time(i32 0)
%6 = trunc i64 %5 to i32
%7 = tail call i32 @srand(i32 %6)
%8 = bitcast [4 x [4 x i32]]* %3 to i32**
%9 = call i32 @start_location(i32** %8)
br label %10
10: ; preds = %25, %2
%11 = call i32 @put_location(i32** %8)
br label %12
12: ; preds = %10, %12
%13 = call signext i8 (...) @getch()
%14 = sext i8 %13 to i32
switch i32 %14, label %12 [
i32 119, label %15
i32 115, label %17
i32 97, label %19
i32 100, label %21
]
15: ; preds = %12
%16 = call i32 @sum_num_up(i32** %8)
br label %23
17: ; preds = %12
%18 = call i32 @sum_num_down(i32** %8)
br label %23
19: ; preds = %12
%20 = call i32 @sum_num_left(i32** %8)
br label %23
21: ; preds = %12
%22 = call i32 @sum_num_right(i32** %8)
br label %23
23: ; preds = %21, %19, %17, %15
%24 = call i32 @check_game_end(i32** %8)
switch i32 %24, label %25 [
i32 0, label %26
i32 1, label %28
]
25: ; preds = %23, %26
br label %10
26: ; preds = %23
%27 = call i32 @add_num(i32** %8)
br label %25
28: ; preds = %23
%29 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
ret i32 0
}