// File: /workspace/github_c_makefile_star2_O1/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 0xb155(%rip), %rsi      # 0x104aa
movl $0x4, %edi
xorl %eax, %eax
callq 0xd5b0
movl $0x30, %edi
movl $0x1f5, %esi            # imm = 0x1F5
callq 0x5d3e
movq %rax, %r14
movq %rax, (%rax)
callq 0xb0fc
movl %eax, %ebp
leaq 0x11f06(%rip), %rax     # 0x1728a
movswl (%rax), %r15d
movl $0xc8, %edi
callq 0xb8d1
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 0x1226c(%rip), %r15     # 0x17628
cmpb $0x0, (%r15)
je 0x53c8
cmpb $0x0, 0x1c(%rbx)
je 0x53f3
movl $0x200, %edi            # imm = 0x200
movl $0x1f7, %esi            # imm = 0x1F7
callq 0x5d3e
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 0x543b
movl $0x200, %edi            # imm = 0x200
movl $0x1f6, %esi            # imm = 0x1F6
callq 0x5d3e
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 0x121fc(%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)
movq 0x10(%r14), %rax
rolw $0x8, 0x4(%rax)
leaq 0x11ee0(%rip), %rax     # 0x17338
movq %rax, %r15
movq %r15, %rdi
movq (%r15), %r15
cmpq %rax, %r15
je 0x5480
movl 0x8(%r15), %ecx
cmpl 0x8(%r14), %ecx
js 0x545b
movq %r15, %rsi
movq %r14, %rdx
callq 0x5bc8
testq %r15, %r15
jne 0x548f
leaq 0x11eb1(%rip), %rsi     # 0x17338
movq %r14, %rdi
callq 0x5bb9
incw 0x5a(%rbx)
leaq 0x11e96(%rip), %r15     # 0x17330
movq (%r15), %rdi
xorl %esi, %esi
callq 0x6416
testq %rax, %rax
je 0x5556
movq %rax, %r14
leaq 0x11de1(%rip), %rbp     # 0x17298
leaq 0xa8d0(%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 0xafe9(%rip), %rsi      # 0x104c6
xorl %eax, %eax
callq 0xd5b0
movzbl 0x1c(%rbx), %eax
movzbl (%rbp), %edi
imull %eax, %edi
shll $0x3, %edi
addq 0x18(%r13), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x6205
movzbl 0x1c(%rbx), %eax
movzbl (%rbp), %edi
imull %eax, %edi
shll $0x3, %edi
addq 0x18(%r13), %rdi
callq 0x6309
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 0xd5b0
movq (%r15), %rdi
movq %r14, %rsi
callq 0x6416
movq %rax, %r14
testq %rax, %rax
jne 0x54be
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq