// File: /workspace/github_cpp_makefile_star2_O1/smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::GetMaxValue(int, long, long)
int64_t   ChessBoard::  GetMaxValue(int deep, int64_t alpha, int64_t beta)
{
    int64_t bestVa = MM_MIN;
    std::vector<StPos>   nextList;
    int64_t va = MM_MIN;
    int win = 0;
    va = CalculateBoard(m_aiside, win, false );
    if( deep <= 0  || win )
    {
        return va;
    }
    
    int n = GetPossbilePos( m_aiside, nextList);
    for( int i=0; i<nextList.size(); i++ )
    {
        PutChess(nextList[i].x, nextList[i].y, m_aiside);
        nextList[i].score = CalculateOnePos(nextList[i].x, nextList[i].y,
                m_aiside, 0);
        UnPutChess(nextList[i].x, nextList[i].y);
    }
    sort(nextList.begin(), nextList.end(), greater<StPos>()   );    

    for( int i=0; i< nextList.size(); i++ )
    {
        StPos pos = nextList[i];
        PutChess(pos.x, pos.y, m_aiside  ); 
        win = 0; 
        va =  GetMinValue(deep-1, alpha , beta);
        UnPutChess(pos.x, pos.y);
        
        if(va  >  bestVa)  
        {
            bestVa = va;
        }
        if(va >   alpha )
            alpha = va;
        if( alpha >= beta) 
            break;
    }
    return bestVa;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, -0x68(%rbp)
movq %rdx, -0x60(%rbp)
movl %esi, %ebx
movq %rdi, %r12
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
leaq -0x2c(%rbp), %rdx
movl $0x0, (%rdx)
movsbl 0x198(%rdi), %esi
xorl %ecx, %ecx
callq 0x2d14
movq %rax, %r14
movl %ebx, -0x30(%rbp)
testl %ebx, %ebx
jle 0x38a8
cmpl $0x0, -0x2c(%rbp)
jne 0x38a8
movsbl 0x198(%r12), %esi
leaq -0x50(%rbp), %rdx
movq %r12, %rdi
callq 0x2a7c
movq -0x50(%rbp), %r13
movq -0x48(%rbp), %r15
movq %r15, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
subq %r13, %rax
je 0x3776
leaq 0x4(%r12), %rax
movq %rax, -0x58(%rbp)
movl $0x4, %r14d
xorl %ebx, %ebx
movl -0x4(%r13,%r14), %esi
movl (%r13,%r14), %edx
movsbl 0x198(%r12), %ecx
movq %r12, %rdi
callq 0x128e
movq -0x50(%rbp), %r15
movl -0x4(%r15,%r14), %esi
movl (%r15,%r14), %edx
movsbl 0x198(%r12), %ecx
movq %r12, %rdi
xorl %r8d, %r8d
callq 0x2c02
movq %rax, 0x4(%r15,%r14)
movslq -0x4(%r15,%r14), %rax
movslq (%r15,%r14), %rcx
leaq (%rax,%rax,4), %rax
movq -0x58(%rbp), %rdx
leaq (%rdx,%rax,4), %rax
movb $0x65, (%rcx,%rax)
addq $-0x18, 0x248(%r12)
decl (%r12)
incq %rbx
movq -0x50(%rbp), %r13
movq -0x48(%rbp), %r15
movq %r15, %rax
subq %r13, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %r14
cmpq %rbx, %rax
ja 0x36dd
jmp 0x377e
sarq $0x3, %rax
imulq %rcx, %rax
cmpq %r15, %r13
je 0x37a6
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x3bb0
movq %r13, %rdi
movq %r15, %rsi
callq 0x3cdb
movl -0x2c(%rbp), %r13d
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x3898
decl -0x30(%rbp)
leaq 0x4(%r12), %rcx
movq %rcx, -0x70(%rbp)
movq $-0x77359400, %r14      # imm = 0x88CA6C00
movl $0x4, %esi
xorl %edi, %edi
movq %rdi, -0x80(%rbp)
movq %r14, -0x58(%rbp)
movl -0x4(%rax,%rsi), %r15d
movq %rsi, -0x78(%rbp)
movl (%rax,%rsi), %ebx
movsbl 0x198(%r12), %ecx
movq %r12, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0x128e
movq -0x68(%rbp), %rcx
movq %r12, %r14
movq -0x60(%rbp), %r12
xorl %r13d, %r13d
movq %r14, %rdi
movl -0x30(%rbp), %esi
movq %r12, %rdx
callq 0x3388
movq -0x68(%rbp), %rdi
movslq %r15d, %rcx
movslq %ebx, %rdx
leaq (%rcx,%rcx,4), %rcx
movq -0x70(%rbp), %rsi
leaq (%rsi,%rcx,4), %rcx
movb $0x65, (%rdx,%rcx)
addq $-0x18, 0x248(%r14)
movq %r14, %rdx
decl (%r14)
movq -0x58(%rbp), %r14
cmpq %r14, %rax
cmovgq %rax, %r14
cmpq %r12, %rax
cmovgq %rax, %r12
cmpq %rdi, %r12
movq -0x80(%rbp), %rdi
jge 0x38a1
movq %r12, -0x60(%rbp)
incq %rdi
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rcx
movq -0x78(%rbp), %rsi
addq $0x18, %rsi
xorl %r13d, %r13d
cmpq %rdi, %rcx
movq %rdx, %r12
ja 0x37d2
jmp 0x38a4
movq $-0x77359400, %r14      # imm = 0x88CA6C00
jmp 0x38a4
xorl %r13d, %r13d
movl %r13d, -0x2c(%rbp)
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x38bd
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10a0
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x38d1
movq %rax, %rbx
jmp 0x38dd
movq %rax, %rbx
movl %r13d, -0x2c(%rbp)
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x38f2
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10a0
movq %rbx, %rdi
callq 0x10e0