// File: /workspace/github_cpp_makefile_star2_O1/t3nma[P]sdl2-TicTacToe/src/Bot.cpp
// Function: Bot::hard(Board&) const
bool Bot::hard(Board &board) const
{
    // can win on a row?
    for(int i=0; i<3; i++)
    {
        if(board.isFieldCircle(i,0) && board.isFieldCircle(i,1) && board.isFieldEmpty(i,2))
        {
            board.place(i,2,false);
            return true;
        }

        if(board.isFieldCircle(i,0) && board.isFieldCircle(i,2) && board.isFieldEmpty(i,1))
        {
            board.place(i,1,false);
            return true;
        }

        if(board.isFieldCircle(i,1) && board.isFieldCircle(i,2) && board.isFieldEmpty(i,0))
        {
            board.place(i,0,false);
            return true;
        }
    }

    // can win on a column?
    for(int j=0; j<3; j++)
    {
        if(board.isFieldCircle(0,j) && board.isFieldCircle(1,j) && board.isFieldEmpty(2,j))
        {
            board.place(2,j,false);
            return true;
        }
        else if(board.isFieldCircle(0,j) && board.isFieldCircle(2,j) && board.isFieldEmpty(1,j))
        {
            board.place(1,j,false);
            return true;
        }
        else if(board.isFieldCircle(1,j) && board.isFieldCircle(2,j) && board.isFieldEmpty(0,j))
        {
            board.place(0,j,false);
            return true;
        }
    }

    // can win on a diagonal?
    if(board.isFieldCircle(0,0) && board.isFieldCircle(1,1) && board.isFieldEmpty(2,2))
    {
        board.place(2,2,false);
        return true;
    }
    else if(board.isFieldCircle(0,0) && board.isFieldCircle(2,2) && board.isFieldEmpty(1,1))
    {
        board.place(1,1,false);
        return true;
    }
    else if(board.isFieldCircle(1,1) && board.isFieldCircle(2,2) && board.isFieldEmpty(0,0))
    {
        board.place(0,0,false);
        return true;
    }
    else if(board.isFieldCircle(0,2) && board.isFieldCircle(1,1) && board.isFieldEmpty(2,0))
    {
        board.place(2,0,false);
        return true;
    }
    else if(board.isFieldCircle(0,2) && board.isFieldCircle(2,0) && board.isFieldEmpty(1,1))
    {
        board.place(1,1,false);
        return true;
    }
    else if(board.isFieldCircle(1,1) && board.isFieldCircle(2,2) && board.isFieldEmpty(0,2))
    {
        board.place(0,2,false);
        return true;
    }

    return false; // no possible way to win
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x1782
testb %al, %al
je 0x1cfb
movq %rbx, %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x1782
testb %al, %al
je 0x1cfb
movl $0x2, %r15d
movq %rbx, %rdi
movl %r14d, %esi
movl $0x2, %edx
callq 0x1726
testb %al, %al
jne 0x1d90
movq %rbx, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x1782
testb %al, %al
je 0x1d3a
movq %rbx, %rdi
movl %r14d, %esi
movl $0x2, %edx
callq 0x1782
testb %al, %al
je 0x1d3a
movl $0x1, %r15d
movq %rbx, %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x1726
testb %al, %al
jne 0x1d90
movq %rbx, %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x1782
testb %al, %al
je 0x1d76
movq %rbx, %rdi
movl %r14d, %esi
movl $0x2, %edx
callq 0x1782
testb %al, %al
je 0x1d76
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x1726
testb %al, %al
jne 0x1d90
cmpl $0x2, %r14d
leal 0x1(%r14), %eax
setae %r12b
movl %eax, %r14d
cmpl $0x3, %eax
jne 0x1cb8
jmp 0x1dad
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x16e4
movb $0x1, %r14b
testb $0x1, %r12b
je 0x2065
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x1782
testb %al, %al
je 0x1df6
movq %rbx, %rdi
movl $0x1, %esi
movl %r14d, %edx
callq 0x1782
testb %al, %al
je 0x1df6
movl $0x2, %r15d
movq %rbx, %rdi
movl $0x2, %esi
movl %r14d, %edx
callq 0x1726
testb %al, %al
jne 0x1e8b
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x1782
testb %al, %al
je 0x1e35
movq %rbx, %rdi
movl $0x2, %esi
movl %r14d, %edx
callq 0x1782
testb %al, %al
je 0x1e35
movl $0x1, %r15d
movq %rbx, %rdi
movl $0x1, %esi
movl %r14d, %edx
callq 0x1726
testb %al, %al
jne 0x1e8b
movq %rbx, %rdi
movl $0x1, %esi
movl %r14d, %edx
callq 0x1782
testb %al, %al
je 0x1e71
movq %rbx, %rdi
movl $0x2, %esi
movl %r14d, %edx
callq 0x1782
testb %al, %al
je 0x1e71
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x1726
testb %al, %al
jne 0x1e8b
cmpl $0x2, %r14d
leal 0x1(%r14), %eax
setae %r12b
movl %eax, %r14d
cmpl $0x3, %eax
jne 0x1db3
jmp 0x1ea8
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x16e4
movb $0x1, %r14b
testb $0x1, %r12b
je 0x2065
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1782
testb %al, %al
je 0x1ef1
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x1782
testb %al, %al
je 0x1ef1
movq %rbx, %rdi
movl $0x2, %esi
movl $0x2, %edx
callq 0x1726
testb %al, %al
je 0x1ef1
movq %rbx, %rdi
movl $0x2, %esi
jmp 0x2051
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1782
testb %al, %al
je 0x1f31
movq %rbx, %rdi
movl $0x2, %esi
movl $0x2, %edx
callq 0x1782
testb %al, %al
je 0x1f31
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x1726
testb %al, %al
jne 0x1ffb
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x1782
testb %al, %al
je 0x1f74
movq %rbx, %rdi
movl $0x2, %esi
movl $0x2, %edx
callq 0x1782
testb %al, %al
je 0x1f74
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1726
testb %al, %al
je 0x1f74
movq %rbx, %rdi
xorl %esi, %esi
jmp 0x1fb8
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1782
testb %al, %al
je 0x1fbf
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x1782
testb %al, %al
je 0x1fbf
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1726
testb %al, %al
je 0x1fbf
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
jmp 0x2056
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1782
testb %al, %al
je 0x200a
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1782
testb %al, %al
je 0x200a
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x1726
testb %al, %al
je 0x200a
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
jmp 0x2056
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x1782
testb %al, %al
je 0x2062
movq %rbx, %rdi
movl $0x2, %esi
movl $0x2, %edx
callq 0x1782
testb %al, %al
je 0x2062
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1726
testb %al, %al
je 0x2065
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x16e4
movb $0x1, %r14b
jmp 0x2065
xorl %r14d, %r14d
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)