// File: /workspace/github_c_makefile_star2_O1/jfriesse[P]omping/rsfunc.c
// Function: rs_poll_timeout
int
rs_poll_timeout(int unicast_socket, int multicast_socket, int timeout, struct timeval *old_tstamp)
{
	struct pollfd pfds[2];
	struct timeval cur_time;
	int poll_timeout;
	int poll_res;
	int res;

	cur_time = util_get_time();

	if (old_tstamp->tv_sec == 0 && old_tstamp->tv_usec == 0) {
		*old_tstamp = cur_time;
	}

	if ((int)util_time_absdiff(cur_time, *old_tstamp) > timeout) {
		memset(old_tstamp, 0, sizeof(*old_tstamp));

		return (0);
	}

	poll_timeout = timeout - util_time_absdiff(cur_time, *old_tstamp);
	if (poll_timeout < 0) {
		poll_timeout = 0;
	}

	memset(pfds, 0, sizeof(struct pollfd) * 2);

	pfds[0].fd = unicast_socket;
	pfds[0].events = POLLIN;

	pfds[1].fd = multicast_socket;
	pfds[1].events = POLLIN;

	poll_res = poll(pfds, 2, poll_timeout);

	if (poll_res == 0) {
		memset(old_tstamp, 0, sizeof(*old_tstamp));

		return (0);
	}

	if (poll_res == -1) {
		if (errno == EINTR) {
			DEBUG2_PRINTF("poll error - EINTR");
			return (-2);
		} else {
			DEBUG2_PRINTF("poll error - errno = %d", errno);
			return (-1);
		}
	}

	if (pfds[0].revents & POLLERR || pfds[0].revents & POLLHUP || pfds[0].revents & POLLNVAL) {
		DEBUG2_PRINTF("poll error. pfds[0] revents = %d", pfds[0].revents);
		return (-1);
	}

	if (pfds[1].revents & POLLERR || pfds[1].revents & POLLHUP || pfds[1].revents & POLLNVAL) {
		DEBUG2_PRINTF("poll error. pfds[1] revents = %d", pfds[1].revents);
		return (-1);
	}

	res = 0;
	if (pfds[0].revents & POLLIN) {
		res |= 1;
	}

	if (pfds[1].revents & POLLIN) {
		res |= 2;
	}

	return (res);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movl %edx, %r15d
movl %esi, %ebp
movl %edi, %r14d
callq 0x8ff2
movq %rax, %r12
movq %rdx, %r13
cmpq $0x0, (%rbx)
jne 0x73fc
cmpq $0x0, 0x8(%rbx)
jne 0x73fc
movq %r12, (%rbx)
movq %r13, 0x8(%rbx)
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
movq %r12, %rdi
movq %r13, %rsi
callq 0x9061
cmpl %r15d, %eax
jg 0x745f
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
movq %r12, %rdi
movq %r13, %rsi
callq 0x9061
subl %eax, %r15d
xorl %edx, %edx
testl %r15d, %r15d
cmovgl %r15d, %edx
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movl %r14d, (%rdi)
movw $0x1, %ax
movw %ax, 0x4(%rdi)
movl %ebp, 0x8(%rdi)
movw %ax, 0xc(%rdi)
movl $0x2, %esi
callq 0x2290
cmpl $-0x1, %eax
je 0x746c
testl %eax, %eax
jne 0x74a0
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
jmp 0x7509
callq 0x2060
movl (%rax), %r8d
leaq 0x41c1(%rip), %rdi      # 0xb63c
cmpl $0x4, %r8d
jne 0x74c6
leaq 0x41bd(%rip), %rcx      # 0xb645
movl $0x60, %esi
movl $0x3, %edx
xorl %eax, %eax
callq 0x4ada
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x7509
movswl 0x6(%rsp), %r8d
testb $0x38, %r8b
je 0x74d9
leaq 0x4189(%rip), %rdi      # 0xb63c
leaq 0x41b6(%rip), %rcx      # 0xb670
movl $0x69, %esi
movl $0x3, %edx
jmp 0x74fd
leaq 0x418b(%rip), %rcx      # 0xb658
movl $0x63, %esi
movl $0x3, %edx
jmp 0x74fd
movswl 0xe(%rsp), %eax
testb $0x38, %al
je 0x7518
leaq 0x4153(%rip), %rdi      # 0xb63c
leaq 0x41a1(%rip), %rcx      # 0xb691
movl $0x6e, %esi
movl $0x3, %edx
movl %eax, %r8d
xorl %eax, %eax
callq 0x4ada
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andl $0x1, %r8d
andl $0x1, %eax
leal (%r8,%rax,2), %eax
jmp 0x7509