// File: /workspace/github_c_makefile_star2_O1/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 0xb97a(%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 0xb8a5(%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 0xbaa1
callq 0x2070
movl (%rax), %edi
cmpl $0x4, %edi
je 0xba48
callq 0x2480
leaq 0x698f(%rip), %rsi      # 0x12413
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd5b0
callq 0xb0ac
callq 0xaa6b
movb $-0x1, %al
jmp 0xbb4e
je 0xbb09
leaq 0xb866(%rip), %rax      # 0x17310
movq %rax, %r13
movq (%r13), %r13
cmpq %rax, %r13
je 0xbb41
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 0xbaad
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 0xbb0d
andl $0x7ffe, %eax           # imm = 0x7FFE
cmpl $0x12, %eax
jae 0xbb39
xorl %eax, %eax
jmp 0xbb4e
callq 0x2070
movl (%rax), %edi
callq 0x2480
leaq 0x691e(%rip), %rsi      # 0x1243e
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd5b0
movq %r13, %rdi
callq 0xaafa
jmp 0xba9a
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