// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x38(%rdi), %r14
testq %r14, %r14
je 0x7be6
movq %rdi, %rbx
movswq 0x40(%rdi), %rax
testq %rax, %rax
je 0x7be6
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
movq %rdx, %r15
shrq $0x2, %r15
testl %r15d, %r15d
jle 0x7be6
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movl $0x41, %ebp
movb 0x4(%r14), %al
addb $-0x21, %al
cmpb $-0x20, %al
jb 0x7bd9
movq 0xfb37(%rip), %rdi      # 0x17678
movq %r14, %rsi
callq 0x69d3
testq %rax, %rax
je 0x7bd9
movq %rax, %r12
movq 0x8(%rax), %rax
cmpq %rbx, %rax
je 0x7bd9
movq 0x8(%rax), %rcx
movb 0x19(%rcx), %dl
movq 0x8(%rbx), %rax
cmpb 0x19(%rax), %dl
ja 0x7bd9
movl 0x8(%rax), %edx
cmpl %edx, 0x8(%rcx)
je 0x7bd4
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 %r13
pushq %r13
pushq %rbp
callq 0x7cd4
addq $0x20, %rsp
movl (%r14), %edi
movzbl 0x4(%r14), %esi
movq 0x8(%r12), %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 %r13
pushq %rbp
callq 0x7cd4
addq $0x20, %rsp
movq %rbx, 0x8(%r12)
addq $0x5, %r14
decq %r15
jne 0x7b2c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq