// File: /workspace/github_c_makefile_star2_O2/qq-smart[P]qq_sh_server/event/qq_epoll.c
// Function: qq_epoll_process_events
qq_int_t
qq_epoll_process_events(qq_msec_t timer, qq_uint_t flags)
{
    int                events;
    uint32_t           revents;
    qq_int_t           instance, i;
    qq_err_t           err;
    qq_event_t        *rev, *wev;
    qq_connection_t   *c;
    qq_queue_t        *queue;

    qq_log_debug("epoll timer: %d", timer);

    events = epoll_wait(ep, event_list, (int) nevents, timer);

    err = (events == -1) ? errno : 0;

    if (flags & QQ_UPDATE_TIME) {
        qq_time_update();
    }

    if (err) {
        if (err == QQ_EINTR) {
            return QQ_OK;
        }

        qq_log_error(err, "epoll_wait() failed");
        return QQ_ERROR;
    }

    if (events == 0) {
        if (timer != QQ_TIMER_INFINITE) {
            return QQ_OK;
        }

        qq_log_error(err, "epoll_wait() returned no events without timeout");
        return QQ_ERROR;
    }

    for (i = 0; i < events; i++) {
        c = event_list[i].data.ptr;

        instance = (uintptr_t) c & 1;
        c = (qq_connection_t *) ((uintptr_t) c & (uintptr_t) ~1);

        rev = c->read;

        if (c->fd == -1 || rev->instance != instance) {
            qq_log_debug("epoll: stale event %p", c);
            continue;
        }

        revents = event_list[i].events;

        qq_log_debug("epoll process: fd:%d ev:%04XD d:%p", c->fd, revents, event_list[i].data.ptr);

        if (revents & (EPOLLERR|EPOLLHUP)) {
            qq_log_debug("epoll_wait() error on fd:%d ev:%04XD", c->fd, revents);
            revents |= EPOLLIN|EPOLLOUT;
        }

        if ((revents & EPOLLIN) && rev->active) {
#if (QQ_HAVE_EPOLLRDHUP)
            if (revents & EPOLLRDHUP) {
                qq_log_debug("epollrdhup on fd:%d", c->fd);
                rev->pending_eof = 1;
            }
            rev->available = 1;
#endif

            qq_log_debug("epollin event fd:%d", c->fd);
            rev->ready = 1;

            queue = rev->accept ? &qq_posted_accept_events
                                : &qq_posted_events;
            qq_post_event(rev, queue);
        }

        wev = c->write;
        if ((revents & EPOLLOUT) && wev->active) {
            if (c->fd == -1 || wev->instance != instance) {
                qq_log_debug("epoll: stale event %p", c);
                continue;
            }

            qq_log_debug("epollout event fd:%d", c->fd);
            wev->ready = 1;
            qq_post_event(wev, &qq_posted_events);
        }
    }

    return QQ_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x663a(%rip), %rdi      # 0x947a
xorl %r14d, %r14d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6706
movl 0xb35d(%rip), %edi      # 0xe1b0
cmpb $0x0, 0xb45e(%rip)      # 0xe2b8
movq 0xb45f(%rip), %rsi      # 0xe2c0
movl $0x2710, %edx           # imm = 0x2710
cmovel %r14d, %edx
movl %ebx, %ecx
callq 0x2120
movl %eax, %r12d
cmpl $-0x1, %eax
jne 0x2e81
callq 0x2030
movl (%rax), %r14d
testb $0x1, %r15b
je 0x2e8c
callq 0x81cd
testl %r14d, %r14d
je 0x2ea2
cmpl $0x4, %r14d
jne 0x3087
xorl %eax, %eax
jmp 0x309b
testl %r12d, %r12d
je 0x30aa
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
imulq $0xc, %r12, %rax
movq %rax, -0x30(%rbp)
xorl %r14d, %r14d
cmpq %r14, -0x30(%rbp)
je 0x2e9b
movq 0xb3f4(%rip), %rax      # 0xe2c0
movq 0x4(%rax,%r14), %rcx
movq %rcx, %r12
andq $-0x2, %r12
movl 0x18(%r12), %esi
cmpl $-0x1, %esi
je 0x3061
movl %ecx, %ebx
andl $0x1, %ebx
movq 0x8(%r12), %r13
btl $0x2, 0x8(%r13)
movl %ebx, %edx
sbbl $0x0, %edx
jne 0x3061
movl (%rax,%r14), %r15d
leaq 0x65d8(%rip), %rdi      # 0x94e4
movl %r15d, %edx
xorl %eax, %eax
callq 0x6706
testb $0x18, %r15b
je 0x2f36
movl 0x18(%r12), %esi
leaq 0x65df(%rip), %rdi      # 0x9507
movl %r15d, %edx
xorl %eax, %eax
callq 0x6706
orl $0x5, %r15d
testb $0x1, %r15b
je 0x2fe8
movl 0x8(%r13), %eax
testb $0x8, %al
je 0x2fe8
btl $0xd, %r15d
jae 0x2f71
movl 0x18(%r12), %esi
leaq 0x65cd(%rip), %rdi      # 0x952c
xorl %eax, %eax
callq 0x6706
movl 0x8(%r13), %eax
movl $0x4000, %ecx           # imm = 0x4000
orl %ecx, %eax
orl $0x100000, %eax         # imm = 0x100000
movl %eax, 0x8(%r13)
movl 0x18(%r12), %esi
leaq 0x65ba(%rip), %rdi      # 0x9540
xorl %eax, %eax
callq 0x6706
movl 0x8(%r13), %eax
movl %eax, %ecx
orl $0x20, %ecx
movl %ecx, 0x8(%r13)
leaq 0x65c8(%rip), %rdi      # 0x9569
testw %ax, %ax
js 0x2fde
leaq 0xb31b(%rip), %rcx      # 0xe2c8
testb $0x2, %al
jne 0x2fb8
leaq 0xb320(%rip), %rcx      # 0xe2d8
orl $0x8020, %eax           # imm = 0x8020
movl %eax, 0x8(%r13)
movq (%rcx), %rax
leaq 0x48(%r13), %rdx
movq %rax, 0x48(%r13)
movq %rdx, 0x8(%rax)
movq %rcx, 0x50(%r13)
movq %rdx, (%rcx)
leaq 0x6576(%rip), %rdi      # 0x9554
movq %r13, %rsi
xorl %eax, %eax
callq 0x6706
testb $0x4, %r15b
je 0x3072
movq 0x10(%r12), %r15
movl 0x8(%r15), %eax
testb $0x8, %al
je 0x3072
movl 0x18(%r12), %esi
cmpl $-0x1, %esi
je 0x3061
btl $0x2, %eax
sbbl $0x0, %ebx
jne 0x3061
leaq 0x6567(%rip), %rdi      # 0x9580
xorl %eax, %eax
callq 0x6706
movl 0x8(%r15), %eax
movl %eax, %ecx
orl $0x20, %ecx
movl %ecx, 0x8(%r15)
testw %ax, %ax
js 0x307b
orl $0x8020, %eax           # imm = 0x8020
movl %eax, 0x8(%r15)
leaq 0xb296(%rip), %rdx      # 0xe2d8
movq (%rdx), %rax
leaq 0x48(%r15), %rcx
movq %rax, 0x48(%r15)
movq %rcx, 0x8(%rax)
movq %rdx, 0x50(%r15)
movq %rcx, (%rdx)
leaq 0x64f5(%rip), %rdi      # 0x9554
jmp 0x3082
leaq 0x6466(%rip), %rdi      # 0x94ce
movq %r12, %rsi
xorl %eax, %eax
callq 0x6706
addq $0xc, %r14
jmp 0x2ebf
leaq 0x64e7(%rip), %rdi      # 0x9569
movq %r15, %rsi
jmp 0x306b
leaq 0x63fc(%rip), %rsi      # 0x948a
movl %r14d, %edi
xorl %eax, %eax
callq 0x65bd
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $-0x1, %rbx
jne 0x2e9b
leaq 0x63e3(%rip), %rsi      # 0x949e
xorl %edi, %edi
jmp 0x3091
nop