// File: /workspace/github_c_makefile_star2_O1/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 0x6880
leaq 0x11aba(%rip), %rax     # 0x17338
movq (%rax), %r12
cmpq %rax, %r12
je 0x5b8b
leaq 0x10(%rsp), %r14
movl 0xc(%rsp), %eax
cmpl 0x8(%r12), %eax
js 0x5b8b
movq (%r12), %r15
movq 0x10(%r12), %rbx
movl 0x8(%rbx), %edi
movq %r14, %rsi
movl $0x10, %edx
callq 0xb8b8
movq 0x28(%r12), %r10
testq %r10, %r10
movq %r15, 0x20(%rsp)
je 0x596c
testb $0x40, 0x1(%rbx)
je 0x58d6
cmpb $0x1, 0x2(%rbx)
je 0x58ed
cmpb $0x0, 0xc(%r12)
je 0x5981
cmpb $0x0, 0x1c(%r10)
je 0x5981
cmpb $0x0, 0xc(%r12)
leaq 0xacf4(%rip), %rdx      # 0x105ee
leaq 0xacf9(%rip), %rax      # 0x105fa
cmoveq %rax, %rdx
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %r8d
movzbl 0x2(%rbx), %r9d
subq $0x8, %rsp
movl $0x4, %edi
leaq 0xac8b(%rip), %rsi      # 0x105b1
movq %r14, %rcx
xorl %eax, %eax
pushq 0x8(%r10)
callq 0xd5b0
addq $0x10, %rsp
movzwl 0x18(%r12), %esi
movq 0x10(%r12), %rdi
movq 0x28(%r12), %r8
leaq 0x40(%r8), %rdx
movl 0x10(%r8), %ecx
callq 0xbb60
testb %al, %al
jns 0x5b30
movq 0x28(%r12), %rdi
callq 0xaafa
jmp 0x5b30
xorl %edi, %edi
leaq 0xabff(%rip), %rsi      # 0x10574
xorl %eax, %eax
callq 0xd5b0
jmp 0x5b30
leaq 0x11988(%rip), %rax     # 0x17310
movq (%rax), %rbx
cmpq %rax, %rbx
je 0x5b30
movq %rbx, (%rsp)
movzwl 0x18(%r12), %eax
cmpq $0x12, %rax
jb 0x5af9
movq 0x10(%r12), %r15
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 0x5af9
leaq 0x11(%r15), %r14
xorl %ebx, %ebx
xorl %r13d, %r13d
movl 0x1c(%r12), %eax
movzbl %bl, %ecx
btl %ecx, %eax
jae 0x59ee
movq (%rsp), %rax
cmpq %rax, 0x28(%r12)
je 0x59f5
andb $-0x41, 0x1(%r15)
jmp 0x59fa
orb $0x40, 0x1(%r15)
testb %bl, %bl
je 0x5a24
movl 0x8(%r15), %edi
leaq 0x10(%rsp), %rbp
movq %rbp, %rsi
movl $0x10, %edx
callq 0xb8b8
leaq 0xac38(%rip), %rcx      # 0x10653
leaq 0xabd8(%rip), %rdx      # 0x105fa
jmp 0x5a48
cmpb $0x0, 0xc(%r12)
leaq 0xabbd(%rip), %rdx      # 0x105ee
leaq 0xabc2(%rip), %rax      # 0x105fa
cmoveq %rax, %rdx
leaq 0x998b(%rip), %rcx      # 0xf3ce
leaq 0x10(%rsp), %rbp
movzwl 0x4(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %r9d
movzbl 0x10(%r15), %r10d
testb $0x40, 0x1(%r15)
movzbl 0x2(%r15), %r11d
leaq 0xd6d8(%rip), %r15      # 0x13143
leaq 0xabed(%rip), %rax      # 0x1065f
cmoveq %rax, %r15
movl $0x4, %edi
leaq 0xab83(%rip), %rsi      # 0x10605
movq %rbp, %r8
xorl %eax, %eax
movq (%rsp), %rbp
pushq 0x8(%rbp)
pushq %r15
pushq %r11
pushq %r10
callq 0xd5b0
addq $0x20, %rsp
movzbl (%r14), %eax
leaq (%rax,%rax,4), %rax
leaq (%rax,%r13), %rdi
addq $0x12, %rdi
movswq %di, %r13
leaq 0x12(%r13), %rcx
movzwl 0x18(%r12), %eax
movzwl %ax, %esi
cmpq %rsi, %rcx
ja 0x5af9
movq 0x10(%r12), %rdx
movswq %di, %rdi
movzbl 0x11(%rdx,%rdi), %r8d
leaq (%r8,%r8,4), %r8
addq %rcx, %r8
cmpq %rsi, %r8
ja 0x5af9
leaq (%rdx,%rdi), %r15
incb %bl
leaq (%rdx,%rdi), %r14
addq $0x11, %r14
cmpq $0x200, %r8             # imm = 0x200
jbe 0x59d6
movq 0x10(%r12), %rdi
movzwl %ax, %esi
movq (%rsp), %rbx
leaq 0x40(%rbx), %rdx
movl 0x10(%rbx), %ecx
movq %rbx, %r8
callq 0xbb60
testb %al, %al
jns 0x5b20
movq %rbx, %rdi
callq 0xaafa
movq (%rbx), %rbx
cmpq 0x114b6(%rip), %rbx     # 0x16fe0
jne 0x5994
leaq 0x11801(%rip), %rbx     # 0x17338
movq %rbx, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x5bcf
cmpb $0x0, 0xc(%r12)
je 0x5b5c
movq 0x28(%r12), %rdi
testq %rdi, %rdi
je 0x5b5c
callq 0x533c
movq 0x10(%r12), %rdi
movl $0x5dd, %esi            # imm = 0x5DD
callq 0x5f5b
movq %r12, %rdi
movl $0x5de, %esi            # imm = 0x5DE
callq 0x5f5b
movq 0x20(%rsp), %r12
cmpq %rbx, %r12
leaq 0x10(%rsp), %r14
jne 0x588f
movl $0x8, %edi
callq 0x689c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq