// File: tewalds[P]pentagod/pentagod.cpp
// Function: main
int main(int argc, char **argv){
	Board::test();
	Move::test();

	srand(Time().in_msec());
	PentagoGTP gtp;

	gtp.colorboard = isatty(fileno(stdout));

	for(int i = 1; i < argc; i++) {
		string arg = argv[i];
		if(arg == "-h" || arg == "--help"){
			die(255, "Usage:\n"
				"\t-h --help     Show this help\n"
				"\t-v --verbose  Give more output over gtp\n"
				"\t-n --nocolor  Don't output the board in color\n"
				"\t-c --cmd      Pass a gtp command from the command line\n"
				"\t-f --file     Run this gtp file before reading from stdin\n"
				"\t-l --logfile  Log the gtp commands in standard format to this file\n"
				);
		}else if(arg == "-v" || arg == "--verbose"){
			gtp.verbose = true;
		}else if(arg == "-n" || arg == "--nocolor"){
			gtp.colorboard = false;
		}else if(arg == "-c" || arg == "--cmd"){
			char * ptr = argv[++i];
			if(ptr == NULL) die(255, "Missing a command");
			gtp.cmd(ptr);
		}else if(arg == "-f" || arg == "--file"){
			char * ptr = argv[++i];
			if(ptr == NULL) die(255, "Missing a file to run");
			FILE * fd = fopen(ptr, "r");
			gtp.setinfile(fd);
			gtp.setoutfile(NULL);
			if(!gtp.run())
				return 0;
			fclose(fd);
		}else if(arg == "-l" || arg == "--logfile"){
			char * ptr = argv[++i];
			if(ptr == NULL) die(255, "Missing a filename to log to");
			FILE * fd = fopen(ptr, "w");
			if(!fd) die(255, string("Failed to open file: ") + ptr);
			gtp.setlogfile(fd);
		}else{
			die(255, "Unknown argument: " + arg + ", try --help");
		}
	}

	gtp.setinfile(stdin);
	gtp.setoutfile(stdout);
	gtp.run();
	return 0;
}

