// File: t3nma[P]sdl2-TicTacToe/src/Bot.cpp
// Function: Bot::medium(Board&) const
bool Bot::medium(Board &board) const
{
    // can block a row?
    for(int i=0; i<3; i++)
    {
        if(board.isFieldCross(i,0) && board.isFieldCross(i,1) && board.isFieldEmpty(i,2))
        {
            board.place(i,2,false);
            return true;
        }

        if(board.isFieldCross(i,0) && board.isFieldCross(i,2) && board.isFieldEmpty(i,1))
        {
            board.place(i,1,false);
            return true;
        }

        if(board.isFieldCross(i,1) && board.isFieldCross(i,2) && board.isFieldEmpty(i,0))
        {
            board.place(i,0,false);
            return true;
        }
    }

    // can block a column?
    for(int j=0; j<3; j++)
    {
        if(board.isFieldCross(0,j) && board.isFieldCross(1,j) && board.isFieldEmpty(2,j))
        {
            board.place(2,j,false);
            return true;
        }
        else if(board.isFieldCross(0,j) && board.isFieldCross(2,j) && board.isFieldEmpty(1,j))
        {
            board.place(1,j,false);
            return true;
        }
        else if(board.isFieldCross(1,j) && board.isFieldCross(2,j) && board.isFieldEmpty(0,j))
        {
            board.place(0,j,false);
            return true;
        }
    }

    // can block a diagonal?
    if(board.isFieldCross(0,0) && board.isFieldCross(1,1) && board.isFieldEmpty(2,2))
    {
        board.place(2,2,false);
        return true;
    }
    else if(board.isFieldCross(0,0) && board.isFieldCross(2,2) && board.isFieldEmpty(1,1))
    {
        board.place(1,1,false);
        return true;
    }
    else if(board.isFieldCross(1,1) && board.isFieldCross(2,2) && board.isFieldEmpty(0,0))
    {
        board.place(0,0,false);
        return true;
    }
    else if(board.isFieldCross(0,2) && board.isFieldCross(1,1) && board.isFieldEmpty(2,0))
    {
        board.place(2,0,false);
        return true;
    }
    else if(board.isFieldCross(0,2) && board.isFieldCross(2,0) && board.isFieldEmpty(1,1))
    {
        board.place(1,1,false);
        return true;
    }
    else if(board.isFieldCross(1,1) && board.isFieldCross(2,0) && board.isFieldEmpty(0,2))
    {
        board.place(0,2,false);
        return true;
    }

    return false; // nothing to block
}

// 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 0x1e68
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
xorl %edx, %edx
callq 0x1af0
testb $0x1, %al
jne 0x1d55
jmp 0x1d9f
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
callq 0x1af0
testb $0x1, %al
jne 0x1d6c
jmp 0x1d9f
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
callq 0x1a90
testb $0x1, %al
jne 0x1d83
jmp 0x1d9f
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
xorl %edx, %edx
callq 0x1af0
testb $0x1, %al
jne 0x1db3
jmp 0x1dfd
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
callq 0x1af0
testb $0x1, %al
jne 0x1dca
jmp 0x1dfd
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
callq 0x1a90
testb $0x1, %al
jne 0x1de1
jmp 0x1dfd
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
callq 0x1af0
testb $0x1, %al
jne 0x1e14
jmp 0x1e58
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
callq 0x1af0
testb $0x1, %al
jne 0x1e2b
jmp 0x1e58
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
xorl %edx, %edx
callq 0x1a90
testb $0x1, %al
jne 0x1e3f
jmp 0x1e58
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
jmp 0x1e5a
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d37
movl $0x0, -0x20(%rbp)
cmpl $0x3, -0x20(%rbp)
jge 0x1fa4
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl %esi, %esi
callq 0x1af0
testb $0x1, %al
jne 0x1e8d
jmp 0x1ed7
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x1, %esi
callq 0x1af0
testb $0x1, %al
jne 0x1ea4
jmp 0x1ed7
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x2, %esi
callq 0x1a90
testb $0x1, %al
jne 0x1ebb
jmp 0x1ed7
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl %esi, %esi
callq 0x1af0
testb $0x1, %al
jne 0x1eeb
jmp 0x1f35
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x2, %esi
callq 0x1af0
testb $0x1, %al
jne 0x1f02
jmp 0x1f35
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x1, %esi
callq 0x1a90
testb $0x1, %al
jne 0x1f19
jmp 0x1f35
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x1, %esi
callq 0x1af0
testb $0x1, %al
jne 0x1f4c
jmp 0x1f90
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x2, %esi
callq 0x1af0
testb $0x1, %al
jne 0x1f63
jmp 0x1f90
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl %esi, %esi
callq 0x1a90
testb $0x1, %al
jne 0x1f77
jmp 0x1f90
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl %ecx, %ecx
movl %ecx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
jmp 0x1f92
jmp 0x1f94
jmp 0x1f96
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1e6f
movq -0x18(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x1af0
testb $0x1, %al
jne 0x1fb7
jmp 0x1ffe
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1af0
testb $0x1, %al
jne 0x1fcd
jmp 0x1ffe
movq -0x18(%rbp), %rdi
movl $0x2, %edx
movl %edx, %esi
callq 0x1a90
testb $0x1, %al
jne 0x1fe3
jmp 0x1ffe
movq -0x18(%rbp), %rdi
movl $0x2, %edx
xorl %ecx, %ecx
movl %edx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x1af0
testb $0x1, %al
jne 0x2011
jmp 0x2058
movq -0x18(%rbp), %rdi
movl $0x2, %edx
movl %edx, %esi
callq 0x1af0
testb $0x1, %al
jne 0x2027
jmp 0x2058
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1a90
testb $0x1, %al
jne 0x203d
jmp 0x2058
movq -0x18(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
movl %edx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1af0
testb $0x1, %al
jne 0x206e
jmp 0x20af
movq -0x18(%rbp), %rdi
movl $0x2, %edx
movl %edx, %esi
callq 0x1af0
testb $0x1, %al
jne 0x2084
jmp 0x20af
movq -0x18(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x1a90
testb $0x1, %al
jne 0x2097
jmp 0x20af
movq -0x18(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1af0
testb $0x1, %al
jne 0x20c5
jmp 0x210c
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1af0
testb $0x1, %al
jne 0x20db
jmp 0x210c
movq -0x18(%rbp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1a90
testb $0x1, %al
jne 0x20f1
jmp 0x210c
movq -0x18(%rbp), %rdi
movl $0x2, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1af0
testb $0x1, %al
jne 0x2122
jmp 0x2166
movq -0x18(%rbp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1af0
testb $0x1, %al
jne 0x2138
jmp 0x2166
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1a90
testb $0x1, %al
jne 0x214e
jmp 0x2166
movq -0x18(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
movl %edx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
movq -0x18(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x1af0
testb $0x1, %al
jne 0x217c
jmp 0x21c0
movq -0x18(%rbp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1af0
testb $0x1, %al
jne 0x2192
jmp 0x21c0
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1a90
testb $0x1, %al
jne 0x21a8
jmp 0x21c0
movq -0x18(%rbp), %rdi
xorl %ecx, %ecx
movl $0x2, %edx
movl %ecx, %esi
callq 0x1a10
movb $0x1, -0x1(%rbp)
jmp 0x21ce
jmp 0x21c2
jmp 0x21c4
jmp 0x21c6
jmp 0x21c8
jmp 0x21ca
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)