// File: /workspace/github_cpp_makefile_star2_O1/smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::GetNextPosMinMax(int, StPos&, long, long)
int64_t ChessBoard::GetNextPosMinMax(int deep, StPos &pos, int64_t alpha , int64_t beta )
{
    int64_t bestVa = MM_MIN;
    std::vector<StPos>   nextList;
    std::vector<StPos>   bestList;

    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 );
        //printf("Pos(%u %u), socre:%u \n", nextList[i].x, nextList[i].y ,nextList[i].score );
    }
    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  ); 
        int win = 0; 
        int64_t va = GetMinValue(deep-1, alpha ,beta) ;
        UnPutChess(pos.x, pos.y);

        if(bestVa <  va)
        {
            bestVa = va;
            bestList.clear();
            bestList.push_back(pos);
        }
        if( va == bestVa)
        {
            bestList.push_back(pos);
        }
        if(va > alpha )
            alpha = va;
        if( alpha >= beta) 
            break;
    }

    for(int i=0 ; i< bestList.size(); i++ )
    {
        PutChess( bestList[i].x, bestList[i].y, m_aiside);
        bestList[i].score = CalculateOnePos( bestList[i].x , bestList[i].y , m_aiside, 0 ); 
        UnPutChess(bestList[i].x, bestList[i].y );
        printf("select pos(%u %u) score:%d , mapVar:%d\n",bestList[i].x ,bestList[i].y, bestList[i].score, bestVa );
    }
    sort(bestList.begin(),   bestList.end(), greater<StPos>()  );
    if(bestList.size() > 0  )
    {
        pos.x = bestList[0].x;
        pos.y = bestList[0].y;
        return 0;    
    }
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, -0xa8(%rbp)
movq %rcx, -0x58(%rbp)
movq %rdx, -0xb0(%rbp)
movl %esi, -0x5c(%rbp)
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rdx
movaps %xmm0, (%rdx)
xorl %eax, %eax
movq %rax, 0x10(%rdx)
movq %rax, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movsbl 0x198(%rdi), %esi
callq 0x2a7c
movq -0x80(%rbp), %rbx
movq -0x78(%rbp), %r13
movq %r13, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
subq %rbx, %rax
je 0x3027
leaq 0x4(%r14), %rax
movq %rax, -0x30(%rbp)
movl $0x4, %r15d
xorl %r12d, %r12d
movl -0x4(%rbx,%r15), %esi
movl (%rbx,%r15), %edx
movsbl 0x198(%r14), %ecx
movq %r14, %rdi
callq 0x128e
movq -0x80(%rbp), %rbx
movl -0x4(%rbx,%r15), %esi
movl (%rbx,%r15), %edx
movsbl 0x198(%r14), %ecx
movq %r14, %rdi
xorl %r8d, %r8d
callq 0x2c02
movq %rax, 0x4(%rbx,%r15)
movslq -0x4(%rbx,%r15), %rax
movslq (%rbx,%r15), %rcx
leaq (%rax,%rax,4), %rax
movq -0x30(%rbp), %rdx
leaq (%rdx,%rax,4), %rax
movb $0x65, (%rcx,%rax)
addq $-0x18, 0x248(%r14)
decl (%r14)
incq %r12
movq -0x80(%rbp), %rbx
movq -0x78(%rbp), %r13
movq %r13, %rax
subq %rbx, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %r15
cmpq %r12, %rax
ja 0x2f93
jmp 0x302f
sarq $0x3, %rax
imulq %rcx, %rax
cmpq %r13, %rbx
je 0x3057
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3bb0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3cdb
movq -0x80(%rbp), %rax
cmpq %rax, -0x78(%rbp)
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
je 0x31cf
decl -0x5c(%rbp)
leaq 0x4(%r14), %rcx
movq %rcx, -0xb8(%rbp)
movq $-0x77359400, -0x30(%rbp) # imm = 0x88CA6C00
xorl %r15d, %r15d
xorl %r13d, %r13d
movups (%rax,%r15), %xmm0
movaps %xmm0, -0xa0(%rbp)
movq 0x10(%rax,%r15), %rax
movq %rax, -0x90(%rbp)
movl -0xa0(%rbp), %esi
movl -0x9c(%rbp), %edx
movsbl 0x198(%r14), %ecx
movq %r14, %rdi
callq 0x128e
movq %r14, %rdi
movl -0x5c(%rbp), %esi
movq -0x58(%rbp), %rdx
movq -0xa8(%rbp), %rcx
callq 0x3388
movq %rax, %rbx
movslq -0xa0(%rbp), %rax
movslq -0x9c(%rbp), %rcx
leaq (%rax,%rax,4), %rax
movq -0xb8(%rbp), %rdx
leaq (%rdx,%rax,4), %rax
movb $0x65, (%rcx,%rax)
addq $-0x18, 0x248(%r14)
decl (%r14)
cmpq %rbx, -0x30(%rbp)
jge 0x3156
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x3118
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x3142
movq -0x90(%rbp), %rax
movq %rax, 0x10(%rsi)
movaps -0xa0(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, -0x48(%rbp)
movq %rbx, -0x30(%rbp)
jmp 0x3156
leaq -0x50(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x3a1a
movq %rbx, -0x30(%rbp)
cmpq -0x30(%rbp), %rbx
jne 0x3192
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x3182
movq -0x90(%rbp), %rax
movq %rax, 0x10(%rsi)
movaps -0xa0(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, -0x48(%rbp)
jmp 0x3192
leaq -0x50(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x3a1a
movq -0x58(%rbp), %rax
cmpq %rax, %rbx
cmovgq %rbx, %rax
movq %rax, -0x58(%rbp)
cmpq -0xa8(%rbp), %rax
jge 0x31d7
incq %r13
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
addq $0x18, %r15
cmpq %r13, %rcx
ja 0x308b
jmp 0x31d7
movq $-0x77359400, -0x30(%rbp) # imm = 0x88CA6C00
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r12
movq %r12, %rax
subq %rbx, %rax
je 0x32b0
leaq 0x4(%r14), %rax
movq %rax, -0x58(%rbp)
movl $0x4, %r15d
xorl %r13d, %r13d
movl -0x4(%rbx,%r15), %esi
movl (%rbx,%r15), %edx
movsbl 0x198(%r14), %ecx
movq %r14, %rdi
callq 0x128e
movq -0x50(%rbp), %rbx
movl -0x4(%rbx,%r15), %esi
movl (%rbx,%r15), %edx
movsbl 0x198(%r14), %ecx
movq %r14, %rdi
xorl %r8d, %r8d
callq 0x2c02
movq %rax, 0x4(%rbx,%r15)
movslq -0x4(%rbx,%r15), %rax
movslq (%rbx,%r15), %rcx
leaq (%rax,%rax,4), %rax
movq -0x58(%rbp), %rdx
leaq (%rdx,%rax,4), %rax
movb $0x65, (%rcx,%rax)
addq $-0x18, 0x248(%r14)
decl (%r14)
movl -0x4(%rbx,%r15), %esi
movl (%rbx,%r15), %edx
movq 0x4(%rbx,%r15), %rcx
leaq 0x1de5(%rip), %rdi      # 0x5058
movq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x1030
incq %r13
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r12
movq %r12, %rax
subq %rbx, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %r15
cmpq %r13, %rax
ja 0x31fc
jmp 0x32c2
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq %r12, %rbx
je 0x32ea
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3bb0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3cdb
movq -0x50(%rbp), %rdi
cmpq %rdi, -0x48(%rbp)
je 0x3309
movl (%rdi), %eax
movq -0xb0(%rbp), %rcx
movl %eax, (%rcx)
movl 0x4(%rdi), %eax
movl %eax, 0x4(%rcx)
xorl %ebx, %ebx
jmp 0x3310
movq $-0x1, %rbx
testq %rdi, %rdi
je 0x3321
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10a0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x3336
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10a0
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3353
jmp 0x3353
jmp 0x3353
jmp 0x3353
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x336b
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x10a0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x3380
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10a0
movq %rbx, %rdi
callq 0x10e0