// File: /workspace/github_c_makefile_star2_O0/open-mesh-mirror[P]batmand/originator.c
// Function: update_orig
void update_orig(struct orig_node *orig_node, struct bat_packet *in, uint32_t neigh, struct batman_if *if_incoming, unsigned char *hna_recv_buff, int16_t hna_buff_len, uint8_t is_duplicate, uint32_t curr_time)
{
	struct list_head *list_pos;
	struct gw_node *gw_node;
	struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
	prof_start(PROF_update_originator);

	debug_output(4, "update_originator(): Searching and updating originator entry of received packet,  \n");

	list_for_each(list_pos, &orig_node->neigh_list) {
		tmp_neigh_node = list_entry(list_pos, struct neigh_node, list);

		if ((tmp_neigh_node->addr == neigh ) && (tmp_neigh_node->if_incoming == if_incoming)) {
			neigh_node = tmp_neigh_node;
			continue;
		}

		if (is_duplicate)
			continue;

		ring_buffer_set(tmp_neigh_node->tq_recv, &tmp_neigh_node->tq_index, 0);
		tmp_neigh_node->tq_avg = ring_buffer_avg(tmp_neigh_node->tq_recv);
	}

	if (!neigh_node)
		neigh_node = create_neighbor(orig_node, get_orig_node(neigh), neigh, if_incoming);
	else
		debug_output(4, "Updating existing last-hop neighbour of originator\n");

	neigh_node->last_valid = curr_time;

	ring_buffer_set(neigh_node->tq_recv, &neigh_node->tq_index, in->tq);
	neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);

	if (!is_duplicate) {
		orig_node->last_ttl = in->ttl;
		neigh_node->last_ttl = in->ttl;
	}

	/**
	 * if we got have a better tq value via this neighbour or
	 * same tq value but the link is more symetric change the next hop
	 * router
	 */
	if ((orig_node->router != neigh_node) && ((!orig_node->router) ||
	    (neigh_node->tq_avg > orig_node->router->tq_avg) ||
	    ((neigh_node->tq_avg == orig_node->router->tq_avg) &&
	     (neigh_node->orig_node->bcast_own_sum[if_incoming->if_num] > orig_node->router->orig_node->bcast_own_sum[if_incoming->if_num]))))
		update_routes(orig_node, neigh_node, hna_recv_buff, hna_buff_len);
	else
		update_routes(orig_node, orig_node->router, hna_recv_buff, hna_buff_len);

	if (orig_node->gwflags != in->gwflags)
		update_gw_list(orig_node, in->gwflags, in->gwport);

	orig_node->gwflags = in->gwflags;
	hna_global_check_tq(orig_node);

	/* restart gateway selection if we have more packets and fast or late switching enabled */
	if ((routing_class > 2) && (orig_node->gwflags != 0) && (curr_gateway != NULL)) {

		/* if the node is not our current gateway and
		   we have preferred gateray disabled and a better tq value or we found our preferred gateway */
		if ((curr_gateway->orig_node != orig_node) &&
				   (((pref_gateway == 0) && (orig_node->router->tq_avg > curr_gateway->orig_node->router->tq_avg)) || (pref_gateway == orig_node->orig))) {

			/* it is our preferred gateway or we have fast switching or the tq is $routing_class better than our old tq */
			if ((pref_gateway == orig_node->orig) || (routing_class == 3) || (orig_node->router->tq_avg - curr_gateway->orig_node->router->tq_avg >= routing_class)) {

				gw_node = NULL;

				list_for_each(list_pos, &gw_list) {
					gw_node = list_entry(list_pos, struct gw_node, list);

					if (gw_node->orig_node == orig_node)
						break;

					gw_node = NULL;
				}

				/* if this gateway had not a gateway failure within the last 30 seconds */
				if ((gw_node != NULL) && ((int)(curr_time - (gw_node->last_failure + 30000)) > 0)) {

					debug_output(3, "Gateway client - restart gateway selection: better gateway found (tq curr: %i, tq new: %i) \n", curr_gateway->orig_node->router->tq_avg, orig_node->router->tq_avg);

					del_default_route();

				}

			}

		}

	}

	prof_stop(PROF_update_originator);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movw %r9w, %ax
