// File: /workspace/github_cpp_makefile_star2_O2/SeTriones[P]Anubis/base_nio_handler.cpp
// Function: base_nio_handler::read_data(int, void*, int, timeval*)
int base_nio_handler::read_data(int fd, void * buf, int buf_len, timeval* timeout) {
    
    if (!(timeout->tv_sec >= 0 && timeout->tv_usec >=0))
        return -1;    

    struct timeval start_time, end_time;
    gettimeofday(&start_time, NULL);
        
    pollfd read_fd;
    read_fd.fd = fd;
    read_fd.events = POLLIN;
    int poll_ret = poll(&read_fd, 1, timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
    if (poll_ret <= 0 || !(read_fd.revents & POLLIN)) {
        fprintf(stderr, "rd ret=%d, errno=%d\n", poll_ret, errno);
        if (read_fd.revents & POLLIN) {
            fprintf(stderr, "POLLIN\n");
        }
        if (read_fd.revents & POLLPRI) {
            fprintf(stderr, "POLLPRI\n");
        }
        if (read_fd.revents & POLLOUT) {
            fprintf(stderr, "POLLOUT\n");
        }
        if (read_fd.revents & POLLRDHUP) {
            fprintf(stderr, "POLLRDHUP\n");
        }
        if (read_fd.revents & POLLERR) {
            fprintf(stderr, "POLLERR\n");
        }
        if (read_fd.revents & POLLHUP) {
            fprintf(stderr, "POLLHUP\n");
        }
        if (read_fd.revents & POLLNVAL) {
            fprintf(stderr, "POLLNVAL\n");
        }
        if (read_fd.revents & POLLRDNORM) {
            fprintf(stderr, "POLLRDNORM\n");
        }
        if (read_fd.revents & POLLRDBAND) {
            fprintf(stderr, "POLLRDBAND\n");
        }
        if (read_fd.revents & POLLWRNORM) {
            fprintf(stderr, "POLLWRNORM\n");
        }
        if (read_fd.revents & POLLWRBAND) {
            fprintf(stderr, "POLLWRBAND\n");
        }
        return -1; 
    }
    int len = read(fd,buf,buf_len);
    gettimeofday(&end_time,NULL);
    long cost = 1000000 * (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_usec - start_time.tv_usec);
    if (timeout->tv_sec > 0) {
        timeout->tv_usec += timeout->tv_sec * 1000000;
        timeout->tv_sec = 0;
    }
    timeout->tv_usec -= cost; 
    //fprintf(stderr,"ori tv_sec=%ld,tv_usec=%ld,cost=%ld\n",timeout->tv_sec,timeout->tv_usec,cost);
    if (len == 0) {
        _INFO("read_len=0,disconnect by peer");
    }
    return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
pushq $-0x1
popq %r14
cmpq $0x0, (%r8)
js 0x2f14
movq %r8, %rbx
cmpq $0x0, 0x8(%r8)
js 0x2f14
movl %ecx, %r12d
movq %rdx, %r15
movl %esi, %ebp
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x2350
movq %rsp, %rdi
movl %ebp, (%rdi)
movw $0x1, 0x4(%rdi)
imull $0x3e8, (%rbx), %ecx    # imm = 0x3E8
movq 0x8(%rbx), %rax
movl $0x3e8, %esi            # imm = 0x3E8
cqto
idivq %rsi
addl %eax, %ecx
pushq $0x1
popq %rsi
movl %ecx, %edx
callq 0x2330
movl %eax, %r14d
testl %eax, %eax
jle 0x2f27
testb $0x1, 0x6(%rsp)
je 0x2f27
movslq %r12d, %rdx
movl %ebp, %edi
movq %r15, %rsi
callq 0x22f0
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2350
movq (%r15), %rax
subq 0x8(%rsp), %rax
imulq $-0xf4240, %rax, %rcx   # imm = 0xFFF0BDC0
movq 0x10(%rsp), %rax
subq 0x8(%r15), %rax
addq %rcx, %rax
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
testq %rdx, %rdx
jle 0x2f04
imulq $0xf4240, %rdx, %rdx    # imm = 0xF4240
addq %rdx, %rcx
andq $0x0, (%rbx)
addq %rcx, %rax
movq %rax, 0x8(%rbx)
testl %r14d, %r14d
je 0x2fcd
movl %r14d, %eax
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x70aa(%rip), %r15      # 0x9fd8
movq (%r15), %rbx
callq 0x2040
movl (%rax), %ecx
leaq 0x31cf(%rip), %rsi      # 0x610e
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x22e0
movzwl 0x6(%rsp), %eax
testb $0x1, %al
jne 0x3039
testb $0x2, %al
jne 0x3058
testb $0x4, %al
jne 0x3077
btl $0xd, %eax
jb 0x3096
testb $0x8, %al
jne 0x30b5
testb $0x10, %al
jne 0x30d4
testb $0x20, %al
jne 0x30f3
testb $0x40, %al
jne 0x3112
testb %al, %al
js 0x3131
btl $0x8, %eax
jb 0x3150
pushq $-0x1
popq %r14
btl $0x9, %eax
jae 0x2f14
movq (%r15), %rcx
leaq 0x31cb(%rip), %rdi      # 0x6188
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
jmp 0x2f14
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x21d0
leaq 0x48(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2100
leaq 0x3013(%rip), %rdx      # 0x6004
leaq 0x30(%rsp), %rbx
pushq $0x12
popq %rsi
movq %rbx, %rdi
movq %r14, %rcx
callq 0x2180
movq 0x6fcd(%rip), %rax      # 0x9fd8
movq (%rax), %r15
callq 0x21b0
leaq 0x317a(%rip), %rsi      # 0x6194
leaq 0x315a(%rip), %r8       # 0x617b
xorl %r14d, %r14d
movq %r15, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x22e0
jmp 0x2f14
movq (%r15), %rcx
leaq 0x30e0(%rip), %rdi      # 0x6123
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f59
movq (%r15), %rcx
leaq 0x30c9(%rip), %rdi      # 0x612b
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f61
movq (%r15), %rcx
leaq 0x30b3(%rip), %rdi      # 0x6134
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f69
movq (%r15), %rcx
leaq 0x309d(%rip), %rdi      # 0x613d
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f73
movq (%r15), %rcx
leaq 0x3089(%rip), %rdi      # 0x6148
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f7b
movq (%r15), %rcx
leaq 0x3073(%rip), %rdi      # 0x6151
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f83
movq (%r15), %rcx
leaq 0x305d(%rip), %rdi      # 0x615a
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f8b
movq (%r15), %rcx
leaq 0x3048(%rip), %rdi      # 0x6164
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f93
movq (%r15), %rcx
leaq 0x3035(%rip), %rdi      # 0x6170
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2f9b
movq (%r15), %rcx
leaq 0x3022(%rip), %rdi      # 0x617c
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
movzwl 0x6(%rsp), %eax
jmp 0x2fa5
nop