// File: /workspace/github_c_makefile_star2_O2/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 0x118a9(%rip), %rsi     # 0x1b0c5
leaq 0x8(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x82d0
pushq $0x1
popq %r14
cmpl $0x1, %eax
jne 0x995d
movl $0x400, %edi            # imm = 0x400
callq 0x82b0
movq %rax, (%rsp)
testq %rax, %rax
je 0x995d
movl 0x8(%rsp), %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x9534
testq %rax, %rax
je 0x987b
movq %rax, %rbx
movq %rax, %rdi
callq 0x93b5
testl %eax, %eax
je 0x9883
pushq $0x1
popq %r14
jmp 0x9955
xorl %r14d, %r14d
jmp 0x995d
leaq 0x10e01(%rip), %rdi     # 0x1a68b
callq 0x8090
xorl %r14d, %r14d
leaq 0x270a7(%rip), %r13     # 0x30940
pushq $0x2
popq %rbp
leaq 0xc(%rsp), %r15
movq 0x1e730(%rip), %rax     # 0x27fd8
movq (%rax), %rdx
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x8370
movq (%rsp), %r12
movq %r12, %rdi
callq 0x8120
movb $0xd, -0x1(%r12,%rax)
movq (%rsp), %r12
movq %r12, %rdi
callq 0x8120
movb $0x0, (%r12,%rax)
movq (%rsp), %rdx
cmpb $0x71, (%rdx)
jne 0x98ea
cmpb $0xd, 0x1(%rdx)
je 0x994d
movq %rbx, %rdi
movl %ebp, %esi
movq %r13, %rcx
movq %r15, %r8
callq 0x961f
movl %eax, %r14d
testl %eax, %eax
sete %cl
movl 0xc(%rsp), %eax
testl %eax, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x992c
movl %eax, %r14d
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x993d
movsbl (%r12,%r13), %edi
callq 0x8050
incq %r12
jmp 0x9918
leaq 0x10d81(%rip), %rdi     # 0x1a6b4
callq 0x8090
jmp 0x98a1
pushq $0xa
popq %rdi
callq 0x8050
xorl %r14d, %r14d
jmp 0x98a1
movq %rbx, %rdi
callq 0x9591
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