// File: qian-jiahong[P]uvncrep017-ws/repeater.cpp
// Function: parseHostAndPort(char*, char*, int, int*)
static bool parseHostAndPort(char *id, char *host, int hostLen, int *port)
{
    int tmpPort;
    char *colonPos;
    
    debug(LEVEL_3, "parseHostAndPort() start: id = %s\n", id);
    
    colonPos = strchr(id, ':');
    if (hostLen < (int) strlen(id)) {
        debug(LEVEL_3, "parseHostAndPort(): Id string too long\n");
        return false;
    }

    if (colonPos == NULL) {
        // No colon -- use default port number
        tmpPort = RFB_PORT_OFFSET;
        strlcpy(host, id, hostLen);
    }
    else {
        strlcpy(host, id, (colonPos-id)+1);

        if (colonPos[1] == ':') {
            // Two colons -- interpret as a port number
            if (sscanf(colonPos + 2, "%d", &tmpPort) != 1) {
                debug(LEVEL_3, "parseHostAndPort(): sscanf error 1\n");
                return false;
            }
        }
        else {
            // One colon -- interpret as a display number or port
            // number
            if (sscanf(colonPos + 1, "%d", &tmpPort) != 1) {
                return false;
            }
            // RealVNC method - If port < 100 interpret as display
            // number else as Port number
            if (tmpPort < 100)
                tmpPort += RFB_PORT_OFFSET;
        }
    }

    *port = tmpPort;
    debug(LEVEL_3, "parseHostAndPort() end: host = %s, port = %d\n", host, tmpPort);
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdx
movl $0x3, %edi
leaq 0x5c30(%rip), %rsi      # 0xb737
movb $0x0, %al
callq 0x2480
movq -0x10(%rbp), %rdi
movl $0x3a, %esi
callq 0x20c0
movq %rax, -0x38(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20e0
movq %rax, %rcx
movl -0x3c(%rbp), %eax
cmpl %ecx, %eax
jge 0x5b55
movl $0x3, %edi
leaq 0x5c15(%rip), %rsi      # 0xb75a
movb $0x0, %al
callq 0x2480
movb $0x0, -0x1(%rbp)
jmp 0x5c3d
cmpq $0x0, -0x38(%rbp)
jne 0x5b79
movl $0x170c, -0x2c(%rbp)    # imm = 0x170C
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x76d0
jmp 0x5c16
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rax
subq %rax, %rdx
addq $0x1, %rdx
callq 0x76d0
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3a, %eax
jne 0x5bdc
movq -0x38(%rbp), %rdi
addq $0x2, %rdi
leaq 0x4ecf(%rip), %rsi      # 0xaa80
leaq -0x2c(%rbp), %rdx
movb $0x0, %al
callq 0x2200
cmpl $0x1, %eax
je 0x5bda
movl $0x3, %edi
leaq 0x5bb5(%rip), %rsi      # 0xb782
movb $0x0, %al
callq 0x2480
movb $0x0, -0x1(%rbp)
jmp 0x5c3d
jmp 0x5c14
movq -0x38(%rbp), %rdi
addq $0x1, %rdi
leaq 0x4e95(%rip), %rsi      # 0xaa80
leaq -0x2c(%rbp), %rdx
movb $0x0, %al
callq 0x2200
cmpl $0x1, %eax
je 0x5c01
movb $0x0, -0x1(%rbp)
jmp 0x5c3d
cmpl $0x64, -0x2c(%rbp)
jge 0x5c12
movl -0x2c(%rbp), %eax
addl $0x170c, %eax           # imm = 0x170C
movl %eax, -0x2c(%rbp)
jmp 0x5c14
jmp 0x5c16
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl $0x3, %edi
leaq 0x5b74(%rip), %rsi      # 0xb7a6
movb $0x0, %al
callq 0x2480
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)