// File: /workspace/github_c_makefile_star2_O2/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, %ebp
testb $0x3, %bpl
je 0x133bc
movq %rdi, %rbx
movl %ebp, %eax
andl $0x6, %eax
cmpl $0x2, %eax
je 0x1337c
xorl %r15d, %r15d
cmpl $-0x1, (%rbx)
je 0x13559
cmpl $0x2, %eax
jne 0x13432
leaq 0x28(%rbx), %rax
xorl %r12d, %r12d
movq (%rax), %rax
testq %rax, %rax
je 0x133c4
testq %r12, %r12
je 0x133a4
movq 0x8(%r12), %rcx
cmpq %rcx, 0x8(%rax)
jge 0x133ad
movq %rax, %r12
addq $0x30, %rax
jmp 0x1338c
jne 0x133a7
movq 0x10(%rax), %rcx
cmpq 0x10(%r12), %rcx
jl 0x133a4
jmp 0x133a7
xorl %r15d, %r15d
jmp 0x13622
testq %r12, %r12
je 0x13432
leaq 0x28(%rsp), %r14
leaq 0x30(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x13634
movq 0x8(%r12), %rcx
subq (%r14), %rcx
movq %rcx, 0x10(%rsp)
movq 0x10(%r12), %rax
movq (%r15), %rdx
cmpq %rdx, %rax
jge 0x13406
addq $0x3e8, %rax            # imm = 0x3E8
decq %rcx
movq %rcx, 0x10(%rsp)
subq %rdx, %rax
imulq $0x3e8, %rax, %rdx      # imm = 0x3E8
movq %rdx, 0x18(%rsp)
testq %rcx, %rcx
jns 0x13420
andq $0x0, 0x10(%rsp)
testq %rax, %rax
jns 0x1342b
andq $0x0, 0x18(%rsp)
leaq 0x10(%rsp), %rax
jmp 0x13447
testb $0x4, %bpl
jne 0x1343c
xorl %eax, %eax
jmp 0x13447
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
movq 0x38(%rbx), %r14
movl (%r14), %edi
movq 0x8(%r14), %rsi
movl 0x4(%rbx), %ecx
testq %rax, %rax
je 0x13475
imull $0x3e8, (%rax), %r8d    # imm = 0x3E8
movq 0x8(%rax), %rax
movl $0x3e8, %r9d            # imm = 0x3E8
cqto
idivq %r9
addl %r8d, %eax
jmp 0x13478
pushq $-0x1
popq %rax
movl %ecx, %edx
movl %eax, %ecx
callq 0x12680
testl %eax, %eax
movl %ebp, 0x24(%rsp)
jle 0x134d7
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 0x134d9
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 0x1349d
xorl %eax, %eax
movl %eax, 0xc(%rsp)
movl %eax, %r14d
xorl %r13d, %r13d
cmpq %r13, %r14
je 0x13550
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movslq (%rcx,%r13,8), %r15
movq %r15, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %rbp
movl 0x4(%rcx,%r13,8), %r12d
movl (%rax,%rdx), %eax
andl %r12d, %eax
testb $0x1, %al
je 0x13534
movq 0x18(%rbp), %rdx
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %ecx
callq *0x8(%rbp)
movl (%rbp), %eax
andl %r12d, %eax
testb $0x2, %al
je 0x1354b
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rax
jne 0x1353c
jmp 0x1354b
testb $0x2, %al
je 0x1354b
movq 0x10(%rbp), %rax
movq 0x18(%rbp), %rdx
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %ecx
callq *%rax
incq %r13
jmp 0x134e3
movl 0x24(%rsp), %ebp
movl 0xc(%rsp), %r15d
testb $0x2, %bpl
je 0x13622
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x12540
cmpq 0x10(%rbx), %rax
jge 0x1358a
leaq 0x28(%rbx), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x1358a
andq $0x0, 0x8(%rcx)
addq $0x30, %rcx
jmp 0x13577
movl %r15d, 0xc(%rsp)
movq %rax, 0x10(%rbx)
leaq 0x28(%rbx), %r15
movq 0x8(%rbx), %r12
movq 0x28(%rbx), %r13
testq %r13, %r13
je 0x1361a
cmpq %r12, (%r13)
jge 0x13600
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x13634
movq 0x8(%r13), %rax
cmpq %rax, 0x10(%rsp)
jle 0x135f3
movq (%r13), %rbp
movq 0x28(%r13), %rdx
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x18(%r13)
incl %r14d
cmpl $-0x1, %eax
je 0x13606
leaq 0x8(%r13), %rsi
movslq %eax, %rdi
addq $0x10, %r13
movq %r13, %rdx
callq 0x1328e
jmp 0x13611
jne 0x13600
movq 0x28(%rsp), %rax
cmpq 0x10(%r13), %rax
jge 0x135c4
addq $0x30, %r13
jmp 0x13614
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x132fd
movq %r15, %r13
movq (%r13), %r13
jmp 0x1359f
addl 0xc(%rsp), %r14d
movl %r14d, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq