// File: /workspace/github_c_makefile_star2_O0/DeforaOS[P]libSystem/src/event.c
// Function: loop_timeout
static int _loop_timeout(Event * event)
{
	struct timeval now;
	unsigned int i = 0;
	EventTimeout * et;

	if(gettimeofday(&now, NULL) != 0)
		return error_set_code(-errno, "%s", strerror(errno));
	event->timeout.tv_sec = (time_t)LONG_MAX;
	event->timeout.tv_usec = (suseconds_t)LONG_MAX;
	while(i < array_count(event->timeouts))
	{
		array_get_copy(event->timeouts, i, &et);
		if(now.tv_sec > et->timeout.tv_sec
				|| (now.tv_sec == et->timeout.tv_sec
					&& now.tv_usec >= et->timeout.tv_usec))
		{
			if(et->func(et->data) != 0)
			{
				array_remove_pos(event->timeouts, i);
				object_delete(et);
				continue;
			}
			et->timeout.tv_sec = et->initial.tv_sec + now.tv_sec;
			et->timeout.tv_usec = et->initial.tv_usec + now.tv_usec;
			if(et->initial.tv_sec < event->timeout.tv_sec
					|| (et->initial.tv_sec
						== event->timeout.tv_sec
						&& et->initial.tv_usec
						< event->timeout.tv_usec))
			{
				event->timeout.tv_sec = et->initial.tv_sec;
				event->timeout.tv_usec = et->initial.tv_usec;
			}
		}
		else
		{
			if(et->timeout.tv_sec - now.tv_sec < event->timeout.tv_sec
					|| (et->timeout.tv_sec - now.tv_sec == event->timeout.tv_sec
						&& et->timeout.tv_usec - now.tv_usec < event->timeout.tv_usec))
			{
				event->timeout.tv_sec = et->timeout.tv_sec
					- now.tv_sec;
				/* XXX may be needed elsewhere too */
				if(et->timeout.tv_usec >= now.tv_usec)
					event->timeout.tv_usec
						= et->timeout.tv_usec
						- now.tv_usec;
				else
				{
					event->timeout.tv_sec--;
					event->timeout.tv_usec
						= now.tv_usec
						- et->timeout.tv_usec;
				}
			}
		}
		i++;
	}
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() %s%lld%s%ld => 0\n", __func__, "tv_sec=",
			(long long)event->timeout.tv_sec, ", tv_usec=",
			(long)event->timeout.tv_usec);
#endif
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x42c0
cmpl $0x0, %eax
je 0x839c
callq 0x40d0
movq %rax, %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x34(%rbp)
callq 0x40d0
movl (%rax), %edi
callq 0x4840
movl -0x34(%rbp), %edi
movq %rax, %rdx
leaq 0x7cd1(%rip), %rsi      # 0x1005e
movb $0x0, %al
callq 0x4630
movl %eax, -0x4(%rbp)
jmp 0x85d3
movq -0x10(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, 0x120(%rax)
movq -0x10(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, 0x128(%rax)
movl -0x24(%rbp), %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
callq 0x4250
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jae 0x85cc
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdx
callq 0x48a0
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jg 0x8438
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x8500
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x8500
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rdi
callq *%rax
cmpl $0x0, %eax
je 0x8472
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0x4590
movq -0x30(%rbp), %rdi
callq 0x44a0
jmp 0x83c6
movq -0x30(%rbp), %rax
movq (%rax), %rcx
addq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
addq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x120(%rcx), %rax
jl 0x84d6
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x120(%rcx), %rax
jne 0x84fb
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x128(%rcx), %rax
jge 0x84fb
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x120(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x128(%rax)
jmp 0x85be
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
subq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x120(%rcx), %rax
jl 0x854f
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
subq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x120(%rcx), %rax
jne 0x85bc
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
subq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x128(%rcx), %rax
jge 0x85bc
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
subq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x120(%rax)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x18(%rbp), %rax
jl 0x858d
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
subq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x128(%rax)
jmp 0x85ba
movq -0x10(%rbp), %rax
movq 0x120(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x120(%rax)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
subq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x128(%rax)
jmp 0x85bc
jmp 0x85be
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x83c6
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)