// File: /workspace/github_c_makefile_star2_O3/open-mesh-mirror[P]batmand/schedule.c
// Function: schedule_own_packet
void schedule_own_packet(struct batman_if *batman_if)
{
	struct forw_node *forw_node_new, *forw_packet_tmp = NULL;
	struct list_head *list_pos, *prev_list_head;
	struct hash_it_t *hashit = NULL;
	struct orig_node *orig_node;


	debug_output(4, "schedule_own_packet(): %s \n", batman_if->dev);

	forw_node_new = debugMalloc(sizeof(struct forw_node), 501);

	INIT_LIST_HEAD(&forw_node_new->list);

	forw_node_new->send_time = get_time_msec() + originator_interval - JITTER + rand_num(2 * JITTER);
	forw_node_new->if_incoming = batman_if;
	forw_node_new->own = 1;
	forw_node_new->num_packets = 0;
	forw_node_new->direct_link_flags = 0;

	/* non-primary interfaces do not send hna information */
	if ((num_hna_local > 0) && (batman_if->if_num == 0)) {

		forw_node_new->pack_buff = debugMalloc(MAX_AGGREGATION_BYTES, 502);
		memcpy(forw_node_new->pack_buff, (unsigned char *)&batman_if->out, sizeof(struct bat_packet));
		memcpy(forw_node_new->pack_buff + sizeof(struct bat_packet), hna_buff_local, num_hna_local * 5);
		forw_node_new->pack_buff_len = sizeof(struct bat_packet) + num_hna_local * 5;
		((struct bat_packet *)forw_node_new->pack_buff)->hna_len = num_hna_local;

	} else {

		forw_node_new->pack_buff = debugMalloc(MAX_AGGREGATION_BYTES, 503);
		memcpy(forw_node_new->pack_buff, &batman_if->out, sizeof(struct bat_packet));
		forw_node_new->pack_buff_len = sizeof(struct bat_packet);
		((struct bat_packet *)forw_node_new->pack_buff)->hna_len = 0;

	}

	/* change sequence number to network order */
	((struct bat_packet *)forw_node_new->pack_buff)->seqno = htons(((struct bat_packet *)forw_node_new->pack_buff)->seqno);

	prev_list_head = (struct list_head *)&forw_list;

	list_for_each(list_pos, &forw_list) {

		forw_packet_tmp = list_entry(list_pos, struct forw_node, list);

		if ((int)(forw_packet_tmp->send_time - forw_node_new->send_time) >= 0) {

			list_add_before(prev_list_head, list_pos, &forw_node_new->list);
			break;

		}

		prev_list_head = &forw_packet_tmp->list;
		forw_packet_tmp = NULL;

	}

	if (forw_packet_tmp == NULL)
		list_add_tail(&forw_node_new->list, &forw_list);

	batman_if->out.seqno++;


	while ( NULL != ( hashit = hash_iterate( orig_hash, hashit ) ) ) {

		orig_node = hashit->bucket->data;

		debug_output( 4, "count own bcast (schedule_own_packet): old = %i, ", orig_node->bcast_own_sum[batman_if->if_num] );
		bit_get_packet( (TYPE_OF_WORD *)&(orig_node->bcast_own[batman_if->if_num * num_words]), 1, 0 );
		orig_node->bcast_own_sum[batman_if->if_num] = bit_packet_count( (TYPE_OF_WORD *)&(orig_node->bcast_own[batman_if->if_num * num_words]) );
		debug_output( 4, "new = %i \n", orig_node->bcast_own_sum[batman_if->if_num] );

	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdx
leaq 0xb159(%rip), %rsi      # 0x104aa
movl $0x4, %edi
xorl %eax, %eax
callq 0xd88c
movl $0x30, %edi
movl $0x1f5, %esi            # imm = 0x1F5
callq 0x5d52
movq %rax, %r14
movq %rax, (%rax)
callq 0xb3f0
movl %eax, %ebp
leaq 0x11f0a(%rip), %rax     # 0x1728a
movswl (%rax), %r15d
movl $0xc8, %edi
callq 0xbbc5
addl %ebp, %r15d
addl %r15d, %eax
addl $-0x64, %eax
movl %eax, 0x8(%r14)
movq %rbx, 0x28(%r14)
movb $0x1, 0xc(%r14)
movb $0x0, 0x20(%r14)
movl $0x0, 0x1c(%r14)
leaq 0x12270(%rip), %r15     # 0x17628
cmpb $0x0, (%r15)
je 0x53c4
cmpb $0x0, 0x1c(%rbx)
je 0x53ef
movl $0x200, %edi            # imm = 0x200
movl $0x1f7, %esi            # imm = 0x1F7
callq 0x5d52
movq %rax, 0x10(%r14)
movups 0x56(%rbx), %xmm0
movups %xmm0, (%rax)
movzwl 0x66(%rbx), %ecx
movw %cx, 0x10(%rax)
movw $0x12, %ax
xorl %r15d, %r15d
jmp 0x5437
movl $0x200, %edi            # imm = 0x200
movl $0x1f6, %esi            # imm = 0x1F6
callq 0x5d52
movq %rax, 0x10(%r14)
movups 0x56(%rbx), %xmm0
movups %xmm0, (%rax)
movzwl 0x66(%rbx), %ecx
movw %cx, 0x10(%rax)
movq 0x10(%r14), %rdi
addq $0x12, %rdi
leaq 0x12200(%rip), %rax     # 0x17620
movq (%rax), %rsi
movzbl (%r15), %r15d
leaq (%r15,%r15,4), %rdx
callq 0x2290
leal (%r15,%r15,4), %eax
addl $0x12, %eax
movw %ax, 0x18(%r14)
movq 0x10(%r14), %rax
movb %r15b, 0x11(%rax)
rolw $0x8, 0x4(%rax)
leaq 0x11ee8(%rip), %rax     # 0x17338
movq %rax, %r15
movq %r15, %rdi
movq (%r15), %r15
cmpq %rax, %r15
je 0x5478
movl 0x8(%r15), %ecx
cmpl 0x8(%r14), %ecx
js 0x5453
movq %r15, %rsi
movq %r14, %rdx
callq 0x5bdc
testq %r15, %r15
jne 0x5487
leaq 0x11eb9(%rip), %rsi     # 0x17338
movq %r14, %rdi
callq 0x5bcd
incw 0x5a(%rbx)
leaq 0x11e9e(%rip), %r15     # 0x17330
movq (%r15), %rdi
xorl %esi, %esi
callq 0x6741
testq %rax, %rax
je 0x554e
movq %rax, %r14
leaq 0x11de9(%rip), %rbp     # 0x17298
leaq 0xa8d8(%rip), %r12      # 0xfd8e
movq 0x8(%r14), %rax
movq (%rax), %r13
movq 0x20(%r13), %rax
movzbl 0x1c(%rbx), %ecx
movzbl (%rax,%rcx), %edx
movl $0x4, %edi
leaq 0xaff1(%rip), %rsi      # 0x104c6
xorl %eax, %eax
callq 0xd88c
movzbl 0x1c(%rbx), %eax
movzbl (%rbp), %edi
imull %eax, %edi
shll $0x3, %edi
addq 0x18(%r13), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x652d
movzbl 0x1c(%rbx), %eax
movzbl (%rbp), %edi
imull %eax, %edi
shll $0x3, %edi
addq 0x18(%r13), %rdi
callq 0x6630
movq 0x20(%r13), %rcx
movzbl 0x1c(%rbx), %edx
movb %al, (%rcx,%rdx)
movq 0x20(%r13), %rax
movzbl 0x1c(%rbx), %ecx
movzbl (%rax,%rcx), %edx
movl $0x4, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0xd88c
movq (%r15), %rdi
movq %r14, %rsi
callq 0x6741
movq %rax, %r14
testq %rax, %rax
jne 0x54b6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq