// File: /workspace/github_c_makefile_star2_O3/erikdubbelboer[P]discnt/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;

            /* Calculate the time missing for the nearest
             * timer to fire. */
            aeGetTime(&now_sec, &now_ms);
            tvp = &tv;
            tvp->tv_sec = shortest->when_sec - now_sec;
            if (shortest->when_ms < now_ms) {
                tvp->tv_usec = ((shortest->when_ms+1000) - now_ms)*1000;
                tvp->tv_sec --;
            } else {
                tvp->tv_usec = (shortest->when_ms - now_ms)*1000;
            }
            if (tvp->tv_sec < 0) tvp->tv_sec = 0;
            if (tvp->tv_usec < 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, %r13d
testb $0x3, %r13b
je 0x17085
movq %rdi, %rbx
movl %r13d, %eax
andl $0x6, %eax
xorl %ebp, %ebp
cmpl $0x2, %eax
je 0x17043
cmpl $-0x1, (%rbx)
je 0x1720b
cmpl $0x2, %eax
jne 0x1708c
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x17120
xorl %r12d, %r12d
testq %r12, %r12
je 0x17068
movq 0x8(%r12), %rcx
cmpq %rcx, 0x8(%rax)
jge 0x17076
movq %rax, %r12
movq 0x30(%rax), %rax
testq %rax, %rax
jne 0x17058
jmp 0x1709b
jne 0x1706b
movq 0x10(%rax), %rcx
cmpq 0x10(%r12), %rcx
jl 0x17068
jmp 0x1706b
xorl %ebp, %ebp
jmp 0x173bb
xorl %ecx, %ecx
btl $0x2, %r13d
adcl $-0x1, %ecx
jmp 0x17125
xorl %r14d, %r14d
leaq 0x28(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x12340
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
movq %rcx, %rax
imulq 0x8(%r15)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdi
movq %rdi, %rax
subq %rdx, %rax
imulq $0x3e8, %rax, %r8       # imm = 0x3E8
leaq 0xf4240(%r8), %rax
xorl %r9d, %r9d
cmpq %rdx, %rdi
setl %r9b
cmovgeq %r8, %rax
subq (%r15), %rsi
subq %r9, %rsi
testq %rsi, %rsi
cmovleq %r14, %rsi
testq %rax, %rax
cmovleq %r14, %rax
mulq %rcx
movq %rdx, %rcx
imull $0x3e8, %esi, %eax      # imm = 0x3E8
shrq $0x7, %rcx
addl %eax, %ecx
jmp 0x17125
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x38(%rbx), %r14
movl (%r14), %edi
movq 0x8(%r14), %rsi
movl 0x4(%rbx), %edx
callq 0x12680
testl %eax, %eax
jle 0x1720b
movl %r13d, 0x8(%rsp)
movq 0x8(%r14), %r11
movq 0x20(%rbx), %rcx
movl %eax, 0x10(%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 0x1715f
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 0x171e4
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 0x171fa
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rax
jne 0x171ec
jmp 0x171fa
testb $0x2, %al
je 0x171fa
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 0x1719a
movl 0x10(%rsp), %ebp
movl 0x8(%rsp), %r13d
testb $0x2, %r13b
je 0x173bb
movl %ebp, 0x1c(%rsp)
movq $0x0, 0x8(%rsp)
xorl %edi, %edi
callq 0x12540
movq 0x28(%rbx), %r14
cmpq 0x10(%rbx), %rax
jge 0x17250
testq %r14, %r14
je 0x173ac
movq %r14, %rcx
movq $0x0, 0x8(%rcx)
movq 0x30(%rcx), %rcx
testq %rcx, %rcx
jne 0x1723f
movq %rax, 0x10(%rbx)
testq %r14, %r14
je 0x173b0
leaq 0x28(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rbx), %r15
movq $0x0, 0x8(%rsp)
leaq 0x28(%rsp), %r13
movabsq $0x20c49ba5e353f7cf, %rbp # imm = 0x20C49BA5E353F7CF
movq %r15, 0x20(%rsp)
cmpq %r15, (%r14)
jge 0x1737d
movq %r13, %rdi
xorl %esi, %esi
callq 0x12340
movq %rbp, %rax
imulq 0x30(%rsp)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movq 0x8(%r14), %rax
cmpq %rax, 0x28(%rsp)
jle 0x17371
movq %rbp, %r15
movq %r13, %rbp
movq (%r14), %r13
movq 0x28(%r14), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq *0x18(%r14)
movl %eax, %r12d
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
cmpl $-0x1, %r12d
je 0x17383
movq %rbp, %r13
movq %rbp, %rdi
xorl %esi, %esi
callq 0x12340
movq %r15, %rbp
movq %r15, %rax
imulq 0x30(%rsp)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movslq %r12d, %rax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x26, %rax
addl %ecx, %eax
cltq
movq 0x28(%rsp), %rcx
addq %rax, %rcx
imull $0x3e8, %eax, %eax      # imm = 0x3E8
subl %eax, %r12d
movslq %r12d, %rax
leaq (%rdx,%rax), %rsi
xorl %edi, %edi
cmpq $0x3e8, %rsi            # imm = 0x3E8
setge %dil
leaq -0x3e8(%rax,%rdx), %rax
cmovlq %rsi, %rax
addq %rcx, %rdi
movq %rdi, 0x8(%r14)
movq %rax, 0x10(%r14)
movq 0x10(%rsp), %r14
jmp 0x17399
jne 0x1737d
cmpq 0x10(%r14), %rdx
jge 0x172bf
addq $0x30, %r14
jmp 0x1739e
movq %rbx, %rdi
movq %r13, %rsi
callq 0x16fb3
movq 0x10(%rsp), %r14
movq %rbp, %r13
movq %r15, %rbp
movq 0x20(%rsp), %r15
movq (%r14), %r14
testq %r14, %r14
jne 0x17287
jmp 0x173b0
movq %rax, 0x10(%rbx)
movq 0x8(%rsp), %rax
addl 0x1c(%rsp), %eax
movl %eax, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq