// File: YSRKEN[P]Shioi/I401/main.cpp
// Function: main
int main(int argc, char *argv[]) {
	// Read arguments
	if (argc < 4) {
		cout << "Usage: I401 [board_text] [turn_text] [depth] (--debug)" << endl
			<< endl
			<< "board_text     : board data of stone or blank" << endl
			<< "turn_text      : turn data of stone or blank" << endl
			<< "depth          : depth of thinking" << endl
			<< R"(--debug(opt)   : put debug info to std::err if this string is "--debug")" << endl
			<< endl
			<< "stone or blank : black(*), white(O), blank(-)" << endl
			<< "return value   : " << endl
			<< R"(    When you specify "--debug", return >=0[move] | -1[can't move] | -2[give up].)" << endl
			<< "    On the other case, return 0[no error] or -1[error]" << endl;
		return -1;
	}
	try {
		Board board(argv[1], argv[2]);
		//board.Test();
		book = BookDB("book.csv");
		const int depth = argv[3] | to_i() | max(0);
		const bool is_debug = (5 <= argc && 0 == std::strcmp("--debug", argv[4]));
		const auto move = board.NextMove(depth, is_debug);
		cout << move << endl;
		if (is_debug) return move;
//		cout << PositionToString(move) << endl;
	}
	catch (const std::exception& er) {
		std::cerr << er.what() << endl;
		cout << -1 << endl;
		return -1;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40f0, %rsp           # imm = 0x40F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x2d9f
movq 0x24336(%rip), %rdi     # 0x26fa0
leaq 0x1b3bb(%rip), %rsi     # 0x1e02c
callq 0x21f0
movq %rax, %rdi
movq 0x24308(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
movq 0x242f9(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
leaq 0x1b3c5(%rip), %rsi     # 0x1e063
callq 0x21f0
movq %rax, %rdi
movq 0x242db(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
leaq 0x1b3d5(%rip), %rsi     # 0x1e091
callq 0x21f0
movq %rax, %rdi
movq 0x242bd(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
leaq 0x1b3e4(%rip), %rsi     # 0x1e0be
callq 0x21f0
movq %rax, %rdi
movq 0x2429f(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
leaq 0x1b3e9(%rip), %rsi     # 0x1e0e1
callq 0x21f0
movq %rax, %rdi
movq 0x24281(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
movq 0x24272(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
leaq 0x1b404(%rip), %rsi     # 0x1e129
callq 0x21f0
movq %rax, %rdi
movq 0x24254(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
leaq 0x1b414(%rip), %rsi     # 0x1e157
callq 0x21f0
movq %rax, %rdi
movq 0x24236(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
leaq 0x1b408(%rip), %rsi     # 0x1e169
callq 0x21f0
movq %rax, %rdi
movq 0x24218(%rip), %rsi     # 0x26f88
callq 0x2220
movq %rax, %rdi
leaq 0x1b43b(%rip), %rsi     # 0x1e1ba
callq 0x21f0
movq %rax, %rdi
movq 0x241fa(%rip), %rsi     # 0x26f88
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3010
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
leaq -0x4040(%rbp), %rdi
callq 0x33e0
jmp 0x2db9
leaq 0x1b431(%rip), %rsi     # 0x1e1f1
leaq -0x4088(%rbp), %rdi
callq 0x3aa0
jmp 0x2dce
leaq 0x26b5b(%rip), %rdi     # 0x29930
leaq -0x4088(%rbp), %rsi
movq %rsi, -0x40c0(%rbp)
callq 0x40a0
movq -0x40c0(%rbp), %rdi
callq 0x33c0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40b8(%rbp)
callq 0x4100
jmp 0x2e0a
movq -0x40b8(%rbp), %rdi
callq 0x2980
movl %eax, -0x40c4(%rbp)
jmp 0x2e1e
movl -0x40c4(%rbp), %eax
movl %eax, -0x4090(%rbp)
movl $0x0, -0x409c(%rbp)
leaq -0x409c(%rbp), %rdi
callq 0x4110
movl %eax, -0x40c8(%rbp)
jmp 0x2e48
movl -0x40c8(%rbp), %eax
movl %eax, -0x4098(%rbp)
leaq -0x4090(%rbp), %rdi
leaq -0x4098(%rbp), %rsi
callq 0x40d0
movl %eax, -0x40cc(%rbp)
jmp 0x2e6f
movl -0x40cc(%rbp), %eax
movl %eax, -0x408c(%rbp)
xorl %eax, %eax
movl $0x5, %ecx
cmpl -0x8(%rbp), %ecx
movb %al, -0x40cd(%rbp)
jg 0x2eb0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0x1b35e(%rip), %rdi     # 0x1e1fa
callq 0x22b0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
sete %al
movb %al, -0x40cd(%rbp)
movb -0x40cd(%rbp), %al
andb $0x1, %al
movb %al, -0x409d(%rbp)
movslq -0x408c(%rbp), %rsi
movzbl -0x409d(%rbp), %edx
andl $0x1, %edx
leaq -0x4040(%rbp), %rdi
callq 0x4130
movl %eax, -0x40d4(%rbp)
jmp 0x2ee3
movl -0x40d4(%rbp), %eax
movl %eax, -0x40a4(%rbp)
movl -0x40a4(%rbp), %esi
movq 0x240a4(%rip), %rdi     # 0x26fa0
callq 0x2360
movq %rax, -0x40e0(%rbp)
jmp 0x2f0a
movq -0x40e0(%rbp), %rdi
movq 0x24070(%rip), %rsi     # 0x26f88
callq 0x2220
jmp 0x2f1f
testb $0x1, -0x409d(%rbp)
je 0x2fec
movl -0x40a4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3010
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x4048(%rbp)
movl %eax, -0x404c(%rbp)
movl -0x404c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x301c
movq -0x4048(%rbp), %rdi
callq 0x20d0
movq %rax, -0x40b0(%rbp)
movq -0x40b0(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, %rsi
movq 0x2405c(%rip), %rdi     # 0x26fe8
callq 0x21f0
movq %rax, -0x40e8(%rbp)
jmp 0x2f9a
movq -0x40e8(%rbp), %rdi
movq 0x23fe0(%rip), %rsi     # 0x26f88
callq 0x2220
jmp 0x2faf
movq 0x23fea(%rip), %rdi     # 0x26fa0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2360
movq %rax, -0x40f0(%rbp)
jmp 0x2fc9
movq -0x40f0(%rbp), %rdi
movq 0x23fb1(%rip), %rsi     # 0x26f88
callq 0x2220
jmp 0x2fde
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
callq 0x2320
jmp 0x3010
jmp 0x3009
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x4048(%rbp)
movl %eax, -0x404c(%rbp)
callq 0x2320
jmp 0x3007
jmp 0x301c
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40f0, %rsp           # imm = 0x40F0
popq %rbp
retq
movq -0x4048(%rbp), %rdi
callq 0x2370
movq %rax, %rdi
callq 0x46a0