// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movl $0x10, -0x6c(%rbp)
leaq -0xf0(%rbp), %rdi
leaq 0xb7a1(%rip), %rsi      # 0x1b428
movl $0x80, %edx
callq 0x22c0
movl -0x2c(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, %eax
movq %rax, -0x58(%rbp)
movl -0x2c(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
imull $0x3e8, %edx, %eax      # imm = 0x3E8
movl %eax, %eax
movq %rax, -0x50(%rbp)
leaq 0xb6c6(%rip), %rax      # 0x1b388
movl (%rax), %edi
addl $0x1, %edi
leaq -0xf0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x58(%rbp), %r8
movq %rcx, %rdx
callq 0x22f0
movb %al, -0x6d(%rbp)
movsbl -0x6d(%rbp), %eax
cmpl $0x0, %eax
jl 0xfcec
jmp 0xfd2d
callq 0x2070
cmpl $0x4, (%rax)
je 0xfd28
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq %rax, %rdx
xorl %edi, %edi
leaq 0x7791(%rip), %rsi      # 0x1749f
movb $0x0, %al
callq 0x123f0
callq 0xf1e0
callq 0xe830
movb $-0x1, -0x1(%rbp)
jmp 0xfe63
jmp 0xfc91
movsbl -0x6d(%rbp), %eax
cmpl $0x0, %eax
jne 0xfd3f
movb $0x0, -0x1(%rbp)
jmp 0xfe63
leaq 0xb66a(%rip), %rax      # 0x1b3b0
movq (%rax), %rax
movq %rax, -0x60(%rbp)
leaq 0xb65c(%rip), %rax      # 0x1b3b0
cmpq %rax, -0x60(%rbp)
je 0xfe56
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl 0x14(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0xf0(%rbp,%rax,8), %rax
movq %rax, -0x100(%rbp)
movq -0x68(%rbp), %rax
movl 0x14(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x100(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0xfe44
movq -0x68(%rbp), %rax
movl 0x14(%rax), %edi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
leaq -0x48(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %r8
xorl %ecx, %ecx
leaq -0x6c(%rbp), %r9
callq 0x2350
movq -0x20(%rbp), %rcx
movw %ax, (%rcx)
cwtl
cmpl $0x0, %eax
jge 0xfe22
callq 0x2070
movl (%rax), %edi
callq 0x24a0
movq %rax, %rdx
xorl %edi, %edi
leaq 0x76be(%rip), %rsi      # 0x174ca
movb $0x0, %al
callq 0x123f0
movq -0x68(%rbp), %rdi
callq 0xe930
movb $-0x1, -0x1(%rbp)
jmp 0xfe63
movq -0x20(%rbp), %rax
movswl (%rax), %eax
movl %eax, %eax
cmpq $0x12, %rax
jae 0xfe37
movb $0x0, -0x1(%rbp)
jmp 0xfe63
movq -0x68(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0xfe56
jmp 0xfe46
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0xfd4d
movl -0x44(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nop