// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rsi, %rbx
cmpl %edi, 0x94(%rsi)
movq %rsi, -0x48(%rbp)
jne 0x8507
leaq 0x98(%rbx), %r14
xorl %eax, %eax
movq %rax, %r13
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %r15
testq %r12, %r12
je 0x8405
movq -0x30(%rbp), %rsi
subq %r12, %rsi
movq %r12, %rdi
callq 0x21f0
subq %r12, %r15
shrq $0x3, %r15
movslq %r15d, %r12
cmpq %r12, %r13
jge 0x8643
movl 0x130(%rbx), %r15d
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %rdi
movl (%rdi,%r13,8), %ebx
testq %rdi, %rdi
je 0x8444
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpl %ebx, %r15d
movq -0x48(%rbp), %rax
je 0x863c
movl 0x130(%rax), %r15d
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %rdi
movl 0x4(%rdi,%r13,8), %ebx
testq %rdi, %rdi
je 0x847e
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpl %ebx, %r15d
movq -0x48(%rbp), %rax
je 0x863c
movl 0x134(%rax), %r15d
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %rdi
movl (%rdi,%r13,8), %ebx
testq %rdi, %rdi
je 0x84b7
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpl %ebx, %r15d
movq -0x48(%rbp), %rax
je 0x863c
movl 0x134(%rax), %r15d
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %rdi
movl 0x4(%rdi,%r13,8), %ebx
testq %rdi, %rdi
je 0x84f1
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
leaq 0x1(%r13), %rax
cmpl %ebx, %r15d
movq -0x48(%rbp), %rbx
jne 0x83da
jmp 0x863c
cmpl %edi, 0x114(%rbx)
jne 0x8643
leaq 0x118(%rbx), %r14
xorl %eax, %eax
movq %rax, %r13
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %r15
testq %r12, %r12
je 0x8547
movq -0x30(%rbp), %rsi
subq %r12, %rsi
movq %r12, %rdi
callq 0x21f0
subq %r12, %r15
shrq $0x3, %r15
movslq %r15d, %r12
cmpq %r12, %r13
jge 0x8643
movl 0x130(%rbx), %r15d
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %rdi
movl (%rdi,%r13,8), %ebx
testq %rdi, %rdi
je 0x8586
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpl %ebx, %r15d
movq -0x48(%rbp), %rax
je 0x863c
movl 0x130(%rax), %r15d
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %rdi
movl 0x4(%rdi,%r13,8), %ebx
testq %rdi, %rdi
je 0x85c0
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpl %ebx, %r15d
movq -0x48(%rbp), %rax
je 0x863c
movl 0x134(%rax), %r15d
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %rdi
movl (%rdi,%r13,8), %ebx
testq %rdi, %rdi
je 0x85f5
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpl %ebx, %r15d
movq -0x48(%rbp), %rax
je 0x863c
movl 0x134(%rax), %r15d
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x52c4
movq -0x40(%rbp), %rdi
movl 0x4(%rdi,%r13,8), %ebx
testq %rdi, %rdi
je 0x862b
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21f0
leaq 0x1(%r13), %rax
cmpl %ebx, %r15d
movq -0x48(%rbp), %rbx
jne 0x851c
movb $0x1, %al
cmpq %r12, %r13
jl 0x8645
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq