// File: /workspace/github_cpp_makefile_star2_O2/nesro[P]NCursesGomoku/src/client.cpp
// Function: CClient::nextMove()
void CClient::nextMove(void) {
    
    static bool firstMove = true;

    int sendSize;
    char sendData[4];
    memset(sendData, '\0', 4);

    int recvSize;
    char recvData[4];
    memset(recvData, '\0', 4);

    char message[CBoard::MESSAGE_LENGTH];

    /* if this is the first move of the client, he can not send the data about
     * the local player move, because he don't play yet. */
    if (firstMove == false) {

        /* prepare send data */
        if (m_Game->m_Players[0]->m_Surrender) {
            sendData[2] = (char) 1;
        } else {
            sendData[0] = (char) m_Board->m_LastStone.m_X;
            sendData[1] = (char) m_Board->m_LastStone.m_Y;
        }

        /* send */
        m_Board->printMessage(" Client sending informations.");
        usleep(500000);

        if ((sendSize = send(m_Game->m_ConnectionSocket, sendData, 4, 0)) ==
                -1) {
            throw CNetworkException("Fatal network error: Client send failed.");
        }

    } else {
        firstMove = false;
    }

    /* nothing to do here */
    if (m_Game->m_Players[0]->m_Surrender || m_IsWinner == true) {
        return;
    }

    /* recv */
    m_Board->printMessage(" Client waits for server move.");
    usleep(500000);

    if ((recvSize = recv(m_Game->m_ConnectionSocket, recvData, 4, 0)) == -1) {
        throw CNetworkException("Fatal network error: Client recv failed.");
    }

    /* parse */
    memset(message, 0, CBoard::MESSAGE_LENGTH);
    sprintf(message, " Client received: %d,%d,%d", recvData[0],
            recvData[1], recvData[2]);
    m_Board->printMessage(message);

    usleep(500000);

    if (recvData[2] == 1) {
        m_Surrender = true;
        return;
    }

    if (m_Board->addStone(m_Mark, (int) recvData[1], (int) recvData[0]) ==
            false) {
        throw CNetworkException("Fatal network error: Bad data received.");
    }
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x38, %rsp
andl $0x0, 0xc(%rsp)
andl $0x0, 0x8(%rsp)
movq %rdi, %rbx
cmpb $0x1, 0x5ede(%rip)      # 0x91e5
jne 0x3322
movq 0x20(%rbx), %rax
movq 0x40(%rax), %rax
cmpb $0x1, 0x8(%rax)
jne 0x332b
movb $0x1, 0xe(%rsp)
movq 0x10(%rbx), %rdi
jmp 0x333d
movb $0x1, 0x5ebc(%rip)      # 0x91e5
jmp 0x3372
movq 0x10(%rbx), %rdi
movb 0x28(%rdi), %al
movb %al, 0xc(%rsp)
movb 0x2c(%rdi), %al
movb %al, 0xd(%rsp)
leaq 0x25df(%rip), %rsi      # 0x5923
callq 0x30f4
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x22b0
movq 0x20(%rbx), %rax
movl 0xc(%rax), %edi
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
xorl %ecx, %ecx
callq 0x2160
cmpl $-0x1, %eax
je 0x343f
movq 0x20(%rbx), %rax
movq 0x40(%rax), %rax
cmpb $0x0, 0x8(%rax)
jne 0x3437
cmpb $0x0, 0xa(%rbx)
jne 0x3437
movq 0x10(%rbx), %rdi
leaq 0x25d1(%rip), %rsi      # 0x596a
callq 0x30f4
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x22b0
movq 0x20(%rbx), %rax
movl 0xc(%rax), %edi
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
xorl %ecx, %ecx
callq 0x20d0
cmpl $-0x1, %eax
je 0x345b
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movsbl 0x8(%rsp), %edx
movsbl 0x9(%rsp), %ecx
movsbl 0xa(%rsp), %r8d
leaq 0x25c3(%rip), %rsi      # 0x59b2
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x30f4
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x22b0
cmpb $0x1, 0xa(%rsp)
jne 0x341c
movb $0x1, 0x8(%rbx)
jmp 0x3437
movq 0x10(%rbx), %rdi
movsbl 0x9(%rbx), %esi
movsbl 0x9(%rsp), %edx
movsbl 0x8(%rsp), %ecx
callq 0x2dd4
testb %al, %al
je 0x3477
addq $0x38, %rsp
popq %rbx
popq %r14
retq
pushq $0x28
popq %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x24f0(%rip), %rsi      # 0x5941
movq %rax, %rdi
callq 0x3ebc
jmp 0x3491
pushq $0x28
popq %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x251c(%rip), %rsi      # 0x5989
movq %rax, %rdi
callq 0x3ebc
jmp 0x3491
pushq $0x28
popq %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x2544(%rip), %rsi      # 0x59cd
movq %rax, %rdi
callq 0x3ebc
leaq 0x5838(%rip), %rsi      # 0x8cd0
leaq 0xa57(%rip), %rdx       # 0x3ef6
movq %rbx, %rdi
callq 0x2310
jmp 0x34ab
jmp 0x34ab
movq %rax, %r14
movq %rbx, %rdi
callq 0x2190
movq %r14, %rdi
callq 0x2320
nop