// File: /workspace/github_cpp_makefile_star2_O1/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 0x2e7e
movq 0xd3b3(%rip), %rbx      # 0xffa8
leaq 0x9444(%rip), %rsi      # 0xc040
movl $0x36, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x9413(%rip), %rsi      # 0xc077
movl $0x2d, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x9403(%rip), %rsi      # 0xc0a5
movl $0x2c, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x93f2(%rip), %rsi      # 0xc0d2
movl $0x22, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x93d7(%rip), %rsi      # 0xc0f5
movl $0x47, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x93b7(%rip), %rsi      # 0xc13d
movl $0x2d, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x93a7(%rip), %rsi      # 0xc16b
movl $0x11, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x937b(%rip), %rsi      # 0xc17d
movl $0x50, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x938e(%rip), %rsi      # 0xc1ce
movl $0x36, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2f3e
movq %rsi, %rbx
movl %edi, %ebp
movq 0x8(%rsi), %rsi
movq 0x10(%rbx), %rdx
leaq 0x38(%rsp), %rdi
callq 0x3050
leaq 0x9369(%rip), %rsi      # 0xc205
movq %rsp, %rdi
callq 0x31f8
leaq 0xfa5d(%rip), %rdi      # 0x12908
movq %rsp, %rsi
callq 0x245a
movq %rsp, %rdi
callq 0x3c20
movq 0x18(%rbx), %rdi
callq 0x2a2c
movl %eax, %r14d
xorl %r15d, %r15d
testl %eax, %eax
cmovlel %r15d, %r14d
cmpl $0x4, %ebp
je 0x2eeb
movq 0x20(%rbx), %rsi
leaq 0x932e(%rip), %rdi      # 0xc20e
callq 0x2260
testl %eax, %eax
sete %r15b
movl %r14d, %esi
movzbl %r15b, %edx
leaq 0x38(%rsp), %rdi
callq 0x38da
movl %eax, %ebx
movq 0xd0a3(%rip), %rdi      # 0xffa8
movl %eax, %esi
callq 0x2320
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
xorl %eax, %eax
testb %r15b, %r15b
cmovnel %ebx, %eax
addq $0x4068, %rsp           # imm = 0x4068
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f5a
movq %rax, %rdi
callq 0x3c14
jmp 0x2f5a
jmp 0x2f5a
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x2fb5
movq %rbx, %rdi
callq 0x20d0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0xd06e(%rip), %rdi      # 0xffe8
movq %rax, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movq 0xd017(%rip), %rdi      # 0xffa8
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2320
movq %rax, %rdi
callq 0x20f0
callq 0x22e0
jmp 0x2e74
movq %rax, %rbx
callq 0x22e0
movq %rbx, %rdi
callq 0x2330
jmp 0x2f4e
nop