// File: /workspace/github_c_makefile_star2_O0/xiaowenhuyuehu[P]remote_access/src/core/remote_terminal.c
// Function: read_msg_hdr
static int _read_msg_hdr(char *buf, int len)
{
    int i = 0;
    int n = 0;
	int timeout = 1000;
	long ellapsed   = 0;
 
    if(len < DEFAULT_MSG_HDR_LEN)
        return -1;

    memset(buf, 0, len);
    struct  timeval    start;
    struct  timeval    stop;
    struct  timeval    diff; 

#if defined(NOPOLL_OS_WIN32)
	nopoll_win32_gettimeofday (&start, NULL);
#else
	gettimeofday (&start, NULL);
#endif

    while(1){
        n = nopoll_conn_read(g_network.handle, buf+i, 1, nopoll_false, 500);
        if(buf[0] != '{'){
            return -1;
        } 

		if(n == -1){
#if defined(NOPOLL_OS_WIN32)
			nopoll_win32_gettimeofday (&stop, NULL);
#else
			gettimeofday (&stop, NULL);
#endif
			_timeval_substract (&stop, &start, &diff);
			ellapsed = (diff.tv_sec * 1000) + (diff.tv_usec / 1000);
			if (ellapsed > (timeout)){
				log_error("timeout %d, we only read:  %d\n", ellapsed, i);
				break;
			}
			else
				continue;
		}

        if(buf[i] == '}'){
            nopoll_conn_read(g_network.handle, buf+i+1, 4, nopoll_true, 1000);

            return i;
        }
        ++i;
    }
    
    return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x3e8, -0x20(%rbp)     # imm = 0x3E8
movq $0x0, -0x28(%rbp)
cmpl $0x400, -0x14(%rbp)     # imm = 0x400
jge 0x84f1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8638
movq -0x10(%rbp), %rdi
movslq -0x14(%rbp), %rdx
xorl %esi, %esi
callq 0x2090
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2110
movq 0x6eac(%rip), %rdi      # 0xf3c0
movq -0x10(%rbp), %rsi
movslq -0x18(%rbp), %rax
addq %rax, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
movl $0x1f4, %r8d            # imm = 0x1F4
callq 0x2220
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
je 0x854c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8638
cmpl $-0x1, -0x1c(%rbp)
jne 0x85e0
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2110
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x6ea0
imulq $0x3e8, -0x58(%rbp), %rax # imm = 0x3E8
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %rcx
movq -0x60(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movslq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jle 0x85db
movq -0x28(%rbp), %r9
movl -0x18(%rbp), %eax
movl $0x3, %edi
leaq 0x3024(%rip), %rsi      # 0xb5e0
leaq 0x3023(%rip), %rdx      # 0xb5e6
movl $0x152, %ecx            # imm = 0x152
leaq 0x35b6(%rip), %r8       # 0xbb85
movl %eax, (%rsp)
movb $0x0, %al
callq 0x4f90
jmp 0x8632
jmp 0x850d
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7d, %eax
jne 0x8624
movq 0x6dc8(%rip), %rdi      # 0xf3c0
movq -0x10(%rbp), %rsi
movslq -0x18(%rbp), %rax
addq %rax, %rsi
addq $0x1, %rsi
movl $0x4, %edx
movl $0x1, %ecx
movl $0x3e8, %r8d            # imm = 0x3E8
callq 0x2220
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8638
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x850d
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)