// File: /workspace/github_c_makefile_star2_O2/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 0xa51d(%rip), %rsi      # 0xf4aa
pushq $0x4
popq %rdi
xorl %eax, %eax
callq 0xcb1c
pushq $0x30
popq %rdi
movl $0x1f5, %esi            # imm = 0x1F5
callq 0x58c9
movq %rax, %r14
movq %rax, (%rax)
callq 0xa9e4
movl %eax, %ebp
leaq 0x122d2(%rip), %rax     # 0x1728a
movswl (%rax), %r15d
movl $0xc8, %edi
callq 0xb066
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)
andl $0x0, 0x1c(%r14)
leaq 0x1263b(%rip), %r15     # 0x17628
cmpb $0x0, (%r15)
je 0x4ff9
cmpb $0x0, 0x1c(%rbx)
je 0x5024
movl $0x200, %edi            # imm = 0x200
movl $0x1f7, %esi            # imm = 0x1F7
callq 0x58c9
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 0x506c
movl $0x200, %edi            # imm = 0x200
movl $0x1f6, %esi            # imm = 0x1F6
callq 0x58c9
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 0x125cb(%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 0x122b3(%rip), %rax     # 0x17338
movq %rax, %r15
movq %r15, %rdi
movq (%r15), %r15
cmpq %rax, %r15
je 0x50ad
movl 0x8(%r15), %ecx
cmpl 0x8(%r14), %ecx
js 0x5088
movq %r15, %rsi
movq %r14, %rdx
callq 0x575c
testq %r15, %r15
jne 0x50bc
leaq 0x12284(%rip), %rsi     # 0x17338
movq %r14, %rdi
callq 0x574d
incw 0x5a(%rbx)
pushq $0x4
popq %rbp
leaq 0x121ce(%rip), %r14     # 0x17298
leaq 0x9cbd(%rip), %r12      # 0xed8e
xorl %r13d, %r13d
leaq 0x12255(%rip), %rax     # 0x17330
movq (%rax), %rdi
movq %r13, %rsi
callq 0x5f8c
testq %rax, %rax
je 0x5170
movq %rax, %r13
movq 0x8(%rax), %rax
movq (%rax), %r15
movq 0x20(%r15), %rax
movzbl 0x1c(%rbx), %ecx
movzbl (%rax,%rcx), %edx
movl %ebp, %edi
leaq 0xa3b8(%rip), %rsi      # 0xf4c6
xorl %eax, %eax
callq 0xcb1c
movzbl 0x1c(%rbx), %eax
movzbl (%r14), %edi
imull %eax, %edi
shll $0x3, %edi
addq 0x18(%r15), %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x5dc5
movzbl 0x1c(%rbx), %eax
movzbl (%r14), %edi
imull %eax, %edi
shll $0x3, %edi
addq 0x18(%r15), %rdi
callq 0x5ea9
movq 0x20(%r15), %rcx
movzbl 0x1c(%rbx), %edx
movb %al, (%rcx,%rdx)
movq 0x20(%r15), %rax
movzbl 0x1c(%rbx), %ecx
movzbl (%rax,%rcx), %edx
movl %ebp, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0xcb1c
jmp 0x50d4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq