// File: /workspace/github_c_makefile_star2_O0/open-mesh-mirror[P]batmand/hna.c
// Function: hna_global_check_tq
void hna_global_check_tq(struct orig_node *orig_node)
{
	struct hna_element *e, *buff;
	struct hna_global_entry *hna_global_entry;
	int i, num_elements;

	if ((orig_node->hna_buff == NULL) || (orig_node->hna_buff_len == 0))
		return;

	num_elements = orig_node->hna_buff_len / sizeof(struct hna_element);
	buff = (struct hna_element *)orig_node->hna_buff;

	for (i = 0; i < num_elements; i++) {
		e = &buff[i];

		if ((e->netmask < 1) || (e->netmask > 32))
			continue;

		hna_global_entry = ((struct hna_global_entry *)hash_find(hna_global_hash, e));

		if (!hna_global_entry)
			continue;

		/* if the given orig node is not in use no routes need to change */
		if (hna_global_entry->curr_orig_node == orig_node)
			continue;

		/* the TQ value has to better than the currently selected orig node */
		if (hna_global_entry->curr_orig_node->router->tq_avg > orig_node->router->tq_avg)
			continue;

		/**
		 * if we change the orig node towards the HNA we may still route via the same next hop
		 * which does not require any routing table changes
		 */
		if (hna_global_entry->curr_orig_node->router->addr == orig_node->router->addr)
			goto set_orig_node;

		add_del_route(e->addr, e->netmask, orig_node->router->addr,
				orig_node->router->if_incoming->addr.sin_addr.s_addr,
				orig_node->router->if_incoming->if_index,
				orig_node->router->if_incoming->dev,
				BATMAN_RT_TABLE_NETWORKS, ROUTE_TYPE_UNICAST, ROUTE_ADD);

		add_del_route(e->addr, e->netmask, hna_global_entry->curr_orig_node->router->addr,
			hna_global_entry->curr_orig_node->router->if_incoming->addr.sin_addr.s_addr,
			hna_global_entry->curr_orig_node->router->if_incoming->if_index,
			hna_global_entry->curr_orig_node->router->if_incoming->dev,
			BATMAN_RT_TABLE_NETWORKS, ROUTE_TYPE_UNICAST, ROUTE_DEL);

set_orig_node:
		hna_global_entry->curr_orig_node = orig_node;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0xa0d4
movq -0x8(%rbp), %rax
movswl 0x40(%rax), %eax
cmpl $0x0, %eax
jne 0xa0d9
jmp 0xa2b3
movq -0x8(%rbp), %rax
movswq 0x40(%rax), %rax
movl $0x5, %ecx
xorl %edx, %edx
divq %rcx
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0xa2b3
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x5, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x1, %eax
jl 0xa13b
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x20, %eax
jle 0xa140
jmp 0xa2a5
movq 0x115d1(%rip), %rdi     # 0x1b718
movq -0x10(%rbp), %rsi
callq 0x83f0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xa160
jmp 0xa2a5
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0xa173
jmp 0xa2a5
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movzbl 0x19(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movzbl 0x19(%rcx), %ecx
cmpl %ecx, %eax
jle 0xa198
jmp 0xa2a5
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jne 0xa1b9
jmp 0xa299
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movb 0x4(%rax), %al
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl 0x8(%rcx), %edx
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x30(%rcx), %rcx
movl 0x34(%rcx), %ecx
movq -0x8(%rbp), %rsi
movq 0x8(%rsi), %rsi
movq 0x30(%rsi), %rsi
movl 0x20(%rsi), %r8d
movq -0x8(%rbp), %rsi
movq 0x8(%rsi), %rsi
movq 0x30(%rsi), %rsi
movq 0x8(%rsi), %r9
xorl %esi, %esi
movzbl %al, %esi
movl $0x41, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0xa420
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movb 0x4(%rax), %al
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
movl 0x8(%rcx), %edx
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
movq 0x30(%rcx), %rcx
movl 0x34(%rcx), %ecx
movq -0x20(%rbp), %rsi
movq 0x8(%rsi), %rsi
movq 0x8(%rsi), %rsi
movq 0x30(%rsi), %rsi
movl 0x20(%rsi), %r8d
movq -0x20(%rbp), %rsi
movq 0x8(%rsi), %rsi
movq 0x8(%rsi), %rsi
movq 0x30(%rsi), %rsi
movq 0x8(%rsi), %r9
xorl %esi, %esi
movzbl %al, %esi
movl $0x41, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xa420
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa102
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)