// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x83d0
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x154(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x16c(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x154(%rax)
jge 0x9b3f
xorl %edi, %edi
leaq 0x19a7b(%rip), %rsi     # 0x235aa
leaq 0x19a79(%rip), %rdx     # 0x235af
movb $0x0, %al
callq 0x21bf0
jmp 0x9b8d
movq -0x8(%rbp), %rdi
callq 0x8220
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x9b8b
movq -0x8(%rbp), %rcx
xorl %edi, %edi
leaq 0x19a4a(%rip), %rsi     # 0x235aa
leaq 0x19a6e(%rip), %rdx     # 0x235d5
movb $0x0, %al
callq 0x21bf0
movq -0x8(%rbp), %rax
movl 0x154(%rax), %edi
callq 0x81c0
movq -0x8(%rbp), %rax
movl $0xffffffff, 0x154(%rax) # imm = 0xFFFFFFFF
jmp 0x9b8d
movq -0x8(%rbp), %rax
cmpl $0x0, 0x154(%rax)
jl 0x9c8b
movq -0x8(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
xorl %esi, %esi
movl $0x10, %edx
callq 0x81a0
movq -0x8(%rbp), %rax
movw $0x2, 0x158(%rax)
movq -0x8(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
addq $0x4, %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x14(%rax), %rdx
callq 0x8270
movq -0x8(%rbp), %rax
movl 0x100(%rax), %eax
movzwl %ax, %edi
callq 0x8150
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x15a(%rax)
movq -0x8(%rbp), %rax
movl 0x154(%rax), %edi
movq -0x8(%rbp), %rsi
addq $0x158, %rsi            # imm = 0x158
movl $0x10, %edx
callq 0x8370
cmpl $0x0, %eax
jge 0x9c63
xorl %edi, %edi
leaq 0x19974(%rip), %rsi     # 0x235aa
leaq 0x199bc(%rip), %rdx     # 0x235f9
movb $0x0, %al
callq 0x21bf0
movq -0x8(%rbp), %rax
movl 0x154(%rax), %edi
callq 0x81c0
movq -0x8(%rbp), %rax
movl $0xffffffff, 0x154(%rax) # imm = 0xFFFFFFFF
jmp 0x9c89
movq -0x8(%rbp), %rax
movl 0x154(%rax), %edi
xorl %esi, %esi
callq 0x9ce0
movq -0x8(%rbp), %rax
movl $0x1, 0x16c(%rax)
movl $0x0, -0x14(%rbp)
jmp 0x9c8b
xorl %eax, %eax
cmpl -0x14(%rbp), %eax
jne 0x9cc5
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0x104, %rdx            # imm = 0x104
movl $0x3, %esi
callq 0x9900
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x83c0
movq -0x8(%rbp), %rdi
leaq -0x420(%rbp), %rsi
callq 0x9a10
movl -0x14(%rbp), %eax
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
nopw %cs:(%rax,%rax)