// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x38(%rdi), %r14
testq %r14, %r14
je 0x736b
movq %rdi, %rbx
movswq 0x40(%rdi), %rax
testq %rax, %rax
je 0x736b
xorl %r12d, %r12d
pushq $0x5
popq %rcx
xorl %edx, %edx
divq %rcx
testl %eax, %eax
cmovgl %eax, %r12d
pushq $0x41
popq %r13
subq $0x1, %r12
jb 0x736b
movb 0x4(%r14), %al
addb $-0x21, %al
cmpb $-0x20, %al
jb 0x7362
movq 0x103ae(%rip), %rdi     # 0x17678
movq %r14, %rsi
callq 0x61eb
testq %rax, %rax
je 0x7362
movq %rax, %r15
movq 0x8(%rax), %rax
cmpq %rbx, %rax
je 0x7362
movq 0x8(%rax), %rcx
movb 0x19(%rcx), %dl
movq 0x8(%rbx), %rax
cmpb 0x19(%rax), %dl
ja 0x7362
movl 0x8(%rax), %edx
cmpl %edx, 0x8(%rcx)
je 0x735e
movl (%r14), %edi
movzbl 0x4(%r14), %esi
movq 0x30(%rax), %rax
movl 0x34(%rax), %ecx
movl 0x20(%rax), %r8d
movq 0x8(%rax), %r9
subq $0x8, %rsp
pushq $0x0
pushq $0x0
pushq %r13
callq 0x745c
addq $0x20, %rsp
movl (%r14), %edi
movzbl 0x4(%r14), %esi
movq 0x8(%r15), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %edx
movq 0x30(%rax), %rax
movl 0x34(%rax), %ecx
movl 0x20(%rax), %r8d
movq 0x8(%rax), %r9
subq $0x8, %rsp
pushq $0x1
pushq $0x0
pushq %r13
callq 0x745c
addq $0x20, %rsp
movq %rbx, 0x8(%r15)
addq $0x5, %r14
jmp 0x72ab
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq