// File: /workspace/github_cpp_makefile_star2_O1/ATOMIC-LICHESS[P]ATOMKRAFT/simple_search.cpp
// Function: test_bestmove(Position&, int)
Move test_bestmove(Position& pos, int maxdepth) {
	Move bestmove = MOVE_NONE;
	

	
	
	
	MoveStack mlist[MAX_MOVES];
	StateInfo st;
	Move m;

	// Generate all legal moves
	MoveStack* last = generate<MV_LEGAL>(pos, mlist);
	
	
	for (int it_depth = 1; it_depth <= maxdepth; ++it_depth) {
	
		bool bSearchPv = true;
		int alpha = -100000;
		int beta  =  100000;
		int score = alpha;
		
		for (MoveStack* cur = mlist; cur != last; cur++) {
			m = cur->move;
			pos.do_move(m, st);
			if (bSearchPv) {
				score = -test_search(pos, -beta, -alpha, it_depth - 1);
			} else {
				score = -test_search(pos, -alpha-1, -alpha, it_depth - 1);
				if (score > alpha) // in fail-soft ... && score < beta ) is common
					score = -test_search(pos, -beta, -alpha, it_depth - 1); // re-search
			}
			pos.undo_move(m);
			
			if(score > alpha) {
				alpha = score; // alpha acts like max in MiniMax
				bestmove = m;
			}
			bSearchPv = false;
		}
		
		
		cout << it_depth << " " << move_to_uci(bestmove, 0) << " " << score << endl;
		
	}
	
	
	return bestmove;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8f8, %rsp            # imm = 0x8F8
movl %esi, %ebx
movq %rdi, %r14
leaq 0xf0(%rsp), %r13
movq %r13, %rsi
callq 0x1a0ce
movq %rax, 0x18(%rsp)
movl %ebx, 0x10(%rsp)
testl %ebx, %ebx
jle 0x28c9a
movl $0x1, %eax
movl $0x0, 0x8(%rsp)
movq %r14, 0x40(%rsp)
movq 0x40(%rsp), %rbp
cmpq 0x18(%rsp), %r13
movq %rax, 0x48(%rsp)
je 0x28bc8
decl %eax
movl %eax, 0xc(%rsp)
movb $0x1, %r15b
movl $0xfffe7960, %r12d      # imm = 0xFFFE7960
movq %r13, %r14
movl (%r14), %esi
movq %rbp, %rdi
movl %esi, 0x14(%rsp)
leaq 0x50(%rsp), %rdx
callq 0x1ef10
movl %r12d, %r13d
negl %r13d
testb $0x1, %r15b
jne 0x28b79
movl %r12d, %esi
notl %esi
movq %rbp, %rdi
movl %r13d, %edx
movl 0xc(%rsp), %ecx
callq 0x28cdf
movl %eax, %ebx
negl %ebx
cmpl %ebx, %r12d
jge 0x28b91
movq %rbp, %rdi
movl $0xfffe7960, %esi       # imm = 0xFFFE7960
movl %r13d, %edx
movl 0xc(%rsp), %ecx
callq 0x28cdf
movl %eax, %ebx
negl %ebx
movq %rbp, %rdi
movl 0x14(%rsp), %r15d
movl %r15d, %esi
callq 0x20056
cmpl %r12d, %ebx
cmovgl %ebx, %r12d
movl 0x8(%rsp), %eax
cmovgl %r15d, %eax
movl %eax, 0x8(%rsp)
addq $0x8, %r14
xorl %r15d, %r15d
cmpq 0x18(%rsp), %r14
jne 0x28b3c
jmp 0x28bcd
movl $0xfffe7960, %ebx       # imm = 0xFFFE7960
movq 0x133cc(%rip), %rdi     # 0x3bfa0
movq 0x48(%rsp), %r12
movl %r12d, %esi
callq 0x5760
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7a4d(%rip), %r14      # 0x30640
movq %r14, %rsi
callq 0x5460
leaq 0x20(%rsp), %rdi
movl 0x8(%rsp), %esi
xorl %edx, %edx
callq 0x17480
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r15, %rdi
callq 0x5460
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x5460
movq %r15, %rdi
movl %ebx, %esi
callq 0x5760
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x28c80
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5400
leal 0x1(%r12), %eax
cmpl 0x10(%rsp), %r12d
leaq 0xf0(%rsp), %r13
jne 0x28b1a
jmp 0x28ca2
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
addq $0x8f8, %rsp            # imm = 0x8F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x28cd7
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5400
movq %rbx, %rdi
callq 0x5790