// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x4068, %rsp           # imm = 0x4068
cmpl $0x3, %edi
jg 0x2972
movq 0xd712(%rip), %rdi      # 0xffa0
leaq 0x87ab(%rip), %rsi      # 0xb040
callq 0x21b0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
leaq 0x87c6(%rip), %rsi      # 0xb077
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
leaq 0x87dd(%rip), %rsi      # 0xb0a5
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
leaq 0x87f3(%rip), %rsi      # 0xb0d2
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
leaq 0x87ff(%rip), %rsi      # 0xb0f5
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
leaq 0x8828(%rip), %rsi      # 0xb13d
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
leaq 0x883f(%rip), %rsi      # 0xb16b
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
leaq 0x883a(%rip), %rsi      # 0xb17d
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
leaq 0x8874(%rip), %rsi      # 0xb1ce
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
pushq $-0x1
popq %rbx
jmp 0x2a13
movq %rsi, %rbx
movl %edi, %ebp
movq 0x8(%rsi), %rsi
movq 0x10(%rbx), %rdx
leaq 0x38(%rsp), %rdi
callq 0x2b64
leaq 0x8875(%rip), %rsi      # 0xb205
movq %rsp, %rdi
callq 0x2d34
leaq 0xff49(%rip), %rdi      # 0x128e8
movq %rsp, %r14
movq %r14, %rsi
callq 0x414a
movq %r14, %rdi
callq 0x331e
movq 0x18(%rbx), %rdi
callq 0x26d9
movl %eax, %r14d
xorl %r15d, %r15d
testl %eax, %eax
cmovlel %r15d, %r14d
cmpl $0x4, %ebp
je 0x29e2
movq 0x20(%rbx), %rsi
leaq 0x8837(%rip), %rdi      # 0xb20e
callq 0x2230
testl %eax, %eax
sete %r15b
movl %r14d, %esi
movzbl %r15b, %edx
leaq 0x38(%rsp), %rdi
callq 0x30b0
movl %eax, %ebp
movq 0xd5a4(%rip), %rdi      # 0xffa0
movl %eax, %esi
callq 0x22e0
movq %rax, %rdi
callq 0x2100
xorl %ebx, %ebx
testb %r15b, %r15b
cmovnel %ebp, %ebx
movl %ebx, %eax
addq $0x4068, %rsp           # imm = 0x4068
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a29
jmp 0x2a29
jmp 0x2a29
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x2a81
movq %rbx, %rdi
callq 0x20c0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0xd59f(%rip), %rdi      # 0xffe8
movq %rax, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
movq 0xd540(%rip), %rdi      # 0xffa0
pushq $-0x1
popq %rbx
movl %ebx, %esi
callq 0x22e0
movq %rax, %rdi
callq 0x2100
callq 0x22a0
jmp 0x2a13
movq %rax, %rbx
callq 0x22a0
movq %rbx, %rdi
callq 0x22f0
movq %rax, %rdi
callq 0x32e9