movl 0x18(%rbp), %r9d
movb 0x10(%rbp), %r9b
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movw %ax, -0x2a(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl $0x5, %edi
callq 0x8760
movl $0x4, %edi
leaq 0x101a3(%rip), %rsi     # 0x15064
movb $0x0, %al
callq 0x123f0
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
addq $0x48, %rcx
cmpq %rcx, %rax
je 0x4f53
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x4f11
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rax
cmpq -0x20(%rbp), %rax
jne 0x4f11
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x4f46
cmpb $0x0, 0x10(%rbp)
je 0x4f19
jmp 0x4f46
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x50(%rbp), %rsi
addq $0x18, %rsi
xorl %edx, %edx
callq 0x8970
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x89c0
movb %al, %cl
movq -0x50(%rbp), %rax
movb %cl, 0x19(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x4ed4
cmpq $0x0, -0x48(%rbp)
jne 0x4f83
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x14(%rbp), %edi
callq 0x4c50
movq -0x58(%rbp), %rdi
movq %rax, %rsi
movl -0x14(%rbp), %edx
movq -0x20(%rbp), %rcx
callq 0x4a60
movq %rax, -0x48(%rbp)
jmp 0x4f96
movl $0x4, %edi
leaq 0x10129(%rip), %rsi     # 0x150b8
movb $0x0, %al
callq 0x123f0
movl 0x18(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x48(%rbp), %rsi
addq $0x18, %rsi
movq -0x10(%rbp), %rax
movzbl 0x10(%rax), %edx
callq 0x8970
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x89c0
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, 0x19(%rax)
cmpb $0x0, 0x10(%rbp)
jne 0x4ff5
movq -0x10(%rbp), %rax
movb 0x2(%rax), %cl
movq -0x8(%rbp), %rax
movb %cl, 0x44(%rax)
movq -0x10(%rbp), %rax
movb 0x2(%rax), %cl
movq -0x48(%rbp), %rax
movb %cl, 0x1a(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x48(%rbp), %rax
je 0x5091
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x507a
movq -0x48(%rbp), %rax
movzbl 0x19(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movzbl 0x19(%rcx), %ecx
cmpl %ecx, %eax
jg 0x507a
movq -0x48(%rbp), %rax
movzbl 0x19(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movzbl 0x19(%rcx), %ecx
cmpl %ecx, %eax
jne 0x5091
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movzbl 0x1c(%rcx), %ecx
movzbl (%rax,%rcx), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x28(%rcx), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movzbl 0x1c(%rdx), %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jle 0x5091
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rdx
movswl -0x2a(%rbp), %ecx
callq 0x30b0
jmp 0x50aa
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x28(%rbp), %rdx
movswl -0x2a(%rbp), %ecx
callq 0x30b0
movq -0x8(%rbp), %rax
movzbl 0x34(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
cmpl %ecx, %eax
je 0x50d9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movb 0x3(%rax), %cl
movq -0x10(%rbp), %rax
movzbl %cl, %esi
movzwl 0x6(%rax), %edx
callq 0x33c0
movq -0x10(%rbp), %rax
movb 0x3(%rax), %cl
movq -0x8(%rbp), %rax
movb %cl, 0x34(%rax)
movq -0x8(%rbp), %rdi
callq 0xa0b0
leaq 0x16263(%rip), %rax     # 0x1b35a
movzbl (%rax), %eax
cmpl $0x2, %eax
jle 0x5288
movq -0x8(%rbp), %rax
movzbl 0x34(%rax), %eax
cmpl $0x0, %eax
je 0x5288
leaq 0x16245(%rip), %rax     # 0x1b360
cmpq $0x0, (%rax)
je 0x5288
leaq 0x16234(%rip), %rax     # 0x1b360
movq (%rax), %rax
movq 0x8(%rax), %rax
cmpq -0x8(%rbp), %rax
je 0x5286
leaq 0x1622c(%rip), %rax     # 0x1b370
cmpl $0x0, (%rax)
jne 0x516f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x19(%rax), %eax
leaq 0x16204(%rip), %rcx     # 0x1b360
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
movzbl 0x19(%rcx), %ecx
cmpl %ecx, %eax
jg 0x5184
leaq 0x161fa(%rip), %rax     # 0x1b370
movl (%rax), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x5286
leaq 0x161e5(%rip), %rax     # 0x1b370
movl (%rax), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
je 0x51da
leaq 0x161be(%rip), %rax     # 0x1b35a
movzbl (%rax), %eax
cmpl $0x3, %eax
je 0x51da
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x19(%rax), %eax
leaq 0x161a9(%rip), %rcx     # 0x1b360
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
movzbl 0x19(%rcx), %ecx
subl %ecx, %eax
leaq 0x1618b(%rip), %rcx     # 0x1b35a
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jl 0x5284
movq $0x0, -0x40(%rbp)
leaq 0x161d7(%rip), %rax     # 0x1b3c0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
leaq 0x161c9(%rip), %rax     # 0x1b3c0
cmpq %rax, -0x38(%rbp)
je 0x522a
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x5215
jmp 0x522a
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x51f0
cmpq $0x0, -0x40(%rbp)
je 0x5282
movl 0x18(%rbp), %eax
movq -0x40(%rbp), %rcx
movl 0x14(%rcx), %ecx
addl $0x7530, %ecx           # imm = 0x7530
subl %ecx, %eax
cmpl $0x0, %eax
jle 0x5282
leaq 0x16111(%rip), %rax     # 0x1b360
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movzbl 0x19(%rax), %edx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x19(%rax), %ecx
movl $0x3, %edi
leaq 0xfe76(%rip), %rsi      # 0x150ec
movb $0x0, %al
callq 0x123f0
callq 0xfb30
jmp 0x5284
jmp 0x5286
jmp 0x5288
movl $0x5, %edi
callq 0x8790
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)