// File: /workspace/github_cpp_makefile_star2_O3/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 0x2e54
movq 0xc3dd(%rip), %rbx      # 0xefa8
leaq 0x849e(%rip), %rsi      # 0xb070
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 0x846d(%rip), %rsi      # 0xb0a7
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 0x845d(%rip), %rsi      # 0xb0d5
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 0x844c(%rip), %rsi      # 0xb102
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 0x8431(%rip), %rsi      # 0xb125
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 0x8411(%rip), %rsi      # 0xb16d
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 0x8401(%rip), %rsi      # 0xb19b
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 0x83d5(%rip), %rsi      # 0xb1ad
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 0x83e8(%rip), %rsi      # 0xb1fe
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 0x2f14
movq %rsi, %rbx
movl %edi, %ebp
movq 0x8(%rsi), %rsi
movq 0x10(%rbx), %rdx
leaq 0x38(%rsp), %rdi
callq 0x3026
leaq 0x83c3(%rip), %rsi      # 0xb235
movq %rsp, %rdi
callq 0x31f4
leaq 0xea87(%rip), %rdi      # 0x11908
movq %rsp, %rsi
callq 0x2454
movq %rsp, %rdi
callq 0x3c10
movq 0x18(%rbx), %rdi
callq 0x2a02
movl %eax, %r14d
xorl %r15d, %r15d
testl %eax, %eax
cmovlel %r15d, %r14d
cmpl $0x4, %ebp
je 0x2ec1
movq 0x20(%rbx), %rsi
leaq 0x8388(%rip), %rdi      # 0xb23e
callq 0x2260
testl %eax, %eax
sete %r15b
movl %r14d, %esi
movzbl %r15b, %edx
leaq 0x38(%rsp), %rdi
callq 0x38a6
movl %eax, %ebx
movq 0xc0cd(%rip), %rdi      # 0xefa8
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 0x2f30
movq %rax, %rdi
callq 0x3c04
jmp 0x2f30
jmp 0x2f30
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x2f8b
movq %rbx, %rdi
callq 0x20d0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0xc098(%rip), %rdi      # 0xefe8
movq %rax, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movq 0xc041(%rip), %rdi      # 0xefa8
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2320
movq %rax, %rdi
callq 0x20f0
callq 0x22e0
jmp 0x2e4a
movq %rax, %rbx
callq 0x22e0
movq %rbx, %rdi
callq 0x2330
jmp 0x2f24
nop