// File: /workspace/github_c_makefile_star2_O2/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 0x8a18
movq %rax, %r12
movq %rdx, %r13
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
testq %rdx, %rdx
jne 0x705a
testq %rcx, %rcx
je 0x704d
xorl %edx, %edx
jmp 0x705a
movq %r12, (%rbx)
movq %r13, 0x8(%rbx)
movq %r13, %rcx
movq %r12, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x8a7d
cmpl %r15d, %eax
jg 0x70b4
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
movq %r12, %rdi
movq %r13, %rsi
callq 0x8a7d
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)
pushq $0x2
popq %rsi
callq 0x22a0
cmpl $-0x1, %eax
je 0x70c1
testl %eax, %eax
jne 0x70ee
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
jmp 0x7149
callq 0x2060
movl (%rax), %r8d
leaq 0x352b(%rip), %rdi      # 0xa5fb
cmpl $0x4, %r8d
jne 0x7110
leaq 0x3527(%rip), %rcx      # 0xa604
pushq $0x60
popq %rsi
pushq $0x3
popq %rdx
xorl %eax, %eax
callq 0x4998
pushq $-0x2
jmp 0x7148
movswl 0x6(%rsp), %r8d
testb $0x38, %r8b
je 0x711f
leaq 0x34fa(%rip), %rdi      # 0xa5fb
leaq 0x3527(%rip), %rcx      # 0xa62f
pushq $0x69
popq %rsi
pushq $0x3
popq %rdx
jmp 0x713f
leaq 0x3500(%rip), %rcx      # 0xa617
pushq $0x63
popq %rsi
pushq $0x3
popq %rdx
jmp 0x713f
movswl 0xe(%rsp), %eax
testb $0x38, %al
je 0x7158
leaq 0x34cc(%rip), %rdi      # 0xa5fb
leaq 0x351a(%rip), %rcx      # 0xa650
pushq $0x6e
popq %rsi
pushq $0x3
popq %rdx
movl %eax, %r8d
xorl %eax, %eax
callq 0x4998
pushq $-0x1
popq %rax
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 0x7149