// File: /workspace/github_c_makefile_star2_O3/schroeder-lvb[P]sissm/src/rdrv.c
// Function: rdrvConnect
int rdrvConnect( rdrvObj *rPtr )
{
    struct hostent *server = NULL;
    int errCode = 1;
    char buf[BUFSIZE_T];

    // Create a socket
    //
#ifdef _WIN32
    rPtr->sockfd = (int) socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
#else 
    rPtr->sockfd = socket( AF_INET, SOCK_STREAM, 0 );
#endif
    rPtr->isConnected = 0;
    if ( rPtr->sockfd < 0 ) {
        logPrintf(LOG_LEVEL_CRITICAL, "rdrv", "Critical Error, socket creation error");
    }
    else {
        // gethostbyname: get the server's DNS entry 
        // 
        server = gethostbyname( rPtr->hostName );
        if ( server == NULL ) {
            logPrintf(LOG_LEVEL_CRITICAL, "rdrv", "Critical Error, no such host ::%s::", rPtr->hostName );
#ifdef _WIN32
            closesocket( rPtr->sockfd );
#else
            close( rPtr->sockfd );
#endif
            rPtr->sockfd = -1;
        }
    }

    // Connect to the server
    //
    if ( rPtr->sockfd >= 0 ) {

        // Build the Internet address
        // 
        // bzero( (char *) &rPtr->serveraddr, sizeof( rPtr->serveraddr) );
        memset( (char *) &rPtr->serveraddr, 0, sizeof( rPtr->serveraddr) );
        rPtr->serveraddr.sin_family = AF_INET;
        // bcopy( (char *) server->h_addr, (char *) &rPtr->serveraddr.sin_addr.s_addr, server->h_length );
        memcpy( (char *) &rPtr->serveraddr.sin_addr.s_addr, (char *) server->h_addr, server->h_length );
        rPtr->serveraddr.sin_port = htons( rPtr->portNo );

        if ( connect( rPtr->sockfd, (struct sockaddr *) &rPtr->serveraddr, sizeof( rPtr->serveraddr ) ) < 0) {
            logPrintf(LOG_LEVEL_CRITICAL, "rdrv", "Warning: unable to connect to host via TCP/IP");
#ifdef _WIN32
            closesocket( rPtr->sockfd );
#else
            close( rPtr->sockfd );
#endif
            rPtr->sockfd = -1;
        }
        else {
            SetSocketBlockingEnabled( rPtr->sockfd, 0 );
            rPtr->isConnected = 1;
            errCode = 0;
        }
    }

    // Send RCON Password to the server
    //
    if (0 == errCode ) {
        rdrvSend( rPtr, 3, rPtr->rconPassword );
        usleep( RDRV_DELAY_PASSWORD );
        rdrvReceive( rPtr, buf );
    }

    return( errCode );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x400, %rsp            # imm = 0x400
movq %rdi, %rbx
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8400
movl %eax, 0x154(%rbx)
movl $0x0, 0x16c(%rbx)
testl %eax, %eax
js 0x94de
movq %rbx, %rdi
callq 0x8240
movq %rax, %r14
testq %rax, %rax
jne 0x94f8
leaq 0x120f1(%rip), %rsi     # 0x1b59d
leaq 0x12115(%rip), %rdx     # 0x1b5c8
xorl %edi, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1a3e3
movl 0x154(%rbx), %edi
callq 0x81d0
movl $0xffffffff, 0x154(%rbx) # imm = 0xFFFFFFFF
movl $0x1, %ebp
jmp 0x95fa
leaq 0x120b8(%rip), %rsi     # 0x1b59d
leaq 0x120b6(%rip), %rdx     # 0x1b5a2
xorl %r14d, %r14d
xorl %edi, %edi
xorl %eax, %eax
callq 0x1a3e3
movl 0x154(%rbx), %r15d
movl $0x1, %ebp
testl %r15d, %r15d
js 0x95fa
leaq 0x158(%rbx), %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x158(%rbx)
movw $0x2, 0x158(%rbx)
leaq 0x15c(%rbx), %rdi
movq 0x18(%r14), %rax
movq (%rax), %rsi
movslq 0x14(%r14), %rdx
callq 0x8290
movzwl 0x100(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x15a(%rbx)
movl %r15d, %edi
movq %r12, %rsi
movl $0x10, %edx
callq 0x8380
testl %eax, %eax
js 0x95ce
movl 0x154(%rbx), %ebp
testl %ebp, %ebp
js 0x9597
movl %ebp, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x80f0
testl %eax, %eax
js 0x9597
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x80f0
movl $0x1, 0x16c(%rbx)
leaq 0x104(%rbx), %rdx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x934e
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x83f0
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x93e8
xorl %ebp, %ebp
jmp 0x95fa
leaq 0x11fc8(%rip), %rsi     # 0x1b59d
leaq 0x12010(%rip), %rdx     # 0x1b5ec
xorl %edi, %edi
xorl %eax, %eax
callq 0x1a3e3
movl 0x154(%rbx), %edi
callq 0x81d0
movl $0xffffffff, 0x154(%rbx) # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x400, %rsp            # imm = 0x400
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq