// File: /workspace/github_c_makefile_star2_O3/open-mesh-mirror[P]batmand/posix/posix.c
// Function: receive_packet
int8_t receive_packet(unsigned char *packet_buff, int32_t packet_buff_len, int16_t *packet_len, uint32_t *neigh, uint32_t timeout, struct batman_if **if_incoming)
{
	struct sockaddr_in addr;
	struct timeval tv;
	struct list_head *if_pos;
	struct batman_if *batman_if;
	uint32_t addr_len;
	int8_t res;
	fd_set tmp_wait_set;


	addr_len = sizeof(struct sockaddr_in);
	memcpy( &tmp_wait_set, &receive_wait_set, sizeof(fd_set) );

	while (1) {

		tv.tv_sec = timeout / 1000;
		tv.tv_usec = (timeout % 1000) * 1000;

		res = select(receive_max_sock + 1, &tmp_wait_set, NULL, NULL, &tv);

		if (res >= 0)
			break;

		if (errno != EINTR) {

			debug_output(0, "Error - can't select (receive_packet): %s\n", strerror(errno));

			/* we might have a deactivated interface - check all active interfaces for problems */
			check_active_interfaces();
			/* on error the wait_sets are reset - we have to re-create them */
			interface_listen_sockets();
			return -1;

		}

	}

	if ( res == 0 )
		return 0;

	list_for_each(if_pos, &if_list) {

		batman_if = list_entry(if_pos, struct batman_if, list);

		if (FD_ISSET(batman_if->udp_recv_sock, &tmp_wait_set)) {

			if ((*packet_len = recvfrom(batman_if->udp_recv_sock, packet_buff, packet_buff_len - 1, 0, (struct sockaddr *)&addr, &addr_len)) < 0) {

				debug_output(0, "Error - can't receive packet: %s\n", strerror(errno));
				deactivate_interface(batman_if);
				return -1;

			}

			if (((unsigned int)*packet_len) < sizeof(struct bat_packet))
				return 0;

			(*if_incoming) = batman_if;
			break;

		}

	}

	*neigh = addr.sin_addr.s_addr;

	return 1;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, 0x8(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movl %esi, %ebp
movq %rdi, 0x10(%rsp)
movl $0x10, 0x4(%rsp)
leaq 0xb686(%rip), %rsi      # 0x17388
leaq 0x48(%rsp), %r13
movl $0x10, %ecx
movq %r13, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %r8d, %eax
imulq $0x10624dd3, %rax, %rbx # imm = 0x10624DD3
shrq $0x26, %rbx
imull $0x3e8, %ebx, %eax      # imm = 0x3E8
subl %eax, %r8d
imull $0x3e8, %r8d, %r15d     # imm = 0x3E8
leaq 0xb5b1(%rip), %r12      # 0x172e8
leaq 0x28(%rsp), %r14
movq %rbx, 0x28(%rsp)
movq %r15, 0x30(%rsp)
movl (%r12), %edi
incl %edi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x22c0
shll $0x18, %eax
jns 0xbd95
callq 0x2070
movl (%rax), %edi
cmpl $0x4, %edi
je 0xbd3c
callq 0x2480
leaq 0x673f(%rip), %rsi      # 0x124b7
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd88c
callq 0xb39d
callq 0xad6d
movb $-0x1, %al
jmp 0xbe42
je 0xbdfd
leaq 0xb572(%rip), %rax      # 0x17310
movq %rax, %r13
movq (%r13), %r13
cmpq %rax, %r13
je 0xbe39
movl 0x14(%r13), %edi
leal 0x3f(%rdi), %ecx
testl %edi, %edi
cmovnsl %edi, %ecx
sarl $0x6, %ecx
movslq %ecx, %rcx
movq 0x48(%rsp,%rcx,8), %rcx
btq %rdi, %rcx
jae 0xbda1
decl %ebp
movslq %ebp, %rdx
leaq 0x38(%rsp), %r8
leaq 0x4(%rsp), %r9
movq 0x10(%rsp), %rsi
xorl %ecx, %ecx
callq 0x2320
movq 0x18(%rsp), %rcx
movw %ax, (%rcx)
testw %ax, %ax
js 0xbe01
andl $0x7ffe, %eax           # imm = 0x7FFE
cmpl $0x12, %eax
jae 0xbe2d
xorl %eax, %eax
jmp 0xbe42
callq 0x2070
movl (%rax), %edi
callq 0x2480
leaq 0x66ce(%rip), %rsi      # 0x124e2
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd88c
movq %r13, %rdi
callq 0xadf9
jmp 0xbd8e
movq 0x8(%rsp), %rax
movq %r13, (%rax)
movl 0x3c(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
movb $0x1, %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq