// File: /workspace/github_c_makefile_star2_O2/open-mesh-mirror[P]batmand/originator.c
// Function: debug_orig
void debug_orig(void) {

	struct hash_it_t *hashit = NULL;
	struct list_head *forw_pos, *orig_pos, *neigh_pos;
	struct forw_node *forw_node;
	struct orig_node *orig_node;
	struct neigh_node *neigh_node;
	struct gw_node *gw_node;
	uint16_t batman_count = 0;
	uint64_t uptime_sec;
	int download_speed, upload_speed, debug_out_size;
	char str[ADDR_STR_LEN], str2[ADDR_STR_LEN], orig_str[ADDR_STR_LEN], debug_out_str[1001];


	if ( debug_clients.clients_num[1] > 0 ) {

		addr_to_string( ((struct batman_if *)if_list.next)->addr.sin_addr.s_addr, orig_str, sizeof(orig_str) );
		uptime_sec = (uint64_t)(get_time_msec64() / 1000);

		debug_output(2, "BOD\n");
		debug_output(2, "%12s     (%s/%i) %15s [%10s], gw_class ... [B.A.T.M.A.N. %s, MainIF/IP: %s/%s, UT: %id%2ih%2im] \n", "Gateway", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF", SOURCE_VERSION, ((struct batman_if *)if_list.next)->dev, orig_str, (uint32_t)(uptime_sec/86400), (uint32_t)((uptime_sec%86400)/3600), (uint32_t)((uptime_sec%3600)/60));

		if ( list_empty( &gw_list ) ) {

			debug_output( 2, "No gateways in range ... \n" );

		} else {

			list_for_each( orig_pos, &gw_list ) {

				gw_node = list_entry( orig_pos, struct gw_node, list );

				if ( gw_node->deleted )
					continue;

				if (gw_node->orig_node->router == NULL)
					continue;

				addr_to_string( gw_node->orig_node->orig, str, sizeof (str) );
				addr_to_string( gw_node->orig_node->router->addr, str2, sizeof (str2) );

				get_gw_speeds( gw_node->orig_node->gwflags, &download_speed, &upload_speed );

				debug_output(2, "%s %-15s (%3i) %15s [%10s], gw_class %3i - %i%s/%i%s, gateway failures: %i \n", ( curr_gateway == gw_node ? "=>" : "  " ), str, gw_node->orig_node->router->tq_avg, str2, gw_node->orig_node->router->if_incoming->dev, gw_node->orig_node->gwflags, (download_speed > 2048 ? download_speed / 1024 : download_speed), (download_speed > 2048 ? "MBit" : "KBit"), (upload_speed > 2048 ? upload_speed / 1024 : upload_speed), (upload_speed > 2048 ? "MBit" : "KBit"), gw_node->gw_failure);

				batman_count++;

			}

			if ( batman_count == 0 )
				debug_output( 2, "No gateways in range ... \n" );

		}

		debug_output( 2, "EOD\n" );

	}

	if ( ( debug_clients.clients_num[0] > 0 ) || ( debug_clients.clients_num[3] > 0 ) ) {

		addr_to_string( ((struct batman_if *)if_list.next)->addr.sin_addr.s_addr, orig_str, sizeof(orig_str) );
		uptime_sec = (uint64_t)(get_time_msec64() / 1000);

		debug_output(1, "BOD \n");
		debug_output(1, "  %-11s (%s/%i) %15s [%10s]: %20s ... [B.A.T.M.A.N. %s, MainIF/IP: %s/%s, UT: %id%2ih%2im] \n", "Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF", "Potential nexthops", SOURCE_VERSION, ((struct batman_if *)if_list.next)->dev, orig_str, (uint32_t)(uptime_sec/86400), (uint32_t)((uptime_sec%86400)/3600), (uint32_t)((uptime_sec%3600)/60));

		if ( debug_clients.clients_num[3] > 0 ) {

			debug_output( 4, "------------------ DEBUG ------------------ \n" );
			debug_output( 4, "Forward list \n" );

			list_for_each( forw_pos, &forw_list ) {
				forw_node = list_entry( forw_pos, struct forw_node, list );
				addr_to_string( ((struct bat_packet *)forw_node->pack_buff)->orig, str, sizeof(str) );
				debug_output( 4, "    %s at %u \n", str, forw_node->send_time );
			}

			debug_output( 4, "Originator list \n" );
			debug_output( 4, "  %-11s (%s/%i) %15s [%10s]: %20s\n", "Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF", "Potential nexthops" );

		}

		while ( NULL != ( hashit = hash_iterate( orig_hash, hashit ) ) ) {

			orig_node = hashit->bucket->data;

			if ( orig_node->router == NULL )
				continue;

			batman_count++;

			addr_to_string( orig_node->orig, str, sizeof (str) );
			addr_to_string( orig_node->router->addr, str2, sizeof (str2) );

			debug_output( 1, "%-15s (%3i) %15s [%10s]:", str, orig_node->router->tq_avg, str2, orig_node->router->if_incoming->dev );
			debug_output( 4, "%15s (%3i) %15s [%10s], last_valid: %u: \n", str, orig_node->router->tq_avg, str2, orig_node->router->if_incoming->dev, orig_node->last_valid );

			debug_out_size = 0;

			list_for_each( neigh_pos, &orig_node->neigh_list ) {

				neigh_node = list_entry( neigh_pos, struct neigh_node, list );

				addr_to_string( neigh_node->addr, str, sizeof (str) );

				debug_out_size = debug_out_size + snprintf( ( debug_out_str + debug_out_size ), ( sizeof(debug_out_str) - 1 - debug_out_size ), " %15s (%3i)", str, neigh_node->tq_avg);

				if ( (unsigned int)(debug_out_size + 30) > sizeof(debug_out_str) - 1 ) {

					debug_output( 1, "%s \n", debug_out_str );
					debug_output( 4, "%s \n", debug_out_str );

					debug_out_size = 0;

				}

			}

			if (debug_out_size > 0) {
				debug_output( 1, "%s \n", debug_out_str );
				debug_output( 4, "%s \n", debug_out_str );
			}

		}

		if ( batman_count == 0 ) {

			debug_output( 1, "No batman nodes in range ... \n" );
			debug_output( 4, "No batman nodes in range ... \n" );

		}

		debug_output( 1, "EOD\n" );
		debug_output( 4, "---------------------------------------------- END DEBUG \n" );

	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
leaq 0x12a52(%rip), %rax     # 0x17348
movq 0x8(%rax), %rax
cmpw $0x0, 0x2(%rax)
jle 0x4a1e
leaq 0x12a04(%rip), %r12     # 0x17310
movq (%r12), %rax
movl 0x34(%rax), %edi
leaq 0x30(%rsp), %rbx
pushq $0x10
popq %rdx
movq %rbx, %rsi
callq 0xb04f
callq 0xaa72
movq %rax, %r15
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movq %rax, %r14
leaq 0xa8bf(%rip), %rsi      # 0xf1fe
pushq $0x2
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0xcb1c
movq (%r12), %rax
movq 0x8(%rax), %r12
movl $0x5265c00, %ecx        # imm = 0x5265C00
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r10
movl $0x15180, %ecx          # imm = 0x15180
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rax
movl $0xe10, %ecx            # imm = 0xE10
xorl %edx, %edx
divl %ecx
movl %eax, %r11d
movl $0xe10, %ecx            # imm = 0xE10
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rax
movw $0x3c, %cx
xorl %edx, %edx
divw %cx
movzwl %ax, %r14d
subq $0x8, %rsp
leaq 0xa8db(%rip), %r15      # 0xf282
leaq 0xa8c9(%rip), %r13      # 0xf277
leaq 0xa84e(%rip), %rsi      # 0xf203
leaq 0xa8a9(%rip), %rdx      # 0xf265
leaq 0xa8aa(%rip), %rcx      # 0xf26d
leaq 0xa8a5(%rip), %r9       # 0xf26f
movl %ebp, %edi
movl $0xff, %r8d
movl $0x0, %eax
pushq %r14
pushq %r11
pushq %r10
pushq %rbx
pushq %r12
pushq %r15
pushq %r13
callq 0xcb1c
addq $0x40, %rsp
leaq 0x1292c(%rip), %rbx     # 0x17320
movq %rbx, %rdi
callq 0x5778
testl %eax, %eax
je 0x4a2b
leaq 0xa88d(%rip), %rsi      # 0xf294
movl $0x0, 0x4(%rsp)
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0xcb1c
jmp 0x4b88
movl $0x0, 0x4(%rsp)
jmp 0x4ba4
leaq 0x10(%rsp), %rsi
pushq $0x10
popq %rbp
leaq 0x40(%rsp), %r14
leaq 0x8(%rsp), %r15
leaq 0xc(%rsp), %r13
movq %rbx, %r12
movl $0x0, 0x4(%rsp)
movq (%r12), %r12
cmpq %rbx, %r12
je 0x4b7c
cmpl $0x0, 0x18(%r12)
jne 0x4a4d
movq 0x8(%r12), %rax
cmpq $0x0, 0x8(%rax)
je 0x4a4d
movl (%rax), %edi
movl %ebp, %edx
callq 0xb04f
movq 0x8(%r12), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %edi
movq %r14, %rsi
movl %ebp, %edx
callq 0xb04f
movq 0x8(%r12), %rax
movzbl 0x34(%rax), %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2ef8
leaq 0x12818(%rip), %rax     # 0x172c0
cmpq %r12, (%rax)
leaq 0xc976(%rip), %rdx      # 0x11428
leaq 0xa843(%rip), %rax      # 0xf2fc
cmoveq %rax, %rdx
movq 0x8(%r12), %rax
movq 0x8(%rax), %rcx
movzbl 0x19(%rcx), %r8d
movq 0x30(%rcx), %rcx
movq %rcx, 0x28(%rsp)
movzbl 0x34(%rax), %eax
movq %rax, 0x20(%rsp)
movl 0x8(%rsp), %eax
movl %eax, %r15d
shrl $0xa, %r15d
movl $0x801, %ecx            # imm = 0x801
cmpl %ecx, %eax
cmovll %eax, %r15d
leaq 0xa089(%rip), %rdi      # 0xeb83
movq %rdi, %rbp
leaq 0xa07a(%rip), %rsi      # 0xeb7e
cmovgeq %rsi, %rbp
movl 0xc(%rsp), %eax
movq %r14, %r9
movl %eax, %r14d
shrl $0xa, %r14d
cmpl %ecx, %eax
cmovll %eax, %r14d
movq %r13, %r11
movq %rdi, %r13
cmovgeq %rsi, %r13
movzwl 0x12(%r12), %r10d
subq $0x8, %rsp
pushq $0x2
popq %rdi
leaq 0xa775(%rip), %rsi      # 0xf2af
leaq 0x18(%rsp), %rcx
xorl %eax, %eax
pushq %r10
pushq %r13
movq %r11, %r13
pushq %r14
movq %r9, %r14
pushq %rbp
pushq $0x10
popq %rbp
pushq %r15
leaq 0x38(%rsp), %r15
pushq 0x50(%rsp)
movq 0x60(%rsp), %r10
pushq 0x8(%r10)
callq 0xcb1c
leaq 0x50(%rsp), %rsi
addq $0x40, %rsp
incl 0x4(%rsp)
jmp 0x4a4d
cmpw $0x0, 0x4(%rsp)
je 0x4a00
leaq 0xd66c(%rip), %rsi      # 0x121fb
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0xcb1c
leaq 0x127a8(%rip), %rax     # 0x17348
movq 0x8(%rax), %rax
cmpw $0x0, (%rax)
jg 0x4bb5
cmpw $0x0, 0x6(%rax)
jle 0x4f60
leaq 0x12754(%rip), %r12     # 0x17310
movq (%r12), %rax
movl 0x34(%rax), %edi
leaq 0x30(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0xb04f
callq 0xaa72
movq %rax, %r15
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movq %rax, %r14
leaq 0xa713(%rip), %rsi      # 0xf2ff
pushq $0x1
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0xcb1c
movq (%r12), %rax
movq 0x8(%rax), %r13
movl $0x5265c00, %ecx        # imm = 0x5265C00
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r10
movl $0x15180, %ecx          # imm = 0x15180
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rax
movl $0xe10, %ecx            # imm = 0xE10
xorl %edx, %edx
divl %ecx
movl %eax, %r11d
movl $0xe10, %ecx            # imm = 0xE10
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rax
movw $0x3c, %cx
xorl %edx, %edx
divw %cx
movzwl %ax, %r14d
leaq 0xa632(%rip), %r15      # 0xf282
leaq 0xa716(%rip), %rbx      # 0xf36d
leaq 0xa619(%rip), %r12      # 0xf277
leaq 0xa6a0(%rip), %rsi      # 0xf305
leaq 0xa6f6(%rip), %rdx      # 0xf362
leaq 0xa5fa(%rip), %rcx      # 0xf26d
leaq 0xa5f5(%rip), %r9       # 0xf26f
movl %ebp, %edi
movl $0xff, %r8d
movl $0x0, %eax
pushq %r14
pushq %r11
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
pushq %r13
pushq %r15
pushq %rbx
pushq %r12
callq 0xcb1c
addq $0x40, %rsp
leaq 0x1269d(%rip), %rax     # 0x17348
movq 0x8(%rax), %rax
cmpw $0x0, 0x6(%rax)
jle 0x4d77
leaq 0xa6bf(%rip), %rsi      # 0xf380
pushq $0x4
popq %rbx
movl %ebx, %edi
xorl %eax, %eax
callq 0xcb1c
leaq 0xa6da(%rip), %rsi      # 0xf3ae
movl %ebx, %edi
xorl %eax, %eax
callq 0xcb1c
leaq 0x12654(%rip), %r12     # 0x17338
leaq 0x10(%rsp), %r14
pushq $0x10
popq %rbp
leaq 0xa6ca(%rip), %r15      # 0xf3bd
movq %r12, %r13
movq (%r13), %r13
cmpq %r12, %r13
je 0x4d25
movq 0x10(%r13), %rax
movl 0x8(%rax), %edi
movq %r14, %rsi
movl %ebp, %edx
callq 0xb04f
movl 0x8(%r13), %ecx
movl %ebx, %edi
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcb1c
jmp 0x4cf6
leaq 0xa6a0(%rip), %rsi      # 0xf3cc
pushq $0x4
popq %rbx
movl %ebx, %edi
xorl %eax, %eax
callq 0xcb1c
leaq 0xa69f(%rip), %rsi      # 0xf3de
leaq 0xa61c(%rip), %rdx      # 0xf362
leaq 0xa520(%rip), %rcx      # 0xf26d
leaq 0xa51b(%rip), %r9       # 0xf26f
movl %ebx, %edi
movl $0xff, %r8d
xorl %eax, %eax
leaq 0xa608(%rip), %r10      # 0xf36d
pushq %r10
leaq 0xa509(%rip), %r10      # 0xf277
pushq %r10
callq 0xcb1c
popq %rax
popq %rcx
leaq 0x125b2(%rip), %r14     # 0x17330
leaq 0x10(%rsp), %rbx
leaq 0x40(%rsp), %r12
xorl %r15d, %r15d
movq (%r14), %rdi
movq %r15, %rsi
callq 0x5f8c
testq %rax, %rax
je 0x4f15
movq %rax, %r15
movq 0x8(%rax), %rax
movq (%rax), %r13
cmpq $0x0, 0x8(%r13)
je 0x4d8b
movl (%r13), %edi
movq %rbx, %rsi
pushq $0x10
popq %rbp
movl %ebp, %edx
callq 0xb04f
movq 0x8(%r13), %rax
movl 0x8(%rax), %edi
movq %r12, %rsi
movl %ebp, %edx
callq 0xb04f
movq 0x8(%r13), %rax
movzbl 0x19(%rax), %ecx
movq 0x30(%rax), %rax
movq 0x8(%rax), %r9
xorl %ebp, %ebp
pushq $0x1
popq %rdi
leaq 0xa613(%rip), %rsi      # 0xf401
movq %rbx, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0xcb1c
movq 0x8(%r13), %rax
movzbl 0x19(%rax), %ecx
movq 0x30(%rax), %rax
movq 0x8(%rax), %r9
movl 0x30(%r13), %r10d
subq $0x8, %rsp
pushq $0x4
popq %rdi
leaq 0xa5fd(%rip), %rsi      # 0xf41a
movq %rbx, %rdx
movq %r12, %r8
xorl %eax, %eax
pushq %r10
callq 0xcb1c
addq $0x10, %rsp
addq $0x48, %r13
movq %r13, %r12
movq (%r12), %r12
cmpq %r13, %r12
je 0x4ec7
movl 0x8(%r12), %edi
movq %rbx, %rsi
pushq $0x10
popq %rdx
callq 0xb04f
movslq %ebp, %r14
leaq (%rsp,%r14), %rdi
addq $0x50, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
subq %r14, %rsi
movzbl 0x19(%r12), %r8d
leaq 0xa5d0(%rip), %rdx      # 0xf444
movq %rbx, %rcx
xorl %eax, %eax
callq 0x21a0
addl %eax, %ebp
addl %r14d, %eax
addl $0xfffffc35, %eax       # imm = 0xFFFFFC35
cmpl $0xfffffc16, %eax       # imm = 0xFFFFFC16
ja 0x4e37
xorl %ebp, %ebp
pushq $0x1
popq %rdi
leaq 0xc433(%rip), %r14      # 0x112ce
movq %r14, %rsi
leaq 0x50(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0xcb1c
pushq $0x4
popq %rdi
movq %r14, %rsi
movq %rbx, %rdx
leaq 0x10(%rsp), %rbx
xorl %eax, %eax
callq 0xcb1c
jmp 0x4e37
incl 0x4(%rsp)
testl %ebp, %ebp
leaq 0x1245c(%rip), %r14     # 0x17330
leaq 0x40(%rsp), %r12
jle 0x4d8b
pushq $0x1
popq %rdi
leaq 0xc3e5(%rip), %r13      # 0x112ce
movq %r13, %rsi
leaq 0x50(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0xcb1c
pushq $0x4
popq %rdi
movq %r13, %rsi
movq %rbx, %rdx
leaq 0x10(%rsp), %rbx
xorl %eax, %eax
callq 0xcb1c
jmp 0x4d8b
cmpw $0x0, 0x4(%rsp)
jne 0x4f3e
leaq 0xa52c(%rip), %rbx      # 0xf450
pushq $0x1
popq %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0xcb1c
pushq $0x4
popq %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0xcb1c
leaq 0xd2b6(%rip), %rsi      # 0x121fb
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0xcb1c
leaq 0xa519(%rip), %rsi      # 0xf46f
pushq $0x4
popq %rdi
xorl %eax, %eax
callq 0xcb1c
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop