// File: /workspace/github_c_makefile_star2_O0/open-mesh-mirror[P]batmand/originator.c
// Function: purge_orig
void purge_orig(uint32_t curr_time)
{
	struct hash_it_t *hashit = NULL;
	struct list_head *neigh_pos, *neigh_temp, *prev_list_head;
	struct list_head *gw_pos, *gw_pos_tmp;
	struct orig_node *orig_node;
	struct neigh_node *neigh_node, *best_neigh_node;
	struct gw_node *gw_node;
	uint8_t gw_purged = 0, neigh_purged, max_tq;
	char orig_str[ADDR_STR_LEN], neigh_str[ADDR_STR_LEN];
	prof_start( PROF_purge_originator );


	/* for all origins... */
	while ( NULL != ( hashit = hash_iterate( orig_hash, hashit ) ) ) {

		orig_node = hashit->bucket->data;

		if ((int)(curr_time - (orig_node->last_valid + (2 * purge_timeout))) > 0) {

			addr_to_string( orig_node->orig, orig_str, ADDR_STR_LEN );
			debug_output( 4, "Originator timeout: originator %s, last_valid %u \n", orig_str, orig_node->last_valid );

			hash_remove_bucket( orig_hash, hashit );

			/* for all neighbours towards this originator ... */
			list_for_each_safe( neigh_pos, neigh_temp, &orig_node->neigh_list ) {

				neigh_node = list_entry(neigh_pos, struct neigh_node, list);

				list_del((struct list_head *)&orig_node->neigh_list, neigh_pos, &orig_node->neigh_list);
				debugFree(neigh_node->tq_recv, 1407);
				debugFree(neigh_node->real_bits, 1409);
				debugFree(neigh_node, 1401);

			}

			list_for_each( gw_pos, &gw_list ) {

				gw_node = list_entry( gw_pos, struct gw_node, list );

				if ( gw_node->deleted )
					continue;

				if ( gw_node->orig_node == orig_node ) {

					addr_to_string( gw_node->orig_node->orig, orig_str, ADDR_STR_LEN );
					debug_output( 3, "Removing gateway %s from gateway list \n", orig_str );

					gw_node->deleted = get_time_msec();
					gw_purged = 1;

					break;

				}

			}

			update_routes( orig_node, NULL, NULL, 0 );

			debugFree( orig_node->bcast_own, 1403 );
			debugFree( orig_node->bcast_own_sum, 1404 );
			debugFree( orig_node, 1405 );

		} else {

			best_neigh_node = NULL;
			max_tq = neigh_purged = 0;
			prev_list_head = (struct list_head *)&orig_node->neigh_list;

			/* for all neighbours towards this originator ... */
			list_for_each_safe( neigh_pos, neigh_temp, &orig_node->neigh_list ) {

				neigh_node = list_entry( neigh_pos, struct neigh_node, list );

				if ((int)(curr_time - (neigh_node->last_valid + purge_timeout)) > 0) {

					addr_to_string( orig_node->orig, orig_str, ADDR_STR_LEN );
					addr_to_string( neigh_node->addr, neigh_str, ADDR_STR_LEN );
					debug_output( 4, "Neighbour timeout: originator %s, neighbour: %s, last_valid %u \n", orig_str, neigh_str, neigh_node->last_valid );

					if (orig_node->router == neigh_node) {

						/* we have to delete the route towards this node before it gets purged */
						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);

						/* if the neighbour is the route towards our gateway */
						if ((curr_gateway != NULL) && (curr_gateway->orig_node == orig_node))
							del_default_route();

						orig_node->router = NULL;

					}

					neigh_purged = 1;
					list_del(prev_list_head, neigh_pos, &orig_node->neigh_list);
					debugFree(neigh_node->tq_recv, 1408);
					debugFree(neigh_node->real_bits, 1410);
					debugFree(neigh_node, 1406);

				} else {

					if ((best_neigh_node == NULL) || (neigh_node->tq_avg > max_tq)) {
						best_neigh_node = neigh_node;
						max_tq = neigh_node->tq_avg;
					}

					prev_list_head = &neigh_node->list;

				}

			}

			if ((neigh_purged) && ((best_neigh_node == NULL) || (orig_node->router == NULL) || (max_tq > orig_node->router->tq_avg)))
				update_routes( orig_node, best_neigh_node, orig_node->hna_buff, orig_node->hna_buff_len );

		}

	}


	prev_list_head = (struct list_head *)&gw_list;

	list_for_each_safe( gw_pos, gw_pos_tmp, &gw_list ) {

		gw_node = list_entry(gw_pos, struct gw_node, list);

		if ((gw_node->deleted) && ((int)(curr_time - (gw_node->deleted + (2 * purge_timeout))) > 0)) {

			list_del( prev_list_head, gw_pos, &gw_list );
			debugFree( gw_pos, 1406 );

		} else {

			prev_list_head = &gw_node->list;

		}

	}

	prof_stop( PROF_purge_originator );

	if ( gw_purged )
		choose_gw();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl %edi, -0x4(%rbp)
