#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*/ c_show_table(int **, int);
int /*<<< orphan*/ copy_map(int **, int **, int);
int **game_initial(int);
int /*<<< orphan*/ game_over(int **, int);
char getchar();
scalar_t__ is_equal_map(int **, int **, int);
scalar_t__ is_over_btr(int **, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_new_num(int **, int);
int /*<<< orphan*/ slide_map(int **, int, int);
int /*<<< orphan*/ system(char *);
int main() {
  int dir;
  int **map;
  int **tmp;
  tmp = game_initial(4);
  map = game_initial(4);
  set_new_num(map, 4);
  system("clear");
  c_show_table(map, 4);
  while ((dir = getchar()) && dir != 'q') {
    while (getchar() != '\n')
      ;
    copy_map(tmp, map, 4);
    slide_map(map, 4, dir);
    if (is_equal_map(map, tmp, 4)) {
      system("clear");
      c_show_table(map, 4);
      continue;
    }
    set_new_num(map, 4);
    if (is_over_btr(map, 4)) {
      c_show_table(map, 4);
      printf("游戏结束");
      game_over(map, 4);
      game_over(tmp, 4);
      break;
    }
    system("clear");
    c_show_table(map, 4);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   10c0 <game_initial@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   10c0 <game_initial@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1030 <set_new_num@plt>
lea    0xe10(%rip),%rdi
call   1050 <system@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   10b0 <c_show_table@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
movsbl %al,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1228 <main+0x78>
cmpl   $0x71,-0x8(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1238 <main+0x88>
jmp    1333 <main+0x183>
jmp    123d <main+0x8d>
mov    $0x0,%al
call   1080 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1255 <main+0xa5>
jmp    123d <main+0x8d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1070 <copy_map@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x4,%esi
call   1040 <slide_map@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <is_equal_map@plt>
cmp    $0x0,%rax
je     12b3 <main+0x103>
lea    0xd65(%rip),%rdi
call   1050 <system@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   10b0 <c_show_table@plt>
jmp    1203 <main+0x53>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1030 <set_new_num@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1090 <is_over_btr@plt>
cmp    $0x0,%rax
je     1314 <main+0x164>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   10b0 <c_show_table@plt>
lea    0xd18(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   10d0 <game_over@plt>
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   10d0 <game_over@plt>
jmp    1333 <main+0x183>
lea    0xce5(%rip),%rdi
call   1050 <system@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   10b0 <c_show_table@plt>
jmp    1203 <main+0x53>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   10c0 <game_initial@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   10c0 <game_initial@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
call   1030 <set_new_num@plt>
lea    0xe1b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1050 <system@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   10b0 <c_show_table@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
test   %al,%al
je     12b5 <main+0x105>
cmp    $0x71,%al
je     12b5 <main+0x105>
movsbl %al,%ebp
nop
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
jne    1220 <main+0x70>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1070 <copy_map@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %ebp,%edx
call   1040 <slide_map@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   10a0 <is_equal_map@plt>
test   %rax,%rax
jne    11f0 <main+0x40>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <set_new_num@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1090 <is_over_btr@plt>
test   %rax,%rax
je     11f0 <main+0x40>
mov    %rbx,%rdi
mov    $0x4,%esi
call   10b0 <c_show_table@plt>
lea    0xd70(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   10d0 <game_over@plt>
mov    %r14,%rdi
mov    $0x4,%esi
call   10d0 <game_over@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@.str.1 = [13 x i8] c"\E6\B8\B8\E6\88\8F\E7\BB\93\E6\9D\9F\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32**
store i32 0, i32* %1
%5 = call i32** @game_initial(i32 4)
store i32** %5, i32*** %4
%6 = call i32** @game_initial(i32 4)
store i32** %6, i32*** %3
%7 = load i32**, i32*** %3
%8 = call i32 @set_new_num(i32** %7, i32 4)
%9 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = load i32**, i32*** %3
%11 = call i32 @c_show_table(i32** %10, i32 4)
br label %12
12: ; preds = %56, %38, %0
%13 = call signext i8 (...) @getchar()
%14 = sext i8 %13 to i32
store i32 %14, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 113
br label %19
19: ; preds = %16, %12
%20 = phi i1 [ false, %12 ], [ %18, %16 ]
br i1 %20, label %21, label %60
21: ; preds = %19
br label %22
22: ; preds = %26, %21
%23 = call signext i8 (...) @getchar()
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %22
br label %22
27: ; preds = %22
%28 = load i32**, i32*** %4
%29 = load i32**, i32*** %3
%30 = call i32 @copy_map(i32** %28, i32** %29, i32 4)
%31 = load i32**, i32*** %3
%32 = load i32, i32* %2
%33 = call i32 @slide_map(i32** %31, i32 4, i32 %32)
%34 = load i32**, i32*** %3
%35 = load i32**, i32*** %4
%36 = call i64 @is_equal_map(i32** %34, i32** %35, i32 4)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %27
%39 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%40 = load i32**, i32*** %3
%41 = call i32 @c_show_table(i32** %40, i32 4)
br label %12
42: ; preds = %27
%43 = load i32**, i32*** %3
%44 = call i32 @set_new_num(i32** %43, i32 4)
%45 = load i32**, i32*** %3
%46 = call i64 @is_over_btr(i32** %45, i32 4)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %42
%49 = load i32**, i32*** %3
%50 = call i32 @c_show_table(i32** %49, i32 4)
%51 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%52 = load i32**, i32*** %3
%53 = call i32 @game_over(i32** %52, i32 4)
%54 = load i32**, i32*** %4
%55 = call i32 @game_over(i32** %54, i32 4)
br label %60
56: ; preds = %42
%57 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%58 = load i32**, i32*** %3
%59 = call i32 @c_show_table(i32** %58, i32 4)
br label %12
60: ; preds = %48, %19
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@.str.1 = [13 x i8] c"\E6\B8\B8\E6\88\8F\E7\BB\93\E6\9D\9F\00"
define i32 @main() {
%1 = tail call i32** @game_initial(i32 4)
%2 = tail call i32** @game_initial(i32 4)
%3 = tail call i32 @set_new_num(i32** %2, i32 4)
br label %4
4: ; preds = %17, %0
%5 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @c_show_table(i32** %2, i32 4)
%7 = tail call signext i8 (...) @getchar()
%8 = sext i8 %7 to i32
switch i8 %7, label %9 [
i8 113, label %27
i8 0, label %27
]
9: ; preds = %4, %9
%10 = tail call signext i8 (...) @getchar()
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %9
12: ; preds = %9
%13 = tail call i32 @copy_map(i32** %1, i32** %2, i32 4)
%14 = tail call i32 @slide_map(i32** %2, i32 4, i32 %8)
%15 = tail call i64 @is_equal_map(i32** %2, i32** %1, i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12, %18
br label %4
18: ; preds = %12
%19 = tail call i32 @set_new_num(i32** %2, i32 4)
%20 = tail call i64 @is_over_btr(i32** %2, i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %18
%23 = tail call i32 @c_show_table(i32** %2, i32 4)
%24 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @game_over(i32** %2, i32 4)
%26 = tail call i32 @game_over(i32** %1, i32 4)
br label %27
27: ; preds = %4, %4, %22
ret i32 0
}