// File: /workspace/github_c_makefile_star2_O2/open-mesh-mirror[P]batmand/schedule.c
// Function: send_outstanding_packets
void send_outstanding_packets(uint32_t curr_time)
{
	struct forw_node *forw_node;
	struct list_head *forw_pos, *if_pos, *temp;
	struct batman_if *batman_if;
	struct bat_packet *bat_packet;
	char orig_str[ADDR_STR_LEN];
	uint8_t directlink, curr_packet_num;
	int16_t curr_packet_len;

	prof_start(PROF_send_outstanding_packets);


	list_for_each_safe(forw_pos, temp, &forw_list) {

		forw_node = list_entry(forw_pos, struct forw_node, list);

		if ((int)(curr_time - forw_node->send_time) < 0)
			break;

		bat_packet = (struct bat_packet *)forw_node->pack_buff;

		addr_to_string(bat_packet->orig, orig_str, ADDR_STR_LEN);

		directlink = (bat_packet->flags & DIRECTLINK ? 1 : 0);

		if (forw_node->if_incoming == NULL) {
			debug_output(0, "Error - can't forward packet: incoming iface not specified \n");
			goto packet_free;
		}

		/* multihomed peer assumed */
		/* non-primary interfaces are only broadcasted on their interface */
		if (((directlink) && (bat_packet->ttl == 1)) ||
			((forw_node->own) && (forw_node->if_incoming->if_num > 0))) {

			debug_output(4, "%s packet (originator %s, seqno %d, TTL %d) on interface %s\n", (forw_node->own ? "Sending own" : "Forwarding"), orig_str, ntohs(bat_packet->seqno), bat_packet->ttl, forw_node->if_incoming->dev);

			if (send_udp_packet(forw_node->pack_buff, forw_node->pack_buff_len, &forw_node->if_incoming->broad, forw_node->if_incoming->udp_send_sock, forw_node->if_incoming) < 0)
					deactivate_interface(forw_node->if_incoming);

			goto packet_free;

		}

		list_for_each(if_pos, &if_list) {

			batman_if = list_entry(if_pos, struct batman_if, list);

			curr_packet_num = curr_packet_len = 0;
			bat_packet = (struct bat_packet *)forw_node->pack_buff;

			while ((curr_packet_len + sizeof(struct bat_packet) <= forw_node->pack_buff_len) &&
				(curr_packet_len + sizeof(struct bat_packet) + bat_packet->hna_len * 5 <= forw_node->pack_buff_len) &&
				(curr_packet_len + sizeof(struct bat_packet) + bat_packet->hna_len * 5 <= MAX_AGGREGATION_BYTES)) {

				if ((forw_node->direct_link_flags & (1 << curr_packet_num)) && (forw_node->if_incoming == batman_if))
					bat_packet->flags |= DIRECTLINK;
				else
					bat_packet->flags &= ~DIRECTLINK;

				if (curr_packet_num > 0)
					addr_to_string(bat_packet->orig, orig_str, ADDR_STR_LEN);

				debug_output(4, "%s %spacket (originator %s, seqno %d, TQ %d, TTL %d, IDF %s) on interface %s\n", (curr_packet_num > 0 ? "Forwarding" : (forw_node->own ? "Sending own" : "Forwarding")), (curr_packet_num > 0 ? "aggregated " : ""), orig_str, ntohs(bat_packet->seqno), bat_packet->tq, bat_packet->ttl, (bat_packet->flags & DIRECTLINK ? "on" : "off"), batman_if->dev);

				curr_packet_len += sizeof(struct bat_packet) + bat_packet->hna_len * 5;
				curr_packet_num++;
				bat_packet = (struct bat_packet *)(forw_node->pack_buff + curr_packet_len);

			}

			if (send_udp_packet(forw_node->pack_buff, forw_node->pack_buff_len, &batman_if->broad, batman_if->udp_send_sock, batman_if) < 0)
				deactivate_interface(batman_if);

		}

packet_free:	list_del((struct list_head *)&forw_list, forw_pos, &forw_list);

		if (forw_node->own && forw_node->if_incoming)
			schedule_own_packet(forw_node->if_incoming);

		debugFree(forw_node->pack_buff, 1501);
		debugFree(forw_node, 1502);

	}

	prof_stop(PROF_send_outstanding_packets);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edi, 0xc(%rsp)
pushq $0x8
popq %rdi
callq 0x63a8
leaq 0x11eae(%rip), %rbx     # 0x17338
movq (%rbx), %rbp
leaq 0x10(%rsp), %r14
cmpq %rbx, %rbp
je 0x571f
movl 0xc(%rsp), %eax
cmpl 0x8(%rbp), %eax
js 0x571f
movq (%rbp), %rax
movq %rax, 0x28(%rsp)
movq 0x10(%rbp), %rbx
movl 0x8(%rbx), %edi
movq %r14, %rsi
pushq $0x10
popq %rdx
callq 0xb04f
movq 0x28(%rbp), %r10
testq %r10, %r10
je 0x556b
testb $0x40, 0x1(%rbx)
je 0x54f8
cmpb $0x1, 0x2(%rbx)
jne 0x54f8
cmpb $0x0, 0xc(%rbp)
leaq 0xa107(%rip), %rdx      # 0xf5ee
leaq 0xa10c(%rip), %rax      # 0xf5fa
cmoveq %rax, %rdx
pushq $0x1
popq %r9
jmp 0x5519
cmpb $0x0, 0xc(%rbp)
je 0x55c9
cmpb $0x0, 0x1c(%r10)
je 0x55c9
movzbl 0x2(%rbx), %r9d
leaq 0xa0d5(%rip), %rdx      # 0xf5ee
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %r8d
subq $0x8, %rsp
pushq $0x4
popq %rdi
leaq 0xa07e(%rip), %rsi      # 0xf5b1
movq %r14, %rcx
xorl %eax, %eax
pushq 0x8(%r10)
callq 0xcb1c
popq %rax
popq %rcx
movzwl 0x18(%rbp), %esi
movq 0x10(%rbp), %rdi
movq 0x28(%rbp), %r8
leaq 0x40(%r8), %rdx
movl 0x10(%r8), %ecx
callq 0xb2dd
testb %al, %al
jns 0x557b
movq 0x28(%rbp), %rdi
callq 0xa44a
jmp 0x557b
xorl %edi, %edi
leaq 0xa000(%rip), %rsi      # 0xf574
xorl %eax, %eax
callq 0xcb1c
leaq 0x11db6(%rip), %rbx     # 0x17338
movq %rbx, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x5763
cmpb $0x0, 0xc(%rbp)
je 0x55a4
movq 0x28(%rbp), %rdi
testq %rdi, %rdi
je 0x55a4
callq 0x4f74
movq 0x10(%rbp), %rdi
movl $0x5dd, %esi            # imm = 0x5DD
callq 0x5b1a
movq %rbp, %rdi
movl $0x5de, %esi            # imm = 0x5DE
callq 0x5b1a
movq 0x28(%rsp), %rbp
jmp 0x548d
leaq 0x11d40(%rip), %r13     # 0x17310
movq (%r13), %r13
cmpq 0x119fd(%rip), %r13     # 0x16fd8
je 0x557b
movq 0x10(%rbp), %rdi
xorl %edx, %edx
movq %rdi, %rbx
xorl %r12d, %r12d
movswq %r12w, %r12
addq $0x12, %r12
movzwl 0x18(%rbp), %esi
cmpq %rsi, %r12
ja 0x56fa
movzbl 0x11(%rbx), %eax
leaq (%rax,%rax,4), %rax
addq %r12, %rax
cmpq %rsi, %rax
ja 0x56fa
cmpq $0x200, %rax            # imm = 0x200
ja 0x56fa
movl 0x1c(%rbp), %eax
movzbl %dl, %ecx
btl %ecx, %eax
jae 0x562f
cmpq %r13, 0x28(%rbp)
je 0x5636
movb 0x1(%rbx), %al
andb $-0x41, %al
jmp 0x563b
movb 0x1(%rbx), %al
orb $0x40, %al
movb %al, 0x1(%rbx)
movq %rdx, 0x30(%rsp)
testb %dl, %dl
je 0x566d
movl 0x8(%rbx), %edi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
pushq $0x10
popq %rdx
callq 0xb04f
movb 0x1(%rbx), %al
leaq 0x9fef(%rip), %rcx      # 0xf653
leaq 0x9f8f(%rip), %rdx      # 0xf5fa
jmp 0x568f
cmpb $0x0, 0xc(%rbp)
leaq 0x9f76(%rip), %rdx      # 0xf5ee
leaq 0x9f7b(%rip), %rcx      # 0xf5fa
cmoveq %rcx, %rdx
leaq 0x8d44(%rip), %rcx      # 0xe3ce
leaq 0x10(%rsp), %r14
movzwl 0x4(%rbx), %esi
rolw $0x8, %si
movzwl %si, %r9d
movzbl 0x10(%rbx), %r10d
movzbl 0x2(%rbx), %r11d
testb $0x40, %al
leaq 0xcb35(%rip), %r15      # 0x121e3
leaq 0x9faa(%rip), %rax      # 0xf65f
cmoveq %rax, %r15
pushq $0x4
popq %rdi
leaq 0x9f42(%rip), %rsi      # 0xf605
movq %r14, %r8
xorl %eax, %eax
pushq 0x8(%r13)
pushq %r15
pushq %r11
pushq %r10
callq 0xcb1c
addq $0x20, %rsp
movzbl 0x11(%rbx), %eax
leaq (%rax,%rax,4), %rax
addq %rax, %r12
movq 0x30(%rsp), %rdx
incb %dl
movq 0x10(%rbp), %rdi
leaq (%rdi,%r12), %rbx
jmp 0x55e9
leaq 0x40(%r13), %rdx
movl 0x10(%r13), %ecx
movq %r13, %r8
callq 0xb2dd
testb %al, %al
jns 0x55d0
movq %r13, %rdi
callq 0xa44a
jmp 0x55d0
pushq $0x8
popq %rdi
callq 0x63c4
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop