// File: /workspace/github_c_makefile_star2_O0/goghcrow[P]dubbo_ab/lib/ae/ae_epoll.c
// Function: aeApiPoll
static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
    aeApiState *state = eventLoop->apidata;
    int retval, numevents = 0;

    retval = epoll_wait(state->epfd,state->events,eventLoop->setsize,
            tvp ? (tvp->tv_sec*1000 + tvp->tv_usec/1000) : -1);
    if (retval > 0) {
        int j;

        numevents = retval;
        for (j = 0; j < numevents; j++) {
            int mask = 0;
            struct epoll_event *e = state->events+j;

            if (e->events & EPOLLIN) mask |= AE_READABLE;
            if (e->events & EPOLLOUT) mask |= AE_WRITABLE;
            // 这里将 EPOLLERR 与 EPOLLHUP 转换成 WRITABLE 事件, 是为了简化处理
            // man 手册 标记可以不处理 EPOLLERR 与 EPOLLHUP, 但是会导致 cpu 100% 故障
            // 比如 skynet的 issues: https://github.com/cloudwu/skynet/issues/644
            // https://blog.codingnow.com/2017/05/epoll_close_without_del.html
            // https://github.com/zhangshiqian1214/skynet/commit/b38951a4fa066fbc7da17f7dffaaf9ce0710582b
            // https://stackoverflow.com/questions/30529883/what-do-epollerr-and-epollhup-really-mean-and-how-to-deal-with-them
            // https://github.com/antirez/redis/pull/569
            // 个人认为这里将 ERR 和 HUP 当成 WRITABLE 或者 READABLE 都可以, 但是都要保证正确判断 read 与 write 返回值
            if (e->events & EPOLLERR) mask |= AE_WRITABLE;
            if (e->events & EPOLLHUP) mask |= AE_WRITABLE;
            eventLoop->fired[j].fd = e->data.fd;
            eventLoop->fired[j].mask = mask;
        }
    }
    return numevents;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x329a
movq -0x10(%rbp), %rax
imulq $0x3e8, (%rax), %rax    # imm = 0x3E8
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %rcx
movq -0x58(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0x32a7
movq $-0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x32a7
movl -0x34(%rbp), %edx
movq -0x40(%rbp), %rsi
movl -0x44(%rbp), %edi
movq -0x50(%rbp), %rax
movl %eax, %ecx
callq 0x22b0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x3395
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x3393
movl $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3317
movl -0x28(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x332e
movl -0x28(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x3345
movl -0x28(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x335c
movl -0x28(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movl -0x28(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x32d6
jmp 0x3395
movl -0x20(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop