#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*/ clear_screen();
int /*<<< orphan*/ generate_board(int **, int *);
int /*<<< orphan*/ generate_pieces(int *);
scalar_t__ has_won(int **);
int /*<<< orphan*/ move_piece(int, int **);
int /*<<< orphan*/ print_board(int **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int unused_pieces[(4 * 4 - 1)];
  generate_pieces(unused_pieces);
  int board[4][4];
  generate_board(board, unused_pieces);
  int piece_to_move;
  clear_screen();
  while (1) {
    printf("\n");
    print_board(board);
    if (has_won(board)) {
      printf("\nCongratulations, you've won!\n");
      return 0;
    }
    printf("\n> ");
    scanf("%d", &piece_to_move);
    clear_screen();
    if (!move_piece(piece_to_move, board)) {
      printf("Invalid move.");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <generate_pieces@plt>
lea    -0x80(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <generate_board@plt>
mov    $0x0,%al
call   1080 <clear_screen@plt>
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1050 <print_board@plt>
lea    -0x80(%rbp),%rdi
call   1090 <has_won@plt>
cmp    $0x0,%rax
je     11ee <main+0x6e>
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe22(%rip),%rdi
lea    -0x84(%rbp),%rsi
call   1070 <scanf@plt>
mov    $0x0,%al
call   1080 <clear_screen@plt>
mov    -0x84(%rbp),%edi
lea    -0x80(%rbp),%rsi
call   1060 <move_piece@plt>
cmp    $0x0,%eax
jne    1238 <main+0xb8>
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
jmp    11af <main+0x2f>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x90,%rsp
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <generate_pieces@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <generate_board@plt>
xor    %eax,%eax
call   10a0 <clear_screen@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1070 <print_board@plt>
mov    %r14,%rdi
call   10b0 <has_won@plt>
test   %rax,%rax
je     1212 <main+0x72>
lea    0xe1b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xde7(%rip),%r14
lea    0xde4(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xdd6(%rip),%r13
jmp    125f <main+0xbf>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <print_board@plt>
mov    %rbx,%rdi
call   10b0 <has_won@plt>
test   %rax,%rax
jne    11f3 <main+0x53>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
call   10a0 <clear_screen@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1080 <move_piece@plt>
test   %eax,%eax
jne    1240 <main+0xa0>
mov    %r13,%rdi
call   1060 <printf@plt>
jmp    1240 <main+0xa0>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [31 x i8] c"\0ACongratulations, you've won!\0A\00"
@.str.2 = [4 x i8] c"\0A> \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"Invalid move.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [15 x i32]
%3 = alloca [4 x [4 x i32]]
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 0
%6 = call i32 @generate_pieces(i32* %5)
%7 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0
%8 = bitcast [4 x i32]* %7 to i32**
%9 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 0
%10 = call i32 @generate_board(i32** %8, i32* %9)
%11 = call i32 (...) @clear_screen()
br label %12
12: ; preds = %0, %34
%13 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0
%15 = bitcast [4 x i32]* %14 to i32**
%16 = call i32 @print_board(i32** %15)
%17 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0
%18 = bitcast [4 x i32]* %17 to i32**
%19 = call i64 @has_won(i32** %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
23: ; preds = %12
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%26 = call i32 (...) @clear_screen()
%27 = load i32, i32* %4
%28 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0
%29 = bitcast [4 x i32]* %28 to i32**
%30 = call i32 @move_piece(i32 %27, i32** %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %23
%33 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %23
br label %12
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c"\0A> \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"Invalid move.\00"
@str = [30 x i8] c"\0ACongratulations, you've won!\00"
define i32 @main() {
%1 = alloca [15 x i32]
%2 = alloca [4 x [4 x i32]]
%3 = alloca i32
%4 = bitcast [15 x i32]* %1 to i8*
%5 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 0
%6 = call i32 @generate_pieces(i32* %5)
%7 = bitcast [4 x [4 x i32]]* %2 to i8*
%8 = bitcast [4 x [4 x i32]]* %2 to i32**
%9 = call i32 @generate_board(i32** %8, i32* %5)
%10 = bitcast i32* %3 to i8*
%11 = call i32 (...) @clear_screen()
%12 = call i32 @putchar(i32 10)
%13 = call i32 @print_board(i32** %8)
%14 = call i64 @has_won(i32** %8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %27, %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
ret i32 0
18: ; preds = %0, %27
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%21 = call i32 (...) @clear_screen()
%22 = load i32, i32* %3
%23 = call i32 @move_piece(i32 %22, i32** %8)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %18
%28 = call i32 @putchar(i32 10)
%29 = call i32 @print_board(i32** %8)
%30 = call i64 @has_won(i32** %8)
%31 = icmp eq i64 %30, 0
br i1 %31, label %18, label %16
}