// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x0, -0x30(%rbp)
movq $0x400, -0x38(%rbp)     # imm = 0x400
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x19ef3(%rip), %rsi     # 0x240cf
leaq -0x2c(%rbp), %rdx
movb $0x0, %al
callq 0x82c0
movl %eax, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jne 0xa20f
movq -0x38(%rbp), %rdi
callq 0x82a0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xa20d
movl $0x0, -0x24(%rbp)
jmp 0xa20f
cmpl $0x0, -0x24(%rbp)
jne 0xa25b
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x9d80
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xa259
movq -0x48(%rbp), %rdi
callq 0x9ad0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xa257
leaq 0x19418(%rip), %rdi     # 0x23661
movb $0x0, %al
callq 0x8170
movl $0x1, -0x30(%rbp)
jmp 0xa259
jmp 0xa25b
cmpl $0x0, -0x30(%rbp)
je 0xa380
jmp 0xa267
cmpl $0x0, -0x20(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xa279
jmp 0xa37e
movq 0x25d58(%rip), %rax     # 0x2ffd8
movq (%rax), %rdx
leaq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8350
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rdi
callq 0x8110
movq %rax, %rcx
movq -0x58(%rbp), %rax
subq $0x1, %rcx
movb $0xd, (%rax,%rcx)
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
callq 0x8110
movq %rax, %rcx
movq -0x50(%rbp), %rax
subq $0x0, %rcx
movb $0x0, (%rax,%rcx)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x71, %eax
jne 0xa2f5
movq -0x40(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0xd, %eax
jne 0xa2f5
movl $0x1, -0x20(%rbp)
jmp 0xa379
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rdx
movl $0x2, %esi
leaq 0x2e637(%rip), %rcx     # 0x38940
leaq -0x28(%rbp), %r8
callq 0x9f20
movl %eax, -0x24(%rbp)
xorl %eax, %eax
cmpl -0x24(%rbp), %eax
jne 0xa369
cmpl $0x0, -0x28(%rbp)
jle 0xa369
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0xa359
movslq -0x1c(%rbp), %rcx
leaq 0x2e604(%rip), %rax     # 0x38940
movsbl (%rax,%rcx), %esi
leaq 0x19260(%rip), %rdi     # 0x235a7
movb $0x0, %al
callq 0x8170
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa329
leaq 0x1923f(%rip), %rdi     # 0x2359f
movb $0x0, %al
callq 0x8170
jmp 0xa377
leaq 0x1931b(%rip), %rdi     # 0x2368b
movb $0x0, %al
callq 0x8170
jmp 0xa379
jmp 0xa267
jmp 0xa380
cmpq $0x0, -0x48(%rbp)
je 0xa39f
cmpl $0x0, -0x30(%rbp)
je 0xa396
movq -0x48(%rbp), %rdi
callq 0x9e10
movq -0x48(%rbp), %rdi
callq 0x9e50
movl -0x24(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)