// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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, %ebp
testb $0x3, %bpl
je 0x12c98
movq %rdi, %rbx
movl %ebp, %eax
andl $0x6, %eax
cmpl $0x2, %eax
je 0x12c5c
xorl %r14d, %r14d
cmpl $-0x1, (%rbx)
je 0x12e85
cmpl $0x2, %eax
jne 0x12ca0
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x12ca0
xorl %r15d, %r15d
testq %r15, %r15
je 0x12c7c
movq 0x8(%r15), %rcx
cmpq %rcx, 0x8(%rax)
jge 0x12c8a
movq %rax, %r15
movq 0x30(%rax), %rax
testq %rax, %rax
jne 0x12c6d
jmp 0x12ca3
jne 0x12c7f
movq 0x10(%rax), %rcx
cmpq 0x10(%r15), %rcx
jl 0x12c7c
jmp 0x12c7f
xorl %r14d, %r14d
jmp 0x13032
xorl %r15d, %r15d
testq %r15, %r15
je 0x12d25
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb200
movabsq $-0x20c49ba5e353f7cf, %rax # imm = 0xDF3B645A1CAC0831
imulq 0x8(%r14)
movq %rdx, %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rcx
addq %rax, %rcx
movq 0x8(%r15), %rax
subq (%r14), %rax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
addq 0x10(%r15), %rcx
addq %rax, %rcx
testq %rcx, %rcx
jle 0x12d30
movq %rcx, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
mulq %rdx
shrq $0x4, %rdx
movq %rdx, 0x10(%rsp)
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
subq %rax, %rcx
imulq $0x3e8, %rcx, %rax      # imm = 0x3E8
movq %rax, 0x18(%rsp)
jmp 0x12d46
testb $0x4, %bpl
jne 0x12d3a
xorl %r14d, %r14d
jmp 0x12d46
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
jmp 0x12d46
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 0x12d80
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 0x12d85
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %r8d, %edx
callq 0xb3f0
xorl %r14d, %r14d
movl $0x0, %ecx
testl %eax, %eax
movq %rbx, 0x8(%rsp)
jle 0x12df0
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 0x12db4
movl %eax, %ecx
movq 0x8(%rsp), %rbx
testl %ecx, %ecx
je 0x12e85
movl %ebp, 0x4(%rsp)
movl %ecx, 0x24(%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 0x12e3f
movq 0x18(%r12), %rdx
movl %r14d, %esi
movl %r15d, %ecx
callq *0x8(%r12)
movl (%r12), %eax
andl %r15d, %eax
testb $0x2, %al
je 0x12e6f
testl %ebx, %ebx
je 0x12e5a
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rax
je 0x12e6f
movq 0x18(%r12), %rdx
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %ecx
callq *0x10(%r12)
incq %rbp
cmpq %rbp, %r13
movq 0x8(%rsp), %rbx
jne 0x12e05
movl 0x24(%rsp), %r14d
movl 0x4(%rsp), %ebp
testb $0x2, %bpl
je 0x13032
movl %r14d, 0x4(%rsp)
xorl %r12d, %r12d
xorl %edi, %edi
callq 0xb350
cmpq 0x10(%rbx), %rax
jge 0x12ebb
movq 0x28(%rbx), %rcx
testq %rcx, %rcx
je 0x12ebb
movq $0x0, 0x8(%rcx)
movq 0x30(%rcx), %rcx
jmp 0x12ea8
movq %rax, 0x10(%rbx)
movq 0x28(%rbx), %r13
testq %r13, %r13
je 0x1302a
leaq 0x28(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %r14
xorl %r12d, %r12d
xorl %ebp, %ebp
movq (%r13), %rax
cmpq $-0x1, %rax
je 0x12fc8
cmpq %r14, %rax
jge 0x12ff8
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0xb200
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x18(%rsp)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movq 0x8(%r13), %rax
cmpq %rax, 0x10(%rsp)
jle 0x13001
movq (%r13), %rsi
movq 0x28(%r13), %rdx
movq %rbx, %rdi
callq *0x18(%r13)
incl %r12d
cmpl $-0x1, %eax
je 0x1300f
movslq %eax, %rbp
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0xb200
movabsq $0x20c49ba5e353f7cf, %rdi # imm = 0x20C49BA5E353F7CF
movq %rdi, %rax
imulq 0x18(%rsp)
movq %rdx, %rcx
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rcx
movq %rbp, %rax
imulq %rdi
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
addq 0x10(%rsp), %rdx
addq %rsi, %rcx
subq %rax, %rbp
leaq (%rcx,%rbp), %rax
xorl %esi, %esi
movl $0x3e8, %edi            # imm = 0x3E8
cmpq %rdi, %rax
leaq -0x3e8(%rcx,%rbp), %rcx
cmovlq %rax, %rcx
setge %sil
addq %rdx, %rsi
movq %rsi, 0x8(%r13)
movq %rcx, 0x10(%r13)
jmp 0x13017
leaq 0x30(%rbp), %rax
testq %rbp, %rbp
cmoveq 0x8(%rsp), %rax
movq 0x30(%r13), %r15
movq %r15, (%rax)
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x12fee
movq 0x28(%r13), %rsi
movq %rbx, %rdi
callq *%rax
movq %r13, %rdi
callq 0x15e7b
jmp 0x12ffc
movq 0x30(%r13), %r15
movq %rbp, %r13
jmp 0x1301b
jne 0x13017
cmpq 0x10(%r13), %rdx
jge 0x12f2d
jmp 0x13017
movq $-0x1, (%r13)
movq 0x30(%r13), %r15
movq %r13, %rbp
movq %r15, %r13
testq %r15, %r15
jne 0x12ede
addl 0x4(%rsp), %r12d
movl %r12d, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq