// File: /workspace/github_c_makefile_star2_O0/open-mesh-mirror[P]batmand/hna.c
// Function: hna_global_add
static void _hna_global_add(struct orig_node *orig_node, struct hna_element *hna_element)
{
	struct hna_global_entry *hna_global_entry;
	struct hna_orig_ptr *hna_orig_ptr = NULL;
	struct orig_node *old_orig_node = NULL;
	struct hashtable_t *swaphash;
	int found = 0;

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

	/* add the hna node if it does not exist */
	if (!hna_global_entry) {
		hna_global_entry = debugMalloc(sizeof(struct hna_global_entry), 703);

		if (!hna_global_entry)
			return;

		hna_global_entry->addr = hna_element->addr;
		hna_global_entry->netmask = hna_element->netmask;
		hna_global_entry->curr_orig_node = NULL;
		INIT_LIST_HEAD_FIRST(hna_global_entry->orig_list);

		hash_add(hna_global_hash, hna_global_entry);

		if (hna_global_hash->elements * 4 > hna_global_hash->size) {
			swaphash = hash_resize(hna_global_hash, hna_global_hash->size * 2);

			if (swaphash == NULL)
				debug_output(0, "Couldn't resize global hna hash table \n");
			else
				hna_global_hash = swaphash;
		}
	}

	/* the given orig_node already is the current orig node for this HNA */
	if (hna_global_entry->curr_orig_node == orig_node)
		return;

	list_for_each_entry(hna_orig_ptr, &hna_global_entry->orig_list, list) {
		if (hna_orig_ptr->orig_node == orig_node) {
			found = 1;
			break;
		}
	}

	/* append the given orig node to the list */
	if (!found) {
		hna_orig_ptr = debugMalloc(sizeof(struct hna_orig_ptr), 704);

		if (!hna_orig_ptr)
			return;

		hna_orig_ptr->orig_node = orig_node;
		INIT_LIST_HEAD(&hna_orig_ptr->list);

		list_add_tail(&hna_orig_ptr->list, &hna_global_entry->orig_list);
	}

	/* our TQ value towards the HNA is better */
	if ((!hna_global_entry->curr_orig_node) ||
		(orig_node->router->tq_avg > hna_global_entry->curr_orig_node->router->tq_avg)) {

		old_orig_node = hna_global_entry->curr_orig_node;
		hna_global_entry->curr_orig_node = orig_node;

		/**
		 * 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 ((old_orig_node) &&
			(hna_global_entry->curr_orig_node->router->addr == old_orig_node->router->addr))
			return;

		add_del_route(hna_element->addr, hna_element->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);
	}

	/* delete previous route */
	if (old_orig_node) {
		add_del_route(hna_element->addr, hna_element->netmask, old_orig_node->router->addr,
					old_orig_node->router->if_incoming->addr.sin_addr.s_addr,
					old_orig_node->router->if_incoming->if_index,
					old_orig_node->router->if_incoming->dev,
					BATMAN_RT_TABLE_NETWORKS, ROUTE_TYPE_UNICAST, ROUTE_DEL);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movq 0x120da(%rip), %rdi     # 0x1b718
movq -0x10(%rbp), %rsi
callq 0x83f0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x9728
movl $0x20, %edi
movl $0x2bf, %esi            # imm = 0x2BF
callq 0x7220
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x9675
jmp 0x9911
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movb 0x4(%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x18(%rbp), %rcx
addq $0x10, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rcx
addq $0x10, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq 0x12056(%rip), %rdi     # 0x1b718
movq -0x18(%rbp), %rsi
callq 0x8290
movq 0x12046(%rip), %rax     # 0x1b718
movl 0x8(%rax), %eax
shll $0x2, %eax
movq 0x12039(%rip), %rcx     # 0x1b718
cmpl 0xc(%rcx), %eax
jle 0x9726
movq 0x1202d(%rip), %rdi     # 0x1b718
movq 0x12026(%rip), %rax     # 0x1b718
movl 0xc(%rax), %esi
shll %esi
callq 0x8620
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x9719
xorl %edi, %edi
leaq 0xc6df(%rip), %rsi      # 0x15def
movb $0x0, %al
callq 0x123f0
jmp 0x9724
movq -0x30(%rbp), %rax
movq %rax, 0x11ff4(%rip)     # 0x1b718
jmp 0x9726
jmp 0x9728
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x973b
jmp 0x9911
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
addq $0x10, %rcx
cmpq %rcx, %rax
je 0x977e
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x976f
movl $0x1, -0x34(%rbp)
jmp 0x977e
jmp 0x9771
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x9747
cmpl $0x0, -0x34(%rbp)
jne 0x97cb
movl $0x10, %edi
movl $0x2c0, %esi            # imm = 0x2C0
callq 0x7220
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x97a3
jmp 0x9911
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
callq 0x6e60
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x97fa
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x19(%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
movzbl 0x19(%rcx), %ecx
cmpl %ecx, %eax
jle 0x98a2
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x983a
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %eax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jne 0x983a
jmp 0x9911
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
cmpq $0x0, -0x28(%rbp)
je 0x9911
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movb 0x4(%rax), %al
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl 0x8(%rcx), %edx
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x30(%rcx), %rcx
movl 0x34(%rcx), %ecx
movq -0x28(%rbp), %rsi
movq 0x8(%rsi), %rsi
movq 0x30(%rsi), %rsi
movl 0x20(%rsi), %r8d
movq -0x28(%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 $0x1, 0x10(%rsp)
callq 0xa420
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)