// File: /workspace/github_c_makefile_star2_O1/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 0x173da
movq %rdi, %rbx
movl %ebp, %eax
andl $0x6, %eax
cmpl $0x2, %eax
je 0x1739e
xorl %r14d, %r14d
cmpl $-0x1, (%rbx)
je 0x175ca
cmpl $0x2, %eax
jne 0x173e2
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x173e2
xorl %r15d, %r15d
testq %r15, %r15
je 0x173be
movq 0x8(%r15), %rcx
cmpq %rcx, 0x8(%rax)
jge 0x173cc
movq %rax, %r15
movq 0x30(%rax), %rax
testq %rax, %rax
jne 0x173af
jmp 0x173e5
jne 0x173c1
movq 0x10(%rax), %rcx
cmpq 0x10(%r15), %rcx
jl 0x173be
jmp 0x173c1
xorl %r14d, %r14d
jmp 0x1772a
xorl %r15d, %r15d
testq %r15, %r15
je 0x1744b
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x12340
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x8(%r14)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movq 0x8(%r15), %rax
subq (%r14), %rax
movq %rax, (%r14)
movq 0x10(%r15), %rsi
movq %rsi, %rcx
subq %rdx, %rcx
imulq $0x3e8, %rcx, %rcx      # imm = 0x3E8
cmpq %rdx, %rsi
jge 0x17456
addq $0xf4240, %rcx          # imm = 0xF4240
movq %rcx, 0x18(%rsp)
decq %rax
movq %rax, 0x10(%rsp)
jmp 0x1745b
testb $0x4, %bpl
jne 0x1747f
xorl %r14d, %r14d
jmp 0x1748b
movq %rcx, 0x18(%rsp)
cmpq $0x0, 0x10(%rsp)
jns 0x1746c
movq $0x0, 0x10(%rsp)
cmpq $0x0, 0x18(%rsp)
jns 0x1748b
movq $0x0, 0x18(%rsp)
jmp 0x1748b
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
movq 0x38(%rbx), %r15
movl (%r15), %edi
movq 0x8(%r15), %rsi
movl 0x4(%rbx), %r8d
testq %r14, %r14
je 0x174c5
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x8(%r14)
movq %rdx, %rcx
imull $0x3e8, (%r14), %eax    # imm = 0x3E8
shrq $0x3f, %rdx
shrq $0x7, %rcx
addl %edx, %ecx
addl %eax, %ecx
jmp 0x174ca
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %r8d, %edx
callq 0x12690
xorl %r14d, %r14d
movl $0x0, %ecx
testl %eax, %eax
movq %rbx, 0x28(%rsp)
jle 0x17535
movq 0x8(%r15), %rcx
movq 0x20(%rbx), %rdx
movl %eax, %esi
addq $0x4, %rcx
xorl %edi, %edi
movl $0x2, %r8d
movl -0x4(%rcx), %r9d
movl (%rcx), %r10d
movl %r9d, %r11d
andl $0x1, %r11d
movl %r9d, %ebx
shrl %ebx
andl $0x2, %ebx
testb $0x18, %r9b
cmovnel %r8d, %ebx
orl %r11d, %ebx
movl %r10d, (%rdx,%rdi,8)
movl %ebx, 0x4(%rdx,%rdi,8)
incq %rdi
addq $0xc, %rcx
cmpq %rdi, %rsi
jne 0x174f9
movl %eax, %ecx
movq 0x28(%rsp), %rbx
testl %ecx, %ecx
je 0x175ca
movl %ebp, 0xc(%rsp)
movl %ecx, 0x34(%rsp)
movl %ecx, %r13d
xorl %ebp, %ebp
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movslq (%rcx,%rbp,8), %r14
movq %r14, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %r12
movl 0x4(%rcx,%rbp,8), %r15d
movq %rbx, %rdi
movl (%rax,%rdx), %ebx
andl %r15d, %ebx
andl $0x1, %ebx
je 0x17584
movq 0x18(%r12), %rdx
movl %r14d, %esi
movl %r15d, %ecx
callq *0x8(%r12)
movl (%r12), %eax
andl %r15d, %eax
testb $0x2, %al
je 0x175b4
testl %ebx, %ebx
je 0x1759f
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rax
je 0x175b4
movq 0x18(%r12), %rdx
movq 0x28(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %ecx
callq *0x10(%r12)
incq %rbp
cmpq %rbp, %r13
movq 0x28(%rsp), %rbx
jne 0x1754a
movl 0x34(%rsp), %r14d
movl 0xc(%rsp), %ebp
testb $0x2, %bpl
je 0x1772a
movl %r14d, 0xc(%rsp)
xorl %ebp, %ebp
xorl %edi, %edi
callq 0x12550
cmpq 0x10(%rbx), %rax
jge 0x175ff
movq 0x28(%rbx), %rcx
testq %rcx, %rcx
je 0x175ff
movq $0x0, 0x8(%rcx)
movq 0x30(%rcx), %rcx
jmp 0x175ec
movq %rax, 0x10(%rbx)
movq 0x28(%rbx), %r15
testq %r15, %r15
je 0x17723
leaq 0x28(%rbx), %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rbx), %r14
xorl %ebp, %ebp
movabsq $0x20c49ba5e353f7cf, %r12 # imm = 0x20C49BA5E353F7CF
cmpq %r14, (%r15)
jge 0x17701
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x12340
movq %r12, %rax
imulq 0x18(%rsp)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movq 0x8(%r15), %rax
cmpq %rax, 0x10(%rsp)
jle 0x176f5
movq (%r15), %r13
movq 0x28(%r15), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq *0x18(%r15)
incl %ebp
cmpl $-0x1, %eax
je 0x17707
movslq %eax, %r13
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x12340
movq %r12, %rax
imulq 0x18(%rsp)
movq %rdx, %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rcx
addq %rax, %rcx
movq %r13, %rax
imulq %r12
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
addq 0x10(%rsp), %rdx
subq %rax, %r13
leaq (%rcx,%r13), %rax
xorl %esi, %esi
movl $0x3e8, %edi            # imm = 0x3E8
cmpq %rdi, %rax
setge %sil
leaq -0x3e8(%rcx,%r13), %rcx
cmovlq %rax, %rcx
addq %rdx, %rsi
movq %rsi, 0x8(%r15)
movq %rcx, 0x10(%r15)
jmp 0x17712
jne 0x17701
cmpq 0x10(%r15), %rdx
jge 0x17663
addq $0x30, %r15
jmp 0x17717
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1730f
movq 0x28(%rsp), %r15
movq (%r15), %r15
testq %r15, %r15
jne 0x17629
addl 0xc(%rsp), %ebp
movl %ebp, %r14d
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq