// File: /workspace/github_c_makefile_star2_O2/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)
movl %r8d, %eax
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movl %esi, %ebp
movq %rdi, 0x10(%rsp)
movl $0x10, 0x4(%rsp)
leaq 0xc1ec(%rip), %rsi      # 0x17388
pushq $0x10
popq %rcx
leaq 0x48(%rsp), %r13
movq %r13, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, %r14d
imull $0x3e8, %edx, %r15d     # imm = 0x3E8
leaq 0xc124(%rip), %r12      # 0x172e8
leaq 0x28(%rsp), %rbx
movq %r14, 0x28(%rsp)
movq %r15, 0x30(%rsp)
movl (%r12), %edi
incl %edi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x22c0
shll $0x18, %eax
jns 0xb222
callq 0x2070
movl (%rax), %edi
cmpl $0x4, %edi
je 0xb1c9
callq 0x2480
leaq 0x6292(%rip), %rsi      # 0x11497
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0xcb1c
callq 0xa99a
callq 0xa3d2
movb $-0x1, %al
jmp 0xb2cb
je 0xb286
leaq 0xc0e5(%rip), %rcx      # 0x17310
pushq $0x40
popq %rsi
movq %rcx, %r13
movq (%r13), %r13
cmpq %rcx, %r13
je 0xb2c2
movl 0x14(%r13), %edi
movl %edi, %eax
cltd
idivl %esi
cltq
movq 0x48(%rsp,%rax,8), %rax
btq %rdx, %rax
jae 0xb231
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 0xb28a
andl $0x7ffe, %eax           # imm = 0x7FFE
cmpl $0x12, %eax
jae 0xb2b6
xorl %eax, %eax
jmp 0xb2cb
callq 0x2070
movl (%rax), %edi
callq 0x2480
leaq 0x6225(%rip), %rsi      # 0x114c2
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0xcb1c
movq %r13, %rdi
callq 0xa44a
jmp 0xb21b
movq 0x8(%rsp), %rax
movq %r13, (%rax)
movl 0x3c(%rsp), %eax
movq 0x20(%rsp), %rcx
movl %eax, (%rcx)
movb $0x1, %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq