// File: /workspace/github_cpp_makefile_star2_O2/janthonyo[P]Redes-Practicas/funcionesServer.cc
// Function: canPutPiece(int, domino&)
bool canPutPiece(int i, domino& game)
{
    //Devuelve true si tienes piezas disponibles para colocar, false si no
    //i es el sd de quien envio el mensaje, tambien identificado como i en server.cc
    if(i==game.getSocketP1())
    {
        for (int j = 0; j < (int) game.getHand1().size(); j++) {
            //Comprueba si coincide first
            if(game.getFirst() == game.getHand1()[j].left)
            {
                return true;
            }
            if(game.getFirst() == game.getHand1()[j].right)
            {
                return true;
            }

            //Comprueba si coincide last
            if(game.getLast() == game.getHand1()[j].left)
            {
                return true;
            }
            if(game.getLast() == game.getHand1()[j].right)
            {
                return true;
            }
        }
    }

    else if(i==game.getSocketP2())
    {
        for (int j = 0; j < (int) game.getHand2().size(); j++) {
            //Comprueba si coincide first
            if(game.getFirst() == game.getHand2()[j].left)
            {
                return true;
            }
            if(game.getFirst() == game.getHand2()[j].right)
            {
                return true;
            }

            //Comprueba si coincide last
            if(game.getLast() == game.getHand2()[j].left)
            {
                return true;
            }
            if(game.getLast() == game.getHand2()[j].right)
            {
                return true;
            }
        }
    }

    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl %edi, 0x94(%rsi)
movq %rsi, -0x58(%rbp)
jne 0x6c2e
leaq 0x98(%rsi), %rax
movq %rax, -0x30(%rbp)
xorl %r13d, %r13d
leaq -0x50(%rbp), %r12
movq -0x58(%rbp), %r15
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
shrq $0x3, %rax
movslq %eax, %r14
movq %r12, %rdi
callq 0x4d28
cmpq %r14, %r13
setl %al
movl %eax, -0x34(%rbp)
jge 0x6d38
movl 0x130(%r15), %r14d
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x50(%rbp), %rax
movl (%rax,%r13,8), %ebx
movq %r12, %rdi
callq 0x4d28
cmpl %ebx, %r14d
je 0x6d38
movl 0x130(%r15), %ebx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x50(%rbp), %rax
movl 0x4(%rax,%r13,8), %r14d
movq %r12, %rdi
callq 0x4d28
cmpl %r14d, %ebx
je 0x6d38
movl 0x134(%r15), %ebx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x50(%rbp), %rax
movl (%rax,%r13,8), %r14d
movq %r12, %rdi
callq 0x4d28
cmpl %r14d, %ebx
je 0x6d38
movl 0x134(%r15), %ebx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x50(%rbp), %rax
movl 0x4(%rax,%r13,8), %r14d
movq %r12, %rdi
callq 0x4d28
incq %r13
cmpl %r14d, %ebx
jne 0x6b42
jmp 0x6d38
cmpl %edi, 0x114(%rsi)
jne 0x6d31
leaq 0x118(%rsi), %rax
movq %rax, -0x30(%rbp)
xorl %r13d, %r13d
leaq -0x50(%rbp), %r12
movq -0x58(%rbp), %r15
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
shrq $0x3, %rax
movslq %eax, %rbx
movq %r12, %rdi
callq 0x4d28
cmpq %rbx, %r13
setl %al
movl %eax, -0x34(%rbp)
jge 0x6d38
movl 0x130(%r15), %ebx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x50(%rbp), %rax
movl (%rax,%r13,8), %r14d
movq %r12, %rdi
callq 0x4d28
cmpl %r14d, %ebx
je 0x6d38
movl 0x130(%r15), %ebx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x50(%rbp), %rax
movl 0x4(%rax,%r13,8), %r14d
movq %r12, %rdi
callq 0x4d28
cmpl %r14d, %ebx
je 0x6d38
movl 0x134(%r15), %ebx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x50(%rbp), %rax
movl (%rax,%r13,8), %r14d
movq %r12, %rdi
callq 0x4d28
cmpl %r14d, %ebx
je 0x6d38
movl 0x134(%r15), %ebx
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x4b12
movq -0x50(%rbp), %rax
movl 0x4(%rax,%r13,8), %r14d
movq %r12, %rdi
callq 0x4d28
incq %r13
cmpl %r14d, %ebx
jne 0x6c50
jmp 0x6d38
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq