// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x4260
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x4260
movl $0x0, -0x4(%rbp)
jmp 0x44ba
movq -0x10(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x4287
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x449a
movl -0x14(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x449a
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x42aa
movl -0x14(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x42aa
movq -0x10(%rbp), %rdi
callq 0x44d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x4365
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x4550
leaq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x68(%rbp), %rax
jge 0x431c
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x3e8, %rax            # imm = 0x3E8
subq -0x68(%rbp), %rax
imulq $0x3e8, %rax, %rcx      # imm = 0x3E8
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
jmp 0x4337
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
subq -0x68(%rbp), %rax
imulq $0x3e8, %rax, %rcx      # imm = 0x3E8
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x434c
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jge 0x4363
movq -0x40(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x4394
movl -0x14(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x438a
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
leaq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x4392
movq $0x0, -0x40(%rbp)
jmp 0x4394
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x45a0
movl %eax, -0x58(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x58(%rbp), %eax
jge 0x4498
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movslq -0x48(%rbp), %rdx
movslq (%rcx,%rdx,8), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x48(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
movl %eax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x443a
movl $0x1, -0x54(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rdx
movl -0x4c(%rbp), %ecx
callq *%rax
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl -0x4c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x4481
cmpl $0x0, -0x54(%rbp)
je 0x4463
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x447f
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rdx
movl -0x4c(%rbp), %ecx
callq *%rax
jmp 0x4481
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x43ab
jmp 0x449a
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x44b4
movq -0x10(%rbp), %rdi
callq 0x4720
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)