// Assembly:
subq $0x338, %rsp            # imm = 0x338
movl $0x0, 0x334(%rsp)
movl %edi, 0x330(%rsp)
movq %rsi, 0x328(%rsp)
callq 0x21750
callq 0x25710
leaq 0x320(%rsp), %rdi
callq 0x5500
leaq 0x320(%rsp), %rdi
callq 0x5550
movl %eax, %edi
callq 0x4380
movq 0x4b54d(%rip), %rax     # 0x4ffd0
movq (%rax), %rsi
movq 0x4b52b(%rip), %rax     # 0x4ffb8
movq (%rax), %rdx
leaq 0x288(%rsp), %rdi
xorl %eax, %eax
movl %eax, %ecx
callq 0x5570
movq 0x4b510(%rip), %rax     # 0x4ffb8
movq (%rax), %rdi
callq 0x43d0
movl %eax, %edi
callq 0x4640
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0x2dc(%rsp)
movl $0x1, 0x284(%rsp)
movl 0x284(%rsp), %eax
cmpl 0x330(%rsp), %eax
jge 0x544f
movq 0x328(%rsp), %rax
movslq 0x284(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x70(%rsp)
leaq 0x25f(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x4670
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
leaq 0x260(%rsp), %rdi
callq 0x44d0
jmp 0x4b29
leaq 0x25f(%rsp), %rdi
callq 0x43f0
leaq 0x3861b(%rip), %rsi     # 0x3d158
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x6f(%rsp)
jmp 0x4b50
movb 0x6f(%rsp), %al
testb $0x1, %al
jne 0x4b81
jmp 0x4b5a
leaq 0x387dd(%rip), %rsi     # 0x3d33e
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x6e(%rsp)
jmp 0x4b74
movb 0x6e(%rsp), %al
testb $0x1, %al
jne 0x4b81
jmp 0x4c69
leaq 0x227(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x4670
movq 0x60(%rsp), %rdx
leaq 0x385bc(%rip), %rsi     # 0x3d15b
leaq 0x228(%rsp), %rdi
callq 0x44d0
jmp 0x4bae
movl $0xff, %edi
leaq 0x228(%rsp), %rsi
callq 0x49f0
jmp 0x4bc2
leaq 0x228(%rsp), %rdi
callq 0x4210
leaq 0x227(%rsp), %rdi
callq 0x43f0
jmp 0x53fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x25f(%rsp), %rdi
callq 0x43f0
jmp 0x54da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x543d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x4c57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x228(%rsp), %rdi
callq 0x4210
leaq 0x227(%rsp), %rdi
callq 0x43f0
jmp 0x543d
leaq 0x38620(%rip), %rsi     # 0x3d290
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x5f(%rsp)
jmp 0x4c83
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0x4cb1
jmp 0x4c8d
leaq 0x385ff(%rip), %rsi     # 0x3d293
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x5e(%rsp)
jmp 0x4ca7
movb 0x5e(%rsp), %al
testb $0x1, %al
jne 0x4cb1
jmp 0x4cc1
movl $0x1, 0x2d8(%rsp)
jmp 0x53fa
leaq 0x385d5(%rip), %rsi     # 0x3d29d
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x5d(%rsp)
jmp 0x4cdb
movb 0x5d(%rsp), %al
testb $0x1, %al
jne 0x4d09
jmp 0x4ce5
leaq 0x385b4(%rip), %rsi     # 0x3d2a0
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x5c(%rsp)
jmp 0x4cff
movb 0x5c(%rsp), %al
testb $0x1, %al
jne 0x4d09
jmp 0x4d16
movb $0x0, 0x2dc(%rsp)
jmp 0x53f8
leaq 0x3858d(%rip), %rsi     # 0x3d2aa
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x5b(%rsp)
jmp 0x4d30
movb 0x5b(%rsp), %al
testb $0x1, %al
jne 0x4d61
jmp 0x4d3a
leaq 0x3856c(%rip), %rsi     # 0x3d2ad
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x5a(%rsp)
jmp 0x4d54
movb 0x5a(%rsp), %al
testb $0x1, %al
jne 0x4d61
jmp 0x4f0a
movq 0x328(%rsp), %rax
movl 0x284(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x284(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x218(%rsp)
cmpq $0x0, 0x218(%rsp)
jne 0x4e3e
leaq 0x1f7(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x4670
movq 0x50(%rsp), %rdx
leaq 0x384fd(%rip), %rsi     # 0x3d2b3
leaq 0x1f8(%rsp), %rdi
callq 0x44d0
jmp 0x4dc5
movl $0xff, %edi
leaq 0x1f8(%rsp), %rsi
callq 0x49f0
jmp 0x4dd9
leaq 0x1f8(%rsp), %rdi
callq 0x4210
leaq 0x1f7(%rsp), %rdi
callq 0x43f0
jmp 0x4e3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x4e2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x4210
leaq 0x1f7(%rsp), %rdi
callq 0x43f0
jmp 0x543d
movq 0x218(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x187(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x4670
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
leaq 0x188(%rsp), %rdi
callq 0x44d0
jmp 0x4e76
leaq 0x1a8(%rsp), %rdi
leaq 0x288(%rsp), %rsi
leaq 0x188(%rsp), %rdx
callq 0x8bc0
jmp 0x4e95
leaq 0x1a8(%rsp), %rdi
callq 0x9090
leaq 0x188(%rsp), %rdi
callq 0x4210
leaq 0x187(%rsp), %rdi
callq 0x43f0
jmp 0x53f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x4ef8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x4210
leaq 0x187(%rsp), %rdi
callq 0x43f0
jmp 0x543d
leaq 0x383b4(%rip), %rsi     # 0x3d2c5
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x3f(%rsp)
jmp 0x4f24
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x4f55
jmp 0x4f2e
leaq 0x38393(%rip), %rsi     # 0x3d2c8
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x3e(%rsp)
jmp 0x4f48
movb 0x3e(%rsp), %al
testb $0x1, %al
jne 0x4f55
jmp 0x50d0
movq 0x328(%rsp), %rax
movl 0x284(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x284(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x178(%rsp)
cmpq $0x0, 0x178(%rsp)
jne 0x5032
leaq 0x157(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x4670
movq 0x30(%rsp), %rdx
leaq 0x38325(%rip), %rsi     # 0x3d2cf
leaq 0x158(%rsp), %rdi
callq 0x44d0
jmp 0x4fb9
movl $0xff, %edi
leaq 0x158(%rsp), %rsi
callq 0x49f0
jmp 0x4fcd
leaq 0x158(%rsp), %rdi
callq 0x4210
leaq 0x157(%rsp), %rdi
callq 0x43f0
jmp 0x5032
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x5020
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x4210
leaq 0x157(%rsp), %rdi
callq 0x43f0
jmp 0x543d
movq 0x178(%rsp), %rdi
leaq 0x39594(%rip), %rsi     # 0x3e5d5
callq 0x4440
movq %rax, 0x28(%rsp)
jmp 0x504d
movq 0x28(%rsp), %rax
movq %rax, 0x148(%rsp)
movq 0x148(%rsp), %rsi
leaq 0x288(%rsp), %rdi
callq 0x90c0
jmp 0x5071
xorl %eax, %eax
movl %eax, %esi
leaq 0x288(%rsp), %rdi
callq 0x90e0
jmp 0x5084
leaq 0x288(%rsp), %rdi
callq 0x9100
movb %al, 0x27(%rsp)
jmp 0x5097
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x50bc
jmp 0x50a1
movl $0x0, 0x334(%rsp)
movl $0x1, 0x144(%rsp)
jmp 0x5407
movq 0x148(%rsp), %rdi
callq 0x43a0
jmp 0x50cb
jmp 0x53f4
leaq 0x3820e(%rip), %rsi     # 0x3d2e5
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x26(%rsp)
jmp 0x50ea
movb 0x26(%rsp), %al
testb $0x1, %al
jne 0x511b
jmp 0x50f4
leaq 0x381ed(%rip), %rsi     # 0x3d2e8
leaq 0x260(%rsp), %rdi
callq 0x8b90
movb %al, 0x25(%rsp)
jmp 0x510e
movb 0x25(%rsp), %al
testb $0x1, %al
jne 0x511b
jmp 0x5340
movq 0x328(%rsp), %rax
movl 0x284(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x284(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x138(%rsp)
cmpq $0x0, 0x138(%rsp)
jne 0x51f8
leaq 0x117(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4670
movq 0x18(%rsp), %rdx
leaq 0x38182(%rip), %rsi     # 0x3d2f2
leaq 0x118(%rsp), %rdi
callq 0x44d0
jmp 0x517f
movl $0xff, %edi
leaq 0x118(%rsp), %rsi
callq 0x49f0
jmp 0x5193
leaq 0x118(%rsp), %rdi
callq 0x4210
leaq 0x117(%rsp), %rdi
callq 0x43f0
jmp 0x51f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x51e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x4210
leaq 0x117(%rsp), %rdi
callq 0x43f0
jmp 0x543d
movq 0x138(%rsp), %rdi
leaq 0x39a2b(%rip), %rsi     # 0x3ec32
callq 0x4440
movq %rax, 0x10(%rsp)
jmp 0x5213
movq 0x10(%rsp), %rax
movq %rax, 0x108(%rsp)
cmpq $0x0, 0x108(%rsp)
jne 0x5324
leaq 0xc7(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x4670
movq 0x8(%rsp), %rdx
leaq 0x380c2(%rip), %rsi     # 0x3d30f
leaq 0xc8(%rsp), %rdi
callq 0x44d0
jmp 0x525c
movq 0x138(%rsp), %rdx
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x93b0
jmp 0x527b
movl $0xff, %edi
leaq 0xe8(%rsp), %rsi
callq 0x49f0
jmp 0x528f
leaq 0xe8(%rsp), %rdi
callq 0x4210
leaq 0xc8(%rsp), %rdi
callq 0x4210
leaq 0xc7(%rsp), %rdi
callq 0x43f0
jmp 0x5324
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x5312
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x5305
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x4210
leaq 0xc8(%rsp), %rdi
callq 0x4210
leaq 0xc7(%rsp), %rdi
callq 0x43f0
jmp 0x543d
movq 0x108(%rsp), %rsi
leaq 0x288(%rsp), %rdi
callq 0x9400
jmp 0x533b
jmp 0x53f2
leaq 0x37fde(%rip), %rsi     # 0x3d325
leaq 0x80(%rsp), %rdi
leaq 0x260(%rsp), %rdx
callq 0x9440
jmp 0x535e
leaq 0x37fd3(%rip), %rdx     # 0x3d338
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x93b0
jmp 0x537c
movl $0xff, %edi
leaq 0xa0(%rsp), %rsi
callq 0x49f0
jmp 0x5390
leaq 0xa0(%rsp), %rdi
callq 0x4210
leaq 0x80(%rsp), %rdi
callq 0x4210
jmp 0x53f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x53e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x4210
leaq 0x80(%rsp), %rdi
callq 0x4210
jmp 0x543d
jmp 0x53f4
jmp 0x53f6
jmp 0x53f8
jmp 0x53fa
jmp 0x53fc
movl $0x0, 0x144(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x4210
movl 0x144(%rsp), %eax
testl %eax, %eax
jne 0x54be
jmp 0x5425
jmp 0x5427
movl 0x284(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x284(%rsp)
jmp 0x4ad1
leaq 0x260(%rsp), %rdi
callq 0x4210
jmp 0x54da
movq 0x4ab7a(%rip), %rax     # 0x4ffd0
movq (%rax), %rsi
leaq 0x288(%rsp), %rdi
callq 0x90c0
jmp 0x5468
movq 0x4ab49(%rip), %rax     # 0x4ffb8
movq (%rax), %rsi
leaq 0x288(%rsp), %rdi
callq 0x90e0
jmp 0x5481
leaq 0x288(%rsp), %rdi
callq 0x9100
jmp 0x5490
movl $0x0, 0x334(%rsp)
movl $0x1, 0x144(%rsp)
jmp 0x54be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x54da
leaq 0x288(%rsp), %rdi
callq 0x9570
movl 0x334(%rsp), %eax
addq $0x338, %rsp            # imm = 0x338
retq
leaq 0x288(%rsp), %rdi
callq 0x9570
movq 0x250(%rsp), %rdi
callq 0x4660
nopw %cs:(%rax,%rax)
nop