// File: /workspace/github_c_makefile_star2_O0/open-mesh-mirror[P]batmand/batman.c
// Function: update_routes
void update_routes(struct orig_node *orig_node, struct neigh_node *neigh_node, unsigned char *hna_recv_buff, int16_t hna_buff_len)
{
	char orig_str[ADDR_STR_LEN], next_str[ADDR_STR_LEN];
	struct neigh_node *old_router;

	prof_start(PROF_update_routes);
	debug_output(4, "update_routes() \n");

	/* also handles orig_node->router == NULL and neigh_node == NULL */
	if ((orig_node != NULL) && (orig_node->router != neigh_node)) {
		old_router = orig_node->router;

		if ( ( orig_node != NULL ) && ( neigh_node != NULL ) ) {
			addr_to_string( orig_node->orig, orig_str, ADDR_STR_LEN );
			addr_to_string( neigh_node->addr, next_str, ADDR_STR_LEN );
			debug_output( 4, "Route to %s via %s\n", orig_str, next_str );
		}

		/* adds duplicated code but makes it more readable */

		/* new route added */
		if ((orig_node->router == NULL) && (neigh_node != NULL)) {

			debug_output(4, "Adding new route\n");

			add_del_route(orig_node->orig, 32, neigh_node->addr, neigh_node->if_incoming->addr.sin_addr.s_addr,
					neigh_node->if_incoming->if_index, neigh_node->if_incoming->dev, BATMAN_RT_TABLE_HOSTS, ROUTE_TYPE_UNICAST, ROUTE_ADD);

			orig_node->batman_if = neigh_node->if_incoming;
			orig_node->router = neigh_node;

			/* add new announced network(s) */
			hna_global_add(orig_node, hna_recv_buff, hna_buff_len);

		/* route deleted */
		} else if ((orig_node->router != NULL) && (neigh_node == NULL)) {

			debug_output(4, "Deleting previous route\n");

			/* remove old announced network(s) */
			hna_global_del(orig_node);

			add_del_route(orig_node->orig, 32, orig_node->router->addr, 0, orig_node->batman_if->if_index,
					orig_node->batman_if->dev, BATMAN_RT_TABLE_HOSTS, ROUTE_TYPE_UNICAST, ROUTE_DEL);

		/* route changed */
		} else {

			debug_output(4, "Route changed\n");

			/* add new route */
			add_del_route(orig_node->orig, 32, neigh_node->addr, neigh_node->if_incoming->addr.sin_addr.s_addr,
					neigh_node->if_incoming->if_index, neigh_node->if_incoming->dev, BATMAN_RT_TABLE_HOSTS, ROUTE_TYPE_UNICAST, ROUTE_ADD);

			/* delete old route */
			add_del_route(orig_node->orig, 32, orig_node->router->addr, 0, orig_node->batman_if->if_index,
					orig_node->batman_if->dev, BATMAN_RT_TABLE_HOSTS, ROUTE_TYPE_UNICAST, ROUTE_DEL);


			orig_node->batman_if = neigh_node->if_incoming;
			orig_node->router = neigh_node;

			/* update announced network(s) */
			hna_global_update(orig_node, hna_recv_buff, hna_buff_len, old_router);
		}

		orig_node->router = neigh_node;

	} else if (orig_node != NULL) {
		hna_global_update(orig_node, hna_recv_buff, hna_buff_len,
				  orig_node->router);
	}

	prof_stop(PROF_update_routes);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movw %cx, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movl $0x1, %edi
callq 0x8760
movl $0x4, %edi
leaq 0x119b2(%rip), %rsi     # 0x14a93
movb $0x0, %al
callq 0x123f0
cmpq $0x0, -0x8(%rbp)
je 0x338a
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x10(%rbp), %rax
je 0x338a
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x3163
cmpq $0x0, -0x10(%rbp)
je 0x3163
movq -0x8(%rbp), %rax
movl (%rax), %edi
leaq -0x30(%rbp), %rsi
movl $0x10, %edx
callq 0xfa90
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x40(%rbp), %rsi
movl $0x10, %edx
callq 0xfa90
leaq -0x30(%rbp), %rdx
leaq -0x40(%rbp), %rcx
movl $0x4, %edi
leaq 0x11949(%rip), %rsi     # 0x14aa5
movb $0x0, %al
callq 0x123f0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x3215
cmpq $0x0, -0x10(%rbp)
je 0x3215
movl $0x4, %edi
leaq 0x11930(%rip), %rsi     # 0x14ab9
movb $0x0, %al
callq 0x123f0
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x34(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x20(%rax), %r8d
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %r9
movl $0x20, %esi
xorl %eax, %eax
movl $0x42, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0xa420
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movswl -0x1a(%rbp), %edx
callq 0x9470
jmp 0x337c
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3294
cmpq $0x0, -0x10(%rbp)
jne 0x3294
movl $0x4, %edi
leaq 0x11898(%rip), %rsi     # 0x14acb
movb $0x0, %al
callq 0x123f0
movq -0x8(%rbp), %rdi
callq 0x9cb0
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x20(%rax), %r8d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %r9
movl $0x20, %esi
xorl %ecx, %ecx
movl $0x42, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xa420
jmp 0x337a
movl $0x4, %edi
leaq 0x11844(%rip), %rsi     # 0x14ae4
movb $0x0, %al
callq 0x123f0
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x34(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x20(%rax), %r8d
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %r9
movl $0x20, %esi
xorl %eax, %eax
movl $0x42, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0xa420
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x20(%rax), %r8d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %r9
movl $0x20, %esi
xorl %ecx, %ecx
movl $0x42, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xa420
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movw -0x1a(%rbp), %ax
movq -0x48(%rbp), %rcx
movswl %ax, %edx
callq 0x9920
jmp 0x337c
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x33af
cmpq $0x0, -0x8(%rbp)
je 0x33ad
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movw -0x1a(%rbp), %ax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movswl %ax, %edx
callq 0x9920
jmp 0x33af
movl $0x1, %edi
callq 0x8790
addq $0x60, %rsp
popq %rbp
retq
nop