// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rsi
leaq 0xc04f(%rip), %rdi      # 0xf47a
movb $0x0, %al
callq 0x9e70
movl 0x10d88(%rip), %edi     # 0x141c0
movq 0x10eb1(%rip), %rsi     # 0x142f0
movq 0x10ea2(%rip), %rax     # 0x142e8
movl %eax, %edx
movq -0x10(%rbp), %rax
movl %eax, %ecx
callq 0x2130
movl %eax, -0x1c(%rbp)
cmpl $-0x1, -0x1c(%rbp)
jne 0x3468
callq 0x2030
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
jmp 0x346f
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0x346f
movl -0x5c(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x3488
callq 0xd3e0
cmpl $0x0, -0x34(%rbp)
je 0x34bf
cmpl $0x4, -0x34(%rbp)
jne 0x34a1
movq $0x0, -0x8(%rbp)
jmp 0x3875
movl -0x34(%rbp), %edi
leaq 0xbfdf(%rip), %rsi      # 0xf48a
movb $0x0, %al
callq 0x9cc0
movq $-0x1, -0x8(%rbp)
jmp 0x3875
cmpl $0x0, -0x1c(%rbp)
jne 0x34f7
cmpq $-0x1, -0x10(%rbp)
je 0x34d9
movq $0x0, -0x8(%rbp)
jmp 0x3875
movl -0x34(%rbp), %edi
leaq 0xbfbb(%rip), %rsi      # 0xf49e
movb $0x0, %al
callq 0x9cc0
movq $-0x1, -0x8(%rbp)
jmp 0x3875
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x386d
movq 0x10dd9(%rip), %rax     # 0x142f0
imulq $0xc, -0x30(%rbp), %rcx
addq %rcx, %rax
movq 0x4(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
andq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x50(%rbp), %rax
andq $-0x2, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
cmpl $-0x1, 0x18(%rax)
je 0x356a
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0x2, %eax
andl $0x1, %eax
movl %eax, %eax
cmpq -0x28(%rbp), %rax
je 0x3581
movq -0x50(%rbp), %rsi
leaq 0xbf59(%rip), %rdi      # 0xf4ce
movb $0x0, %al
callq 0x9e70
jmp 0x385c
movq 0x10d68(%rip), %rax     # 0x142f0
imulq $0xc, -0x30(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x50(%rbp), %rax
movl 0x18(%rax), %esi
movl -0x20(%rbp), %edx
movq 0x10d4a(%rip), %rax     # 0x142f0
imulq $0xc, -0x30(%rbp), %rcx
addq %rcx, %rax
movq 0x4(%rax), %rcx
leaq 0xbf2b(%rip), %rdi      # 0xf4e4
movb $0x0, %al
callq 0x9e70
movl -0x20(%rbp), %eax
andl $0x18, %eax
cmpl $0x0, %eax
je 0x35ec
movq -0x50(%rbp), %rax
movl 0x18(%rax), %esi
movl -0x20(%rbp), %edx
leaq 0xbf2b(%rip), %rdi      # 0xf507
movb $0x0, %al
callq 0x9e70
movl -0x20(%rbp), %eax
orl $0x5, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3737
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0x3, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3737
movl -0x20(%rbp), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x3649
movq -0x50(%rbp), %rax
movl 0x18(%rax), %esi
leaq 0xbf00(%rip), %rdi      # 0xf52c
movb $0x0, %al
callq 0x9e70
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xffffbfff, %ecx       # imm = 0xFFFFBFFF
orl $0x4000, %ecx           # imm = 0x4000
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xffefffff, %ecx       # imm = 0xFFEFFFFF
orl $0x100000, %ecx         # imm = 0x100000
movl %ecx, 0x8(%rax)
movq -0x50(%rbp), %rax
movl 0x18(%rax), %esi
leaq 0xbed3(%rip), %rdi      # 0xf540
movb $0x0, %al
callq 0x9e70
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x20, %ecx
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edx
shrl %edx
andl $0x1, %edx
leaq 0x10c71(%rip), %rax     # 0x14308
leaq 0x10c5a(%rip), %rcx     # 0x142f8
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0xf, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x3723
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xffff7fff, %ecx       # imm = 0xFFFF7FFF
orl $0x8000, %ecx           # imm = 0x8000
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rax
movq (%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rcx
addq $0x48, %rcx
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x40(%rbp), %rcx
addq $0x48, %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rsi
leaq 0xbe3a(%rip), %rdi      # 0xf554
movb $0x0, %al
callq 0x9e70
jmp 0x3735
movq -0x40(%rbp), %rsi
leaq 0xbe3b(%rip), %rdi      # 0xf569
movb $0x0, %al
callq 0x9e70
jmp 0x3737
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x20(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x385a
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0x3, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x385a
movq -0x50(%rbp), %rax
cmpl $-0x1, 0x18(%rax)
je 0x3787
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0x2, %eax
andl $0x1, %eax
movl %eax, %eax
cmpq -0x28(%rbp), %rax
je 0x379e
movq -0x50(%rbp), %rsi
leaq 0xbd3c(%rip), %rdi      # 0xf4ce
movb $0x0, %al
callq 0x9e70
jmp 0x385c
movq -0x50(%rbp), %rax
movl 0x18(%rax), %esi
leaq 0xbdd4(%rip), %rdi      # 0xf580
movb $0x0, %al
callq 0x9e70
movq -0x48(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x20, %ecx
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0xf, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x3846
movq -0x48(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xffff7fff, %ecx       # imm = 0xFFFF7FFF
orl $0x8000, %ecx           # imm = 0x8000
movl %ecx, 0x8(%rax)
leaq 0x10b16(%rip), %rax     # 0x14308
movq (%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x48(%rbp), %rcx
addq $0x48, %rcx
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rax
leaq 0x10aec(%rip), %rcx     # 0x14308
movq %rcx, 0x50(%rax)
movq -0x48(%rbp), %rcx
addq $0x48, %rcx
leaq 0x10ad9(%rip), %rax     # 0x14308
movq %rcx, (%rax)
movq -0x48(%rbp), %rsi
leaq 0xbd17(%rip), %rdi      # 0xf554
movb $0x0, %al
callq 0x9e70
jmp 0x3858
movq -0x48(%rbp), %rsi
leaq 0xbd18(%rip), %rdi      # 0xf569
movb $0x0, %al
callq 0x9e70
jmp 0x385a
jmp 0x385c
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x34ff
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop