// File: 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
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x3, -0x1c(%rbp)
jge 0x2328
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
xorl %edx, %edx
callq 0x1b50
testb $0x1, %al
jne 0x2215
jmp 0x225f
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
callq 0x1b50
testb $0x1, %al
jne 0x222c
jmp 0x225f
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
callq 0x1a90
testb $0x1, %al
jne 0x2243
jmp 0x225f
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
xorl %edx, %edx
callq 0x1b50
testb $0x1, %al
jne 0x2273
jmp 0x22bd
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
callq 0x1b50
testb $0x1, %al
jne 0x228a
jmp 0x22bd
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
callq 0x1a90
testb $0x1, %al
jne 0x22a1
jmp 0x22bd
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
callq 0x1b50
testb $0x1, %al
jne 0x22d4
jmp 0x2318
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
callq 0x1b50
testb $0x1, %al
jne 0x22eb
jmp 0x2318
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
xorl %edx, %edx
callq 0x1a90
testb $0x1, %al
jne 0x22ff
jmp 0x2318
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
jmp 0x231a
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x21f7
movl $0x0, -0x20(%rbp)
cmpl $0x3, -0x20(%rbp)
jge 0x2464
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl %esi, %esi
callq 0x1b50
testb $0x1, %al
jne 0x234d
jmp 0x2397
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x1, %esi
callq 0x1b50
testb $0x1, %al
jne 0x2364
jmp 0x2397
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x2, %esi
callq 0x1a90
testb $0x1, %al
jne 0x237b
jmp 0x2397
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl %esi, %esi
callq 0x1b50
testb $0x1, %al
jne 0x23ab
jmp 0x23f5
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x2, %esi
callq 0x1b50
testb $0x1, %al
jne 0x23c2
jmp 0x23f5
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x1, %esi
callq 0x1a90
testb $0x1, %al
jne 0x23d9
jmp 0x23f5
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x1, %esi
callq 0x1b50
testb $0x1, %al
jne 0x240c
jmp 0x2450
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x2, %esi
callq 0x1b50
testb $0x1, %al
jne 0x2423
jmp 0x2450
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl %esi, %esi
callq 0x1a90
testb $0x1, %al
jne 0x2437
jmp 0x2450
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl %ecx, %ecx
movl %ecx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
jmp 0x2452
jmp 0x2454
jmp 0x2456
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x232f
movq -0x18(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x2477
jmp 0x24be
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x248d
jmp 0x24be
movq -0x18(%rbp), %rdi
movl $0x2, %edx
movl %edx, %esi
callq 0x1a90
testb $0x1, %al
jne 0x24a3
jmp 0x24be
movq -0x18(%rbp), %rdi
movl $0x2, %edx
xorl %ecx, %ecx
movl %edx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x24d1
jmp 0x2518
movq -0x18(%rbp), %rdi
movl $0x2, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x24e7
jmp 0x2518
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1a90
testb $0x1, %al
jne 0x24fd
jmp 0x2518
movq -0x18(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
movl %edx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x252e
jmp 0x256f
movq -0x18(%rbp), %rdi
movl $0x2, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x2544
jmp 0x256f
movq -0x18(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x1a90
testb $0x1, %al
jne 0x2557
jmp 0x256f
movq -0x18(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1b50
testb $0x1, %al
jne 0x2585
jmp 0x25cc
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x259b
jmp 0x25cc
movq -0x18(%rbp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1a90
testb $0x1, %al
jne 0x25b1
jmp 0x25cc
movq -0x18(%rbp), %rdi
movl $0x2, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1b50
testb $0x1, %al
jne 0x25e2
jmp 0x2626
movq -0x18(%rbp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1b50
testb $0x1, %al
jne 0x25f8
jmp 0x2626
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1a90
testb $0x1, %al
jne 0x260e
jmp 0x2626
movq -0x18(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
movl %edx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x263c
jmp 0x2680
movq -0x18(%rbp), %rdi
movl $0x2, %edx
movl %edx, %esi
callq 0x1b50
testb $0x1, %al
jne 0x2652
jmp 0x2680
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1a90
testb $0x1, %al
jne 0x2668
jmp 0x2680
movq -0x18(%rbp), %rdi
xorl %ecx, %ecx
movl $0x2, %edx
movl %ecx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x268e
jmp 0x2682
jmp 0x2684
jmp 0x2686
jmp 0x2688
jmp 0x268a
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)