// File: /workspace/github_c_makefile_star2_O1/yakushstanislav[P]EagleMQ/src/event.c
// Function: process_events
int process_events(EventLoop *loop, int flags)
{
	FileEvent *file_event;
	TimeEvent *shortest = NULL;
	struct timeval tv, *tvp;
	int processed = 0, i, mask, fd, rfired, events;
	long sec, ms;

	if (!(flags & EG_EVENT_TIME) && !(flags & EG_EVENT_FILE)) {
		return 0;
	}

	if (loop->maxfd != -1 || ((flags & EG_EVENT_TIME) && !(flags & EG_DONT_WAIT)))
	{
		if (flags & EG_EVENT_TIME && !(flags & EG_DONT_WAIT)) {
			shortest = search_nearest_timer(loop);
		}

		if (shortest)
		{
			get_time(&sec, &ms);

			tvp = &tv;
			tvp->tv_sec = shortest->sec - sec;

			if (shortest->ms < ms) {
				tvp->tv_usec = ((shortest->ms + 1000) - ms) * 1000;
				tvp->tv_sec--;
			} else {
				tvp->tv_usec = (shortest->ms - ms) * 1000;
			}

			if (tvp->tv_sec < 0) {
				tvp->tv_sec = 0;
			}

			if (tvp->tv_usec < 0) {
				tvp->tv_usec = 0;
			}
		} else {
			if (flags & EG_DONT_WAIT) {
				tv.tv_sec = tv.tv_usec = 0;
				tvp = &tv;
			} else {
				tvp = NULL;
			}
		}

		events = event_api_poll(loop, tvp);
		for (i = 0; i < events; i++)
		{
			file_event = &loop->events[loop->fired[i].fd];
			mask = loop->fired[i].mask;
			fd = loop->fired[i].fd;
			rfired = 0;

			if (file_event->mask & mask & EG_EVENT_READABLE) {
				rfired = 1;
				file_event->read_handler(loop, fd, file_event->data, mask);
			}

			if (file_event->mask & mask & EG_EVENT_WRITABLE) {
				if (!rfired || file_event->write_handler != file_event->read_handler) {
					file_event->write_handler(loop, fd, file_event->data, mask);
				}
			}
			processed++;
		}
	}

	if (flags & EG_EVENT_TIME) {
		processed += process_time_events(loop);
	}

	return processed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
testb $0x3, %bpl
je 0x3a57
movq %rdi, %r8
movl %ebp, %eax
andl $0x6, %eax
cmpl $0x2, %eax
movq %rdi, (%rsp)
je 0x3a1b
xorl %r14d, %r14d
cmpl $-0x1, (%r8)
je 0x3c50
cmpl $0x2, %eax
jne 0x3a5f
movq 0x20(%r8), %rax
testq %rax, %rax
je 0x3a5f
xorl %r15d, %r15d
testq %r15, %r15
je 0x3a3b
movq 0x8(%r15), %rcx
cmpq %rcx, 0x8(%rax)
jge 0x3a49
movq %rax, %r15
movq 0x30(%rax), %rax
testq %rax, %rax
jne 0x3a2c
jmp 0x3a62
jne 0x3a3e
movq 0x10(%rax), %rcx
cmpq 0x10(%r15), %rcx
jl 0x3a3b
jmp 0x3a3e
xorl %r14d, %r14d
jmp 0x3da9
xorl %r15d, %r15d
testq %r15, %r15
je 0x3aca
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x21b0
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, 0x10(%rsp)
movq 0x10(%r15), %rsi
movq %rsi, %rcx
subq %rdx, %rcx
imulq $0x3e8, %rcx, %rcx      # imm = 0x3E8
cmpq %rdx, %rsi
jge 0x3ad5
addq $0xf4240, %rcx          # imm = 0xF4240
movq %rcx, 0x18(%rsp)
decq %rax
movq %rax, 0x10(%rsp)
jmp 0x3ada
testb $0x4, %bpl
jne 0x3b06
xorl %r9d, %r9d
jmp 0x3b12
movq %rcx, 0x18(%rsp)
cmpq $0x0, 0x10(%rsp)
movq (%rsp), %r8
jns 0x3aef
movq $0x0, 0x10(%rsp)
leaq 0x10(%rsp), %r9
cmpq $0x0, 0x8(%r9)
jns 0x3b12
movq $0x0, 0x18(%rsp)
jmp 0x3b12
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r9
movaps %xmm0, (%r9)
movq 0x30(%r8), %r15
movl (%r15), %edi
movq 0x8(%r15), %rsi
movl 0x4(%r8), %r8d
testq %r9, %r9
je 0x3b4c
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x8(%r9)
movq %rdx, %rcx
imull $0x3e8, (%r9), %eax     # imm = 0x3E8
shrq $0x3f, %rdx
shrq $0x7, %rcx
addl %edx, %ecx
addl %eax, %ecx
jmp 0x3b51
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %r8d, %edx
callq 0x2350
xorl %r14d, %r14d
movl $0x0, %ecx
testl %eax, %eax
jle 0x3bb6
movq 0x8(%r15), %rcx
movq (%rsp), %rdx
movq 0x18(%rdx), %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 0x3b7f
movl %eax, %ecx
testl %ecx, %ecx
movq (%rsp), %r8
je 0x3c50
movl %ebp, 0x8(%rsp)
movl %ecx, 0x34(%rsp)
movl %ecx, %r13d
xorl %ebp, %ebp
movq 0x10(%r8), %rax
movq 0x18(%r8), %rcx
movslq (%rcx,%rbp,8), %r14
movq %r14, %rdx
shlq $0x5, %rdx
leaq (%rax,%rdx), %r12
movl 0x4(%rcx,%rbp,8), %r15d
movl (%rax,%rdx), %ebx
andl %r15d, %ebx
andl $0x1, %ebx
je 0x3c0d
movq 0x18(%r12), %rdx
movq %r8, %rdi
movl %r14d, %esi
movl %r15d, %ecx
callq *0x8(%r12)
movq (%rsp), %r8
movl (%r12), %eax
andl %r15d, %eax
testb $0x2, %al
je 0x3c3f
testl %ebx, %ebx
je 0x3c28
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rax
je 0x3c3f
movq 0x18(%r12), %rdx
movq %r8, %rdi
movl %r14d, %esi
movl %r15d, %ecx
callq *0x10(%r12)
movq (%rsp), %r8
incq %rbp
cmpq %rbp, %r13
jne 0x3bcf
movl 0x34(%rsp), %r14d
movl 0x8(%rsp), %ebp
testb $0x2, %bpl
je 0x3da9
movq 0x20(%r8), %r15
testq %r15, %r15
je 0x3da4
leaq 0x20(%r8), %rbx
movq 0x8(%r8), %r12
xorl %ebp, %ebp
leaq 0x20(%rsp), %r13
cmpq %r12, (%r15)
jl 0x3c89
movq 0x30(%r15), %r15
testq %r15, %r15
jne 0x3c76
jmp 0x3da6
movq %r13, %rdi
xorl %esi, %esi
callq 0x21b0
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq 0x28(%rsp)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movq 0x8(%r15), %rax
cmpq %rax, 0x20(%rsp)
jle 0x3d72
movq %rbx, 0x8(%rsp)
movq (%r15), %r13
movq 0x28(%r15), %rdx
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq *0x18(%r15)
incl %ebp
cmpl $-0x1, %eax
je 0x3d84
movslq %eax, %r13
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21b0
movabsq $0x20c49ba5e353f7cf, %rsi # imm = 0x20C49BA5E353F7CF
movq %rsi, %rax
imulq 0x28(%rsp)
movq %rdx, %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rcx
addq %rax, %rcx
movq %r13, %rax
imulq %rsi
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
addq 0x20(%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
movq %rbx, %r13
cmovlq %rax, %rcx
addq %rdx, %rsi
movq %rsi, 0x8(%r15)
movq %rcx, 0x10(%r15)
movq 0x8(%rsp), %rbx
movq %rbx, %r15
jmp 0x3d9c
jne 0x3d7e
cmpq 0x10(%r15), %rdx
jge 0x3cbf
addq $0x30, %r15
jmp 0x3d9c
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3987
movq 0x8(%rsp), %rbx
movq %rbx, %r15
leaq 0x20(%rsp), %r13
movq (%r15), %r15
jmp 0x3c7f
xorl %ebp, %ebp
addl %ebp, %r14d
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq