// File: /workspace/github_cpp_makefile_star2_O2/nesro[P]NCursesGomoku/src/server.cpp
// Function: CServer::nextMove()
void CServer::nextMove(void) {
    int sendSize;
    char sendData[4];
    memset(sendData, '\0', 4);

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

    char message[CBoard::MESSAGE_LENGTH];

    /* 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 */
    memset(message, 0, CBoard::MESSAGE_LENGTH);
    sprintf(message, " Server sending: %d,%d,%d", sendData[0],
            sendData[1], sendData[2]);
    m_Board->printMessage(message);
    usleep(1000000);


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

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

    /* recv */
    for (int i = 0; i < 10; i++) {

        m_Board->printMessage(" Server waits for client move.");
        usleep(500000);

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

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

        usleep(500000);

        if (recvData[0] == -1 || recvData[1] == -1) {
            continue;
        }

        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 recevied.");
        } else {
            return;
        }
    }
    throw CNetworkException("Fatal network error: Please, wait and then \
run again program with another port.");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
andl $0x0, 0xc(%rsp)
movq %rdi, %rbx
andl $0x0, 0x8(%rsp)
movq 0x20(%rdi), %rax
movq 0x40(%rax), %rax
cmpb $0x1, 0x8(%rax)
jne 0x4322
movb $0x1, 0xe(%rsp)
xorl %ecx, %ecx
pushq $0x1
popq %r8
xorl %edx, %edx
jmp 0x433d
movq 0x10(%rbx), %rax
movl 0x28(%rax), %ecx
movb %cl, 0xc(%rsp)
movl 0x2c(%rax), %eax
movb %al, 0xd(%rsp)
movsbl %cl, %edx
movsbl %al, %ecx
xorl %r8d, %r8d
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0x1b47(%rip), %rsi      # 0x5e9c
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x30f4
movl $0xf4240, %edi          # imm = 0xF4240
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 0x44e3
movq 0x20(%rbx), %rax
movq 0x40(%rax), %rax
cmpb $0x0, 0x8(%rax)
jne 0x4488
cmpb $0x0, 0xa(%rbx)
jne 0x4488
pushq $0xb
popq %r14
leaq 0x8(%rsp), %r15
pushq $0x4
popq %r12
leaq 0x1b63(%rip), %r13      # 0x5f27
leaq 0x10(%rsp), %rbp
decl %r14d
je 0x4497
movq 0x10(%rbx), %rdi
leaq 0x1b02(%rip), %rsi      # 0x5edf
callq 0x30f4
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x22b0
movq 0x20(%rbx), %rax
movl 0xc(%rax), %edi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x20d0
cmpl $-0x1, %eax
je 0x44b3
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movsbl 0x8(%rsp), %edx
movsbl 0x9(%rsp), %ecx
movsbl 0xa(%rsp), %r8d
movq %rbp, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x30f4
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x22b0
movsbl 0x8(%rsp), %ecx
cmpl $-0x1, %ecx
sete %dl
movb 0x9(%rsp), %al
cmpb $-0x1, %al
sete %sil
orb %dl, %sil
jne 0x43c9
cmpb $0x1, 0xa(%rsp)
jne 0x4474
movb $0x1, 0x8(%rbx)
jmp 0x4488
movsbl %al, %edx
movq 0x10(%rbx), %rdi
movsbl 0x9(%rbx), %esi
callq 0x2dd4
testb %al, %al
je 0x44ff
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x1ac1(%rip), %rsi      # 0x5f6a
movq %rax, %rdi
callq 0x3ebc
jmp 0x44cd
pushq $0x28
popq %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x1a39(%rip), %rsi      # 0x5efe
movq %rax, %rdi
callq 0x3ebc
leaq 0x47fc(%rip), %rsi      # 0x8cd0
leaq -0x5e5(%rip), %rdx      # 0x3ef6
movq %rbx, %rdi
callq 0x2310
pushq $0x28
popq %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x19c1(%rip), %rsi      # 0x5eb6
movq %rax, %rdi
callq 0x3ebc
jmp 0x44cd
pushq $0x28
popq %rdi
callq 0x2150
movq %rax, %rbx
leaq 0x1a31(%rip), %rsi      # 0x5f42
movq %rax, %rdi
callq 0x3ebc
jmp 0x44cd
jmp 0x4521
jmp 0x4521
jmp 0x4521
movq %rax, %r14
movq %rbx, %rdi
callq 0x2190
movq %r14, %rdi
callq 0x2320