// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
callq 0xcb30
movq %rax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x9e4a
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x9e4a
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq (%rax), %rdx
movq 0x8(%rax), %rcx
callq 0xcbe0
cmpl -0x10(%rbp), %eax
jle 0x9e83
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2150
movl $0x0, -0x4(%rbp)
jmp 0xa065
movslq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq (%rax), %rdx
movq 0x8(%rax), %rcx
callq 0xcbe0
movq %rax, %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x9ebd
movl $0x0, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2150
movl -0x8(%rbp), %eax
movl %eax, -0x30(%rbp)
movw $0x1, -0x2c(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x28(%rbp)
movw $0x1, -0x24(%rbp)
leaq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl $0x2, %esi
callq 0x22a0
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jne 0x9f1b
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2150
movl $0x0, -0x4(%rbp)
jmp 0xa065
cmpl $-0x1, -0x48(%rbp)
jne 0x9f89
callq 0x2050
cmpl $0x4, (%rax)
jne 0x9f56
leaq 0x573a(%rip), %rdi      # 0xf66c
movl $0x60, %esi
movl $0x3, %edx
leaq 0x5732(%rip), %rcx      # 0xf675
movb $0x0, %al
callq 0x5dc0
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0xa065
callq 0x2050
movl (%rax), %r8d
leaq 0x5707(%rip), %rdi      # 0xf66c
movl $0x63, %esi
movl $0x3, %edx
leaq 0x5712(%rip), %rcx      # 0xf688
movb $0x0, %al
callq 0x5dc0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa065
movswl -0x2a(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x9fad
movswl -0x2a(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x9fad
movswl -0x2a(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x9fdd
movswl -0x2a(%rbp), %r8d
leaq 0x56b3(%rip), %rdi      # 0xf66c
movl $0x69, %esi
movl $0x3, %edx
leaq 0x56d6(%rip), %rcx      # 0xf6a0
movb $0x0, %al
callq 0x5dc0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa065
movswl -0x22(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0xa001
movswl -0x22(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0xa001
movswl -0x22(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xa02e
movswl -0x22(%rbp), %r8d
leaq 0x565f(%rip), %rdi      # 0xf66c
movl $0x6e, %esi
movl $0x3, %edx
leaq 0x56a3(%rip), %rcx      # 0xf6c1
movb $0x0, %al
callq 0x5dc0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa065
movl $0x0, -0x4c(%rbp)
movswl -0x2a(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa04a
movl -0x4c(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x4c(%rbp)
movswl -0x22(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa05f
movl -0x4c(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop