// File: /workspace/github_c_makefile_star2_O3/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 0x8ea2
movq %rax, %r12
movq %rdx, %r13
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
testq %rdx, %rdx
jne 0x72ee
testq %rcx, %rcx
je 0x72e1
xorl %edx, %edx
jmp 0x72ee
movq %r12, (%rbx)
movq %r13, 0x8(%rbx)
movq %r13, %rcx
movq %r12, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x8f11
cmpl %r15d, %eax
jg 0x734a
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
movq %r12, %rdi
movq %r13, %rsi
callq 0x8f11
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 0x22a0
cmpl $-0x1, %eax
je 0x7357
testl %eax, %eax
jne 0x738b
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %eax, %eax
jmp 0x73f4
callq 0x2060
movl (%rax), %r8d
leaq 0x4295(%rip), %rdi      # 0xb5fb
cmpl $0x4, %r8d
jne 0x73b1
leaq 0x4291(%rip), %rcx      # 0xb604
movl $0x60, %esi
movl $0x3, %edx
xorl %eax, %eax
callq 0x4ad6
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x73f4
movswl 0x6(%rsp), %r8d
testb $0x38, %r8b
je 0x73c4
leaq 0x425d(%rip), %rdi      # 0xb5fb
leaq 0x428a(%rip), %rcx      # 0xb62f
movl $0x69, %esi
movl $0x3, %edx
jmp 0x73e8
leaq 0x425f(%rip), %rcx      # 0xb617
movl $0x63, %esi
movl $0x3, %edx
jmp 0x73e8
movswl 0xe(%rsp), %eax
testb $0x38, %al
je 0x7403
leaq 0x4227(%rip), %rdi      # 0xb5fb
leaq 0x4275(%rip), %rcx      # 0xb650
movl $0x6e, %esi
movl $0x3, %edx
movl %eax, %r8d
xorl %eax, %eax
callq 0x4ad6
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 0x73f4