// File: /workspace/github_c_makefile_star2_O3/schroeder-lvb[P]sissm/src/rdrv.c
// Function: rdrvTerminal
int rdrvTerminal( char *hostName, char *portNoStr, char *rconPassword )
{
    int         i, exitLoop = 0, errCode = 1, bytesRead, portNo, isConnected = 0;
    size_t      rconCmdSize = 1024;
    char        *rconCmd = NULL;
    static char rconResp[1024*16];
    rdrvObj     *rPtr = NULL;
    
    // Parse Parameters, allocate getline() buffer [required] 
    //
    if ( 1 == sscanf( portNoStr, "%d", &portNo )) {
        rconCmd = (char *) malloc( rconCmdSize );
        if (rconCmd != NULL) errCode = 0;
    }
  
    // Open and Connect to the server 
    //
    if ( !errCode ) {
        // printf("\nSISSM RconTerm ::%s::%d::%s::\n", hostName, portNo, rconPassword );
        rPtr = rdrvInit( hostName, portNo, rconPassword );
        if ( rPtr != NULL ) {
            errCode = rdrvConnect( rPtr );
            if ( !errCode ) { 
                printf("\nConnection successful. Type 'q' to exit\n");
                isConnected = 1;
            }
        }
    }

    // Command Loop until 'q' is pressed
    //
    if ( isConnected ) {
        while ( !exitLoop ) {
#ifdef _WIN32
            memset( rconCmd, 0, rconCmdSize );
            gets_s( rconCmd, rconCmdSize );
            rconCmd[ strlen( rconCmd ) - 0 ] = 0x0d; 
            rconCmd[ strlen( rconCmd ) + 1 ] = 0x00;
#else
            getline( &rconCmd, &rconCmdSize, stdin );
            rconCmd[ strlen( rconCmd ) - 1 ] = 0x0d;
            rconCmd[ strlen( rconCmd ) - 0 ] = 0x00; 
#endif     
            if  (( rconCmd[0] == 'q' ) && ( rconCmd[1] == 0x0d )) 
                exitLoop = 1;
            else {
                errCode = rdrvCommand( rPtr, 2, rconCmd, rconResp, &bytesRead );
                if ( (0 == errCode) && (bytesRead > 0) ) {
                    for (i=0; i<bytesRead; i++) printf("%c", rconResp[i]);
                    printf("\n");
                }
                else {
                    printf("\nNo Response/Error Response\n");
                }
            }
        }
    }

    // Close the RCON port
    //
    if ( rPtr != NULL ) {
        if ( isConnected ) rdrvDisconnect( rPtr );
        rdrvDestroy( rPtr );
    }

    return( errCode );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %rax
movq %rdi, %r15
movq $0x400, 0x10(%rsp)      # imm = 0x400
leaq 0x1279c(%rip), %rsi     # 0x1c0c5
leaq 0x8(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x82d0
movl $0x1, %r14d
cmpl $0x1, %eax
jne 0x9a74
movl $0x400, %edi            # imm = 0x400
callq 0x82b0
movq %rax, (%rsp)
testq %rax, %rax
je 0x9a74
movl 0x8(%rsp), %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x960c
testq %rax, %rax
je 0x9a5c
movq %rax, %rbx
movq %rax, %rdi
callq 0x945e
movl $0x1, %r14d
testl %eax, %eax
jne 0x9a6c
leaq 0x11cf5(%rip), %rdi     # 0x1b68b
callq 0x8090
xorl %r14d, %r14d
leaq 0x10(%rsp), %r12
leaq 0x26f96(%rip), %r13     # 0x30940
leaq 0xc(%rsp), %rbp
movq 0x1e622(%rip), %rax     # 0x27fd8
movq (%rax), %rdx
movq %rsp, %rdi
movq %r12, %rsi
callq 0x8360
movq (%rsp), %r15
movq %r15, %rdi
callq 0x8120
movb $0xd, -0x1(%r15,%rax)
movq (%rsp), %r15
movq %r15, %rdi
callq 0x8120
movb $0x0, (%r15,%rax)
movq (%rsp), %rdx
cmpb $0x71, (%rdx)
jne 0x99f6
cmpb $0xd, 0x1(%rdx)
je 0x9a61
movq %rbx, %rdi
movl $0x2, %esi
movq %r13, %rcx
movq %rbp, %r8
callq 0x972d
movl %eax, %r14d
testl %eax, %eax
sete %cl
movl 0xc(%rsp), %eax
testl %eax, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x9a4b
movl %eax, %r14d
xorl %r15d, %r15d
movsbl (%r15,%r13), %edi
callq 0x8050
incq %r15
cmpq %r15, %r14
jne 0x9a27
movl $0xa, %edi
callq 0x8050
xorl %r14d, %r14d
jmp 0x99af
leaq 0x11c62(%rip), %rdi     # 0x1b6b4
callq 0x8090
jmp 0x99af
xorl %r14d, %r14d
jmp 0x9a74
movl 0x154(%rbx), %edi
callq 0x81d0
movq %rbx, %rdi
callq 0x8040
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop