// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl %esi, %r12d
testb $0x3, %r12b
je 0x1b2c1
movq %rdi, %rbx
movl %r12d, %eax
andl $0x6, %eax
xorl %ebp, %ebp
cmpl $0x2, %eax
je 0x1b27e
cmpl $-0x1, (%rbx)
je 0x1b44d
cmpl $0x2, %eax
jne 0x1b2c8
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x1b35e
movl %r12d, %r14d
xorl %r13d, %r13d
testq %r13, %r13
je 0x1b2a5
movq 0x8(%r13), %rcx
cmpq %rcx, 0x8(%rax)
jge 0x1b2b3
movq %rax, %r13
movq 0x30(%rax), %rax
testq %rax, %rax
jne 0x1b296
jmp 0x1b2df
jne 0x1b2a8
movq 0x10(%rax), %rcx
cmpq 0x10(%r13), %rcx
jl 0x1b2a5
jmp 0x1b2a8
xorl %ebp, %ebp
jmp 0x1b614
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testb $0x4, %r12b
je 0x1b364
xorl %r15d, %r15d
xorl %eax, %eax
jmp 0x1b359
xorl %r15d, %r15d
leaq 0x18(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x10240
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%r12)
movq %rdx, %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rcx
addq %rax, %rcx
movq 0x8(%r13), %rax
subq (%r12), %rax
addq 0x10(%r13), %rcx
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
addq %rax, %rcx
movl $0x0, %eax
testq %rcx, %rcx
movl %r14d, %r12d
jle 0x1b359
movq %rcx, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
mulq %rdx
shrq $0x4, %rdx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
subq %rax, %rcx
movq %rcx, %r15
addl %eax, %r15d
jmp 0x1b364
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq 0x38(%rbx), %r14
movl (%r14), %edi
movq 0x8(%r14), %rsi
movl 0x4(%rbx), %edx
movl %r15d, %ecx
callq 0x104d0
testl %eax, %eax
jle 0x1b44d
movl %r12d, 0x10(%rsp)
movq 0x8(%r14), %r11
movq 0x20(%rbx), %rcx
movl %eax, 0xc(%rsp)
movl %eax, %r13d
addq $0x4, %r11
xorl %edx, %edx
movl $0x2, %esi
movl -0x4(%r11), %edi
movl (%r11), %r8d
movl %edi, %r9d
andl $0x1, %r9d
movl %edi, %r10d
shrl %r10d
andl $0x2, %r10d
testb $0x18, %dil
cmovnel %esi, %r10d
orl %r9d, %r10d
movl %r8d, (%rcx,%rdx,8)
movl %r10d, 0x4(%rcx,%rdx,8)
incq %rdx
addq $0xc, %r11
cmpq %rdx, %r13
jne 0x1b3a1
xorl %r15d, %r15d
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movslq (%rcx,%r15,8), %r12
movq %r12, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %r14
movl 0x4(%rcx,%r15,8), %ebp
movl (%rax,%rdx), %eax
andl %ebp, %eax
testb $0x1, %al
je 0x1b426
movq 0x18(%r14), %rdx
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %ecx
callq *0x8(%r14)
movl (%r14), %eax
andl %ebp, %eax
testb $0x2, %al
je 0x1b43c
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rax
jne 0x1b42e
jmp 0x1b43c
testb $0x2, %al
je 0x1b43c
movq 0x10(%r14), %rax
movq 0x18(%r14), %rdx
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %ecx
callq *%rax
incq %r15
cmpq %r15, %r13
jne 0x1b3dc
movl 0xc(%rsp), %ebp
movl 0x10(%rsp), %r12d
testb $0x2, %r12b
je 0x1b614
movl %ebp, 0xc(%rsp)
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x10410
movq 0x28(%rbx), %r12
cmpq 0x10(%rbx), %rax
jge 0x1b48c
testq %r12, %r12
je 0x1b608
movq %r12, %rcx
movq $0x0, 0x8(%rcx)
movq 0x30(%rcx), %rcx
testq %rcx, %rcx
jne 0x1b47b
movq %rax, 0x10(%rbx)
testq %r12, %r12
je 0x1b60c
leaq 0x28(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rbx), %rbp
xorl %r15d, %r15d
xorl %r13d, %r13d
movq (%r12), %rax
cmpq $-0x1, %rax
je 0x1b59e
cmpq %rbp, %rax
jge 0x1b5d1
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x10240
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x20(%rsp)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movq 0x8(%r12), %rax
cmpq %rax, 0x18(%rsp)
jle 0x1b5db
movq (%r12), %rsi
movq 0x28(%r12), %rdx
movq %rbx, %rdi
callq *0x18(%r12)
incl %r15d
cmpl $-0x1, %eax
je 0x1b5ea
movl %eax, %r13d
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x10240
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x20(%rsp)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movslq %r13d, %rax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x26, %rax
addl %ecx, %eax
cltq
movq 0x18(%rsp), %rcx
addq %rax, %rcx
imull $0x3e8, %eax, %eax      # imm = 0x3E8
subl %eax, %r13d
movslq %r13d, %rax
leaq (%rdx,%rax), %rsi
xorl %edi, %edi
cmpq $0x3e8, %rsi            # imm = 0x3E8
leaq -0x3e8(%rax,%rdx), %rax
cmovlq %rsi, %rax
setge %dil
addq %rcx, %rdi
movq %rdi, 0x8(%r12)
movq %rax, 0x10(%r12)
jmp 0x1b5f2
leaq 0x30(%r13), %rax
testq %r13, %r13
cmoveq 0x10(%rsp), %rax
movq 0x30(%r12), %r14
movq %r14, (%rax)
movq 0x20(%r12), %rax
testq %rax, %rax
je 0x1b5c7
movq 0x28(%r12), %rsi
movq %rbx, %rdi
callq *%rax
movq %r12, %rdi
callq 0x1a877
jmp 0x1b5d6
movq 0x30(%r12), %r14
movq %r13, %r12
jmp 0x1b5f7
jne 0x1b5f2
cmpq 0x10(%r12), %rdx
jge 0x1b4fc
jmp 0x1b5f2
movq $-0x1, (%r12)
movq 0x30(%r12), %r14
movq %r12, %r13
movq %r14, %r12
testq %r14, %r14
jne 0x1b4ac
jmp 0x1b60c
movq %rax, 0x10(%rbx)
addl 0xc(%rsp), %r15d
movl %r15d, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq