// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl %edi, 0xc(%rsp)
movl $0x8, %edi
callq 0x6bbc
leaq 0x11aba(%rip), %rax     # 0x17338
movq (%rax), %r12
cmpq %rax, %r12
je 0x5b9c
leaq 0x10(%rsp), %r14
movl 0xc(%rsp), %eax
cmpl 0x8(%r12), %eax
js 0x5b9c
movq (%r12), %r15
movq 0x10(%r12), %rbx
movl 0x8(%rbx), %edi
movq %r14, %rsi
movl $0x10, %edx
callq 0xbbac
movq 0x28(%r12), %r10
testq %r10, %r10
movq %r15, 0x20(%rsp)
je 0x597b
testb $0x40, 0x1(%rbx)
je 0x58f6
cmpb $0x1, 0x2(%rbx)
jne 0x58f6
cmpb $0x0, 0xc(%r12)
leaq 0xad0b(%rip), %rdx      # 0x105ee
leaq 0xad10(%rip), %rax      # 0x105fa
cmoveq %rax, %rdx
movl $0x1, %r9d
jmp 0x5919
cmpb $0x0, 0xc(%r12)
je 0x5990
cmpb $0x0, 0x1c(%r10)
je 0x5990
movzbl 0x2(%rbx), %r9d
leaq 0xacd5(%rip), %rdx      # 0x105ee
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %r8d
subq $0x8, %rsp
movl $0x4, %edi
leaq 0xac7c(%rip), %rsi      # 0x105b1
movq %r14, %rcx
xorl %eax, %eax
pushq 0x8(%r10)
callq 0xd88c
addq $0x10, %rsp
movzwl 0x18(%r12), %esi
movq 0x10(%r12), %rdi
movq 0x28(%r12), %r8
leaq 0x40(%r8), %rdx
movl 0x10(%r8), %ecx
callq 0xbe54
testb %al, %al
jns 0x5b41
movq 0x28(%r12), %rdi
callq 0xadf9
jmp 0x5b41
xorl %edi, %edi
leaq 0xabf0(%rip), %rsi      # 0x10574
xorl %eax, %eax
callq 0xd88c
jmp 0x5b41
leaq 0x11979(%rip), %rax     # 0x17310
movq (%rax), %rbx
cmpq %rax, %rbx
je 0x5b41
movzwl 0x18(%r12), %eax
movq 0x10(%r12), %r15
cmpq $0x12, %rax
movq %rbx, (%rsp)
jb 0x5b0c
movzbl 0x11(%r15), %ecx
cmpq $0x63, %rcx
setae %dl
leaq (%rcx,%rcx,4), %rcx
addl $0x12, %ecx
cmpl %eax, %ecx
seta %cl
orb %dl, %cl
jne 0x5b0c
leaq 0x11(%r15), %r13
xorl %r14d, %r14d
xorl %ebx, %ebx
movl 0x1c(%r12), %eax
movzbl %r14b, %ecx
btl %ecx, %eax
jae 0x59fe
movq (%rsp), %rax
cmpq %rax, 0x28(%r12)
je 0x5a06
movb 0x1(%r15), %al
andb $-0x41, %al
jmp 0x5a0c
movb 0x1(%r15), %al
orb $0x40, %al
movb %al, 0x1(%r15)
testb %r14b, %r14b
je 0x5a3f
movl 0x8(%r15), %edi
leaq 0x10(%rsp), %rbp
movq %rbp, %rsi
movl $0x10, %edx
callq 0xbbac
movb 0x1(%r15), %al
leaq 0xac1d(%rip), %rcx      # 0x10653
leaq 0xabbd(%rip), %rdx      # 0x105fa
jmp 0x5a63
cmpb $0x0, 0xc(%r12)
leaq 0xaba2(%rip), %rdx      # 0x105ee
leaq 0xaba7(%rip), %rcx      # 0x105fa
cmoveq %rcx, %rdx
leaq 0x9970(%rip), %rcx      # 0xf3ce
leaq 0x10(%rsp), %rbp
movzwl 0x4(%r15), %esi
rolw $0x8, %si
movzwl %si, %r9d
movzbl 0x10(%r15), %r10d
movzbl 0x2(%r15), %r11d
testb $0x40, %al
leaq 0xd780(%rip), %r15      # 0x13203
leaq 0xabd5(%rip), %rax      # 0x1065f
cmoveq %rax, %r15
movl $0x4, %edi
leaq 0xab6b(%rip), %rsi      # 0x10605
movq %rbp, %r8
xorl %eax, %eax
movq (%rsp), %rbp
pushq 0x8(%rbp)
pushq %r15
pushq %r11
pushq %r10
callq 0xd88c
addq $0x20, %rsp
movzbl (%r13), %eax
leal (%rax,%rax,4), %eax
addl %ebx, %eax
addl $0x12, %eax
movq 0x10(%r12), %rdi
movswq %ax, %rbx
leaq 0x12(%rbx), %rcx
movzwl 0x18(%r12), %eax
movzwl %ax, %edx
cmpq %rdx, %rcx
ja 0x5b0f
movzbl 0x11(%rdi,%rbx), %esi
leaq (%rsi,%rsi,4), %rsi
addq %rcx, %rsi
cmpq %rdx, %rsi
ja 0x5b0f
leaq (%rdi,%rbx), %r15
incb %r14b
leaq (%rdi,%rbx), %r13
addq $0x11, %r13
cmpq $0x200, %rsi            # imm = 0x200
jbe 0x59e5
jmp 0x5b0f
movq %r15, %rdi
movzwl %ax, %esi
movq (%rsp), %rbx
leaq 0x40(%rbx), %rdx
movl 0x10(%rbx), %ecx
movq %rbx, %r8
callq 0xbe54
testb %al, %al
jns 0x5b31
movq %rbx, %rdi
callq 0xadf9
movq (%rbx), %rbx
cmpq 0x114a5(%rip), %rbx     # 0x16fe0
jne 0x59a3
leaq 0x117f0(%rip), %rbx     # 0x17338
movq %rbx, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x5be3
cmpb $0x0, 0xc(%r12)
je 0x5b6d
movq 0x28(%r12), %rdi
testq %rdi, %rdi
je 0x5b6d
callq 0x5338
movq 0x10(%r12), %rdi
movl $0x5dd, %esi            # imm = 0x5DD
callq 0x628b
movq %r12, %rdi
movl $0x5de, %esi            # imm = 0x5DE
callq 0x628b
movq 0x20(%rsp), %r12
cmpq %rbx, %r12
leaq 0x10(%rsp), %r14
jne 0x588f
movl $0x8, %edi
callq 0x6bd8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)