// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %r15
movq $0x400, 0x20(%rsp)      # imm = 0x400
movq $0x0, 0x8(%rsp)
leaq 0x12757(%rip), %rsi     # 0x1c0cd
xorl %ebx, %ebx
leaq 0x18(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x82d0
movb $0x1, %r12b
movl $0x1, %ebp
cmpl $0x1, %eax
jne 0x99e2
movq 0x20(%rsp), %rdi
callq 0x82b0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x99e0
movl 0x18(%rsp), %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x9617
testq %rax, %rax
je 0x99de
movq %rax, %rbx
movq %rax, %rdi
callq 0x945e
testl %eax, %eax
jne 0x99e2
leaq 0x11cbc(%rip), %rdi     # 0x1b68e
callq 0x8090
xorl %ebp, %ebp
xorl %r12d, %r12d
jmp 0x99e2
xorl %ebp, %ebp
xorl %ebx, %ebx
movl %r12d, 0x14(%rsp)
testb %r12b, %r12b
jne 0x9abd
xorl %r14d, %r14d
leaq 0x20(%rsp), %r15
leaq 0x26f41(%rip), %r12     # 0x30940
movq 0x1e5d2(%rip), %rax     # 0x27fd8
movq (%rax), %rdx
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x8360
movq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x8120
movb $0xd, -0x1(%r13,%rax)
movq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x8120
movb $0x0, (%r13,%rax)
movq 0x8(%rsp), %rdx
cmpb $0x71, (%rdx)
jne 0x9a51
movl $0x1, %eax
cmpb $0xd, 0x1(%rdx)
je 0x9ab2
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rcx
leaq 0x1c(%rsp), %r8
callq 0x9748
movl %eax, %ebp
testl %eax, %eax
sete %cl
movl 0x1c(%rsp), %eax
testl %eax, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x9aa3
movl %eax, %r13d
xorl %ebp, %ebp
movsbl (%rbp,%r12), %edi
callq 0x8050
incq %rbp
cmpq %rbp, %r13
jne 0x9a82
movl $0xa, %edi
callq 0x8050
xorl %ebp, %ebp
jmp 0x9aaf
leaq 0x11c0d(%rip), %rdi     # 0x1b6b7
callq 0x8090
movl %r14d, %eax
movl %eax, %r14d
testl %eax, %eax
je 0x99ff
testq %rbx, %rbx
je 0x9af0
cmpb $0x0, 0x14(%rsp)
jne 0x9ae8
movl 0x154(%rbx), %edi
callq 0x81d0
movl $0xffffffff, 0x154(%rbx) # imm = 0xFFFFFFFF
movl $0x0, 0x16c(%rbx)
movq %rbx, %rdi
callq 0x8040
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)