// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/ae.c
// Function: aeProcessEvents
int aeProcessEvents(aeEventLoop *eventLoop, int flags)
{
    int processed = 0, numevents;

    /* Nothing to do? return ASAP */
    if (!(flags & AE_TIME_EVENTS) && !(flags & AE_FILE_EVENTS)) return 0;

    /* Note that we want call select() even if there are no
     * file events to process as long as we want to process time
     * events, in order to sleep until the next time event is ready
     * to fire. */
    if (eventLoop->maxfd != -1 ||
        ((flags & AE_TIME_EVENTS) && !(flags & AE_DONT_WAIT))) {
        int j;
        aeTimeEvent *shortest = NULL;
        struct timeval tv, *tvp;

        if (flags & AE_TIME_EVENTS && !(flags & AE_DONT_WAIT))
            shortest = aeSearchNearestTimer(eventLoop);
        if (shortest) {
            long now_sec, now_ms;

            aeGetTime(&now_sec, &now_ms);
            tvp = &tv;

            /* How many milliseconds we need to wait for the next
             * time event to fire? */
            long long ms =
                (shortest->when_sec - now_sec)*1000 +
                shortest->when_ms - now_ms;

            if (ms > 0) {
                tvp->tv_sec = ms/1000;
                tvp->tv_usec = (ms % 1000)*1000;
            } else {
                tvp->tv_sec = 0;
                tvp->tv_usec = 0;
            }
        } else {
            /* If we have to check for events but need to return
             * ASAP because of AE_DONT_WAIT we need to set the timeout
             * to zero */
            if (flags & AE_DONT_WAIT) {
                tv.tv_sec = tv.tv_usec = 0;
                tvp = &tv;
            } else {
                /* Otherwise we can block */
                tvp = NULL; /* wait forever */
            }
        }

        numevents = aeApiPoll(eventLoop, tvp);
        for (j = 0; j < numevents; j++) {
            aeFileEvent *fe = &eventLoop->events[eventLoop->fired[j].fd];
            int mask = eventLoop->fired[j].mask;
            int fd = eventLoop->fired[j].fd;
            int rfired = 0;

	    /* note the fe->mask & mask & ... code: maybe an already processed
             * event removed an element that fired and we still didn't
             * processed, so we check if the event is still valid. */
            if (fe->mask & mask & AE_READABLE) {
                rfired = 1;
                fe->rfileProc(eventLoop,fd,fe->clientData,mask);
            }
            if (fe->mask & mask & AE_WRITABLE) {
                if (!rfired || fe->wfileProc != fe->rfileProc)
                    fe->wfileProc(eventLoop,fd,fe->clientData,mask);
            }
            processed++;
        }
    }
    /* Check time events */
    if (flags & AE_TIME_EVENTS)
        processed += processTimeEvents(eventLoop);

    return processed; /* return the number of processed file/time events */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
testb $0x3, %bpl
je 0x16d46
movq %rdi, %rbx
movl %ebp, %ecx
andl $0x6, %ecx
cmpl $0x2, %ecx
je 0x16d08
xorl %eax, %eax
cmpl $-0x1, (%rbx)
je 0x16ecd
cmpl $0x2, %ecx
jne 0x16d95
leaq 0x28(%rbx), %rax
xorl %r13d, %r13d
movq (%rax), %rax
testq %rax, %rax
je 0x16d4d
testq %r13, %r13
je 0x16d2f
movq 0x8(%r13), %rcx
cmpq %rcx, 0x8(%rax)
jge 0x16d38
movq %rax, %r13
addq $0x30, %rax
jmp 0x16d18
jne 0x16d32
movq 0x10(%rax), %rcx
cmpq 0x10(%r13), %rcx
jl 0x16d2f
jmp 0x16d32
xorl %eax, %eax
jmp 0x16fe1
testq %r13, %r13
je 0x16d95
leaq 0x18(%rsp), %r15
leaq 0x30(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x16ff0
movq 0x8(%r13), %rax
subq (%r15), %rax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
addq 0x10(%r13), %rax
subq (%r12), %rax
testq %rax, %rax
jle 0x16dac
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
imulq $0x3e8, %rdx, %rcx      # imm = 0x3E8
jmp 0x16db0
testb $0x4, %bpl
jne 0x16d9f
xorl %edx, %edx
jmp 0x16dbc
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
jmp 0x16dbc
xorl %eax, %eax
xorl %ecx, %ecx
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
movq %rcx, 0x8(%rdx)
movq 0x38(%rbx), %r14
movl (%r14), %edi
movq 0x8(%r14), %rsi
movl 0x4(%rbx), %ecx
testq %rdx, %rdx
je 0x16dea
imull $0x3e8, (%rdx), %r8d    # imm = 0x3E8
movq 0x8(%rdx), %rax
movl $0x3e8, %r9d            # imm = 0x3E8
cqto
idivq %r9
addl %r8d, %eax
jmp 0x16ded
pushq $-0x1
popq %rax
movl %ecx, %edx
movl %eax, %ecx
callq 0x104d0
testl %eax, %eax
movl %ebp, 0x10(%rsp)
jle 0x16e4c
movl %eax, %r15d
movq 0x8(%r14), %rcx
movq 0x20(%rbx), %rdx
addq $0x4, %rcx
xorl %esi, %esi
pushq $0x2
popq %rdi
cmpq %rsi, %r15
je 0x16e4e
movl -0x4(%rcx), %r8d
movl (%rcx), %r9d
movl %r8d, %r10d
andl $0x1, %r10d
movl %r8d, %r11d
shrl %r11d
andl $0x2, %r11d
testb $0x18, %r8b
cmovnel %edi, %r11d
orl %r10d, %r11d
movl %r9d, (%rdx,%rsi,8)
movl %r11d, 0x4(%rdx,%rsi,8)
incq %rsi
addq $0xc, %rcx
jmp 0x16e12
xorl %eax, %eax
movl %eax, 0xc(%rsp)
movl %eax, %r13d
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0x16ec5
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movslq (%rcx,%rbp,8), %r15
movq %r15, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %r14
movl 0x4(%rcx,%rbp,8), %r12d
movl (%rax,%rdx), %eax
andl %r12d, %eax
testb $0x1, %al
je 0x16ea9
movq 0x18(%r14), %rdx
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %ecx
callq *0x8(%r14)
movl (%r14), %eax
andl %r12d, %eax
testb $0x2, %al
je 0x16ec0
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rax
jne 0x16eb1
jmp 0x16ec0
testb $0x2, %al
je 0x16ec0
movq 0x10(%r14), %rax
movq 0x18(%r14), %rdx
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %ecx
callq *%rax
incq %rbp
jmp 0x16e57
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %ebp
testb $0x2, %bpl
je 0x16fe1
movl %eax, 0xc(%rsp)
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x10410
cmpq 0x10(%rbx), %rax
jge 0x16f02
leaq 0x28(%rbx), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x16f02
andq $0x0, 0x8(%rcx)
addq $0x30, %rcx
jmp 0x16eef
movq %rax, 0x10(%rbx)
leaq 0x28(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rbx), %r14
movq 0x28(%rbx), %r12
xorl %r15d, %r15d
testq %r12, %r12
je 0x16fd9
movq (%r12), %rax
cmpq $-0x1, %rax
je 0x16f7e
cmpq %r14, %rax
jge 0x16fcf
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x16ff0
movq 0x8(%r12), %rax
cmpq %rax, 0x20(%rsp)
jle 0x16fb7
movq (%r12), %rsi
movq 0x28(%r12), %rdx
movq %rbx, %rdi
callq *0x18(%r12)
incl %r13d
cmpl $-0x1, %eax
je 0x16fc7
leaq 0x8(%r12), %rsi
movslq %eax, %rdi
leaq 0x10(%r12), %rdx
callq 0x16c4a
jmp 0x16fcc
leaq 0x30(%r15), %rax
testq %r15, %r15
cmoveq 0x10(%rsp), %rax
movq 0x30(%r12), %rbp
movq %rbp, (%rax)
movq 0x20(%r12), %rax
testq %rax, %rax
je 0x16fa7
movq 0x28(%r12), %rsi
movq %rbx, %rdi
callq *%rax
movq %r12, %rdi
callq 0x1653d
movq %rbp, %r12
jmp 0x16f1a
jne 0x16fcc
movq 0x18(%rsp), %rax
cmpq 0x10(%r12), %rax
jge 0x16f51
jmp 0x16fcc
orq $-0x1, (%r12)
movq %r12, %r15
movq 0x30(%r12), %r12
jmp 0x16f1a
addl 0xc(%rsp), %r13d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq