// File: /workspace/github_cpp_makefile_star2_O3/juancalaca[P]dotsboxes/main.cc
// Function: main
int main ()
{
	// Number of players
	int num_players = 2;
	
	// declare player data
	string player_names[num_players];
	player_names[0] = "P1";
	player_names[1] = "P2";

	int player_scores[num_players];
	
	//initialize player data
	for (int i = 0; i < num_players; i++)
	{
		player_scores[i] = 0;
	}
	
	// Board size
	int board_columns = 3;
	int board_rows = 3;
	
	// Make game Board
	DotsBoard *board = new DotsBoard(board_rows, board_columns);
	
	//print initial state of the game board
	board->PrintBoard();
	
	
	// Zedboard instance to control the game
	ZedBoard *zed = new ZedBoard();
 	
 	// run the game	
 	int current = 0;
 	
 	while (!board->GameOver())
 	{
		int claimed = TakeTurn(player_names[current], board, zed, board_rows, board_columns);
 		if (claimed > 0)
 		{
 			player_scores[current] += claimed;
 		}
 		else {
 			// update whose turn it is
 			current = (current + 1) % num_players;	
		}	
 	}
	
	//print final state of board
	board->PrintBoard();

	//tell user the game is over
	cout << "The game is now over, all the boxes are taken!" << endl;
	
	// Find winner & print
	if (player_scores[0] == player_scores[1])
	{
		cout << player_names[0] << " and " << player_names[1] << " Tied!" << endl;
	}
	else if ( player_scores[0] > player_scores[1])
	{
		cout << player_names[0] << " won this game!" << endl;
	}
	else
	{
		cout << player_names[1] << " won this game!" << endl;
	}
	
	
	// Delete game board, controller, players, zedboard
	delete zed;
	delete board;
	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl $0x10, %eax
leaq (%rax,%rbp), %rcx
addq $-0xa0, %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x3da2
leaq -0xa0(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x1419(%rip), %rcx      # 0x51f1
movl $0x2, %r8d
xorl %esi, %esi
callq 0x21a0
leaq -0x80(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x1400(%rip), %rcx      # 0x51f4
movl $0x2, %r8d
xorl %esi, %esi
callq 0x21a0
movq %rsp, %rax
leaq -0x10(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq %rcx, %rsp
movq $0x0, -0x10(%rax)
movl $0x28, %edi
callq 0x2130
movq %rax, %r12
movq %rax, %rdi
movl $0x3, %esi
movl $0x3, %edx
callq 0x27bc
movq %r12, %rdi
callq 0x2b52
movl $0x10, %edi
callq 0x2130
movq %rax, %rbx
movq %rax, %rdi
callq 0x4138
movq %rbx, -0x38(%rbp)
xorl %r13d, %r13d
leaq -0x58(%rbp), %r15
movl %r13d, %r13d
movq %r13, %rax
shlq $0x5, %rax
leaq (%rax,%rbp), %rbx
addq $-0xa0, %rbx
movq %r12, %rdi
callq 0x2b48
testb %al, %al
jne 0x3ef3
leaq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x25cc
movq %r15, %rdi
movq %r12, %r14
movq %r12, %rsi
movq -0x38(%rbp), %rdx
movl $0x3, %ecx
movl $0x3, %r8d
callq 0x3864
movl %eax, %r12d
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x3ed2
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2140
testl %r12d, %r12d
je 0x3ee4
movq -0x30(%rbp), %rax
addl %r12d, (%rax,%r13,4)
movq %r14, %r12
jmp 0x3e73
notl %r13d
andl $0x1, %r13d
movq %r14, %r12
jmp 0x3e5e
movq %r12, %rdi
callq 0x2b52
movq -0x38(%rbp), %rbx
movq 0x40ca(%rip), %r15      # 0x7fd0
leaq 0x12ea(%rip), %rsi      # 0x51f7
movl $0x2e, %edx
movq %r15, %rdi
callq 0x2150
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq 0x4098(%rip), %rdi      # 0x7fd0
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %eax
cmpl %eax, (%rcx)
jne 0x3fc1
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0x406b(%rip), %rdi      # 0x7fd0
callq 0x2150
movq %rax, %r15
leaq 0x12b2(%rip), %rsi      # 0x5226
movl $0x5, %edx
movq %rax, %rdi
callq 0x2150
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq %r15, %rdi
callq 0x2150
movq %rax, %r15
leaq 0x1291(%rip), %rsi      # 0x522c
movl $0x6, %edx
movq %rax, %rdi
callq 0x2150
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2110
jmp 0x4049
jle 0x400a
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0x3ff8(%rip), %rdi      # 0x7fd0
callq 0x2150
movq %rax, %r15
leaq 0x124c(%rip), %rsi      # 0x5233
movl $0xf, %edx
movq %rax, %rdi
callq 0x2150
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2110
jmp 0x4049
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq 0x3fb7(%rip), %rdi      # 0x7fd0
callq 0x2150
movq %rax, %r15
leaq 0x120b(%rip), %rsi      # 0x5233
movl $0xf, %edx
movq %rax, %rdi
callq 0x2150
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x419a
movl $0x10, %esi
movq %rbx, %rdi
callq 0x2140
movq %r12, %rdi
callq 0x2a62
movl $0x28, %esi
movq %r12, %rdi
callq 0x2140
leaq -0x70(%rbp), %rbx
xorl %r14d, %r14d
movq -0x80(%rbp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x40a6
movq (%rax), %rsi
incq %rsi
callq 0x2140
addq $-0x20, %r14
cmpq $-0x40, %r14
jne 0x408d
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movl $0x10, %esi
movq %rbx, %rdi
jmp 0x40fa
jmp 0x4103
movq %rax, %r15
movl $0x28, %esi
movq %r12, %rdi
jmp 0x40fa
jmp 0x4103
jmp 0x4103
jmp 0x4103
movq %rax, %r15
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x4106
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x4106
jmp 0x4103
movq %rax, %r15
leaq -0x70(%rbp), %rbx
xorl %r14d, %r14d
movq -0x80(%rbp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x4126
movq (%rax), %rsi
incq %rsi
callq 0x2140
addq $-0x20, %r14
cmpq $-0x40, %r14
jne 0x410d
movq %r15, %rdi
callq 0x21d0