movq $0x0, -0x10(%rbp)
movb $0x0, -0x59(%rbp)
movl $0x6, %edi
callq 0x8760
leaq 0x16105(%rip), %rax     # 0x1b3d0
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x7fb0
movq %rax, %rcx
movq %rcx, -0x10(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x571b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x4(%rbp), %eax
movq -0x40(%rbp), %rcx
movl 0x30(%rcx), %ecx
leaq 0x15f9f(%rip), %rdx     # 0x1b2a8
movl (%rdx), %edx
shll %edx
addl %edx, %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x54ca
movq -0x40(%rbp), %rax
movl (%rax), %edi
leaq -0x70(%rbp), %rsi
movl $0x10, %edx
callq 0xfa90
leaq -0x70(%rbp), %rdx
movq -0x40(%rbp), %rax
movl 0x30(%rax), %ecx
movl $0x4, %edi
leaq 0xfe04(%rip), %rsi      # 0x15149
movb $0x0, %al
callq 0x123f0
leaq 0x1607d(%rip), %rax     # 0x1b3d0
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x8480
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
addq $0x48, %rcx
cmpq %rcx, %rax
je 0x53ef
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
addq $0x48, %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq $0x48, %rdx
callq 0x6ed0
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x57f, %esi            # imm = 0x57F
callq 0x7720
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rdi
movl $0x581, %esi            # imm = 0x581
callq 0x7720
movq -0x48(%rbp), %rdi
movl $0x579, %esi            # imm = 0x579
callq 0x7720
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x5376
leaq 0x15fca(%rip), %rax     # 0x1b3c0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x15fbc(%rip), %rax     # 0x1b3c0
cmpq %rax, -0x30(%rbp)
je 0x5481
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x541e
jmp 0x5471
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x40(%rbp), %rax
jne 0x546f
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %edi
leaq -0x70(%rbp), %rsi
movl $0x10, %edx
callq 0xfa90
leaq -0x70(%rbp), %rdx
movl $0x3, %edi
leaq 0xfd28(%rip), %rsi      # 0x1517c
movb $0x0, %al
callq 0x123f0
callq 0xf260
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x18(%rax)
movb $0x1, -0x59(%rbp)
jmp 0x5481
jmp 0x5471
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x53fd
movq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
movq %rdx, %rsi
callq 0x30b0
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x57b, %esi            # imm = 0x57B
callq 0x7720
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdi
movl $0x57c, %esi            # imm = 0x57C
callq 0x7720
movq -0x40(%rbp), %rdi
movl $0x57d, %esi            # imm = 0x57D
callq 0x7720
jmp 0x5716
movq $0x0, -0x50(%rbp)
movb $0x0, -0x5a(%rbp)
movb $0x0, -0x5b(%rbp)
movq -0x40(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
addq $0x48, %rcx
cmpq %rcx, %rax
je 0x56c8
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x4(%rbp), %eax
movq -0x48(%rbp), %rcx
movl 0x1c(%rcx), %ecx
leaq 0x15d7d(%rip), %rdx     # 0x1b2a8
addl (%rdx), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x567d
movq -0x40(%rbp), %rax
movl (%rax), %edi
leaq -0x70(%rbp), %rsi
movl $0x10, %edx
callq 0xfa90
movq -0x48(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x80(%rbp), %rsi
movl $0x10, %edx
callq 0xfa90
leaq -0x70(%rbp), %rdx
leaq -0x80(%rbp), %rcx
movq -0x48(%rbp), %rax
movl 0x1c(%rax), %r8d
movl $0x4, %edi
leaq 0xfc27(%rip), %rsi      # 0x151a4
movb $0x0, %al
callq 0x123f0
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x48(%rbp), %rax
jne 0x5630
movl $0x4, %edi
leaq 0xfc43(%rip), %rsi      # 0x151e5
movb $0x0, %al
callq 0x123f0
movq -0x40(%rbp), %rdi
callq 0x9cb0
movq -0x40(%rbp), %rax
movl (%rax), %edi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %edx
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x20(%rax), %r8d
movq -0x40(%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
leaq 0x15d5b(%rip), %rax     # 0x1b360
cmpq $0x0, (%rax)
je 0x5624
leaq 0x15d4e(%rip), %rax     # 0x1b360
movq (%rax), %rax
movq 0x8(%rax), %rax
cmpq -0x40(%rbp), %rax
jne 0x5624
callq 0xfb30
movq -0x40(%rbp), %rax
movq $0x0, 0x8(%rax)
movb $0x1, -0x5a(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq $0x48, %rdx
callq 0x6ed0
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x580, %esi            # imm = 0x580
callq 0x7720
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rdi
movl $0x582, %esi            # imm = 0x582
callq 0x7720
movq -0x48(%rbp), %rdi
movl $0x57e, %esi            # imm = 0x57E
callq 0x7720
jmp 0x56ae
cmpq $0x0, -0x50(%rbp)
je 0x5694
movq -0x48(%rbp), %rax
movzbl 0x19(%rax), %eax
movzbl -0x5b(%rbp), %ecx
cmpl %ecx, %eax
jle 0x56a6
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movb 0x19(%rax), %al
movb %al, -0x5b(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x56b0
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x54fd
movzbl -0x5a(%rbp), %eax
cmpl $0x0, %eax
je 0x5714
cmpq $0x0, -0x50(%rbp)
je 0x56f7
movq -0x40(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x56f7
movzbl -0x5b(%rbp), %eax
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rcx
movzbl 0x19(%rcx), %ecx
cmpl %ecx, %eax
jle 0x5714
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x40(%rbp), %rax
movswl 0x40(%rax), %ecx
callq 0x30b0
jmp 0x5716
jmp 0x52c4
leaq 0x15c9e(%rip), %rax     # 0x1b3c0
movq %rax, -0x28(%rbp)
leaq 0x15c93(%rip), %rax     # 0x1b3c0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
leaq 0x15c7a(%rip), %rax     # 0x1b3c0
cmpq %rax, -0x30(%rbp)
je 0x57bf
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x57a0
movl -0x4(%rbp), %eax
movq -0x58(%rbp), %rcx
movl 0x18(%rcx), %ecx
leaq 0x15b39(%rip), %rdx     # 0x1b2a8
movl (%rdx), %edx
shll %edx
addl %edx, %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x57a0
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x15c35(%rip), %rdx     # 0x1b3c0
callq 0x6ed0
movq -0x30(%rbp), %rdi
movl $0x57e, %esi            # imm = 0x57E
callq 0x7720
jmp 0x57a8
movq -0x58(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x57aa
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x573f
movl $0x6, %edi
callq 0x8790
cmpb $0x0, -0x59(%rbp)
je 0x57d4
callq 0x2c70
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)