// File: /workspace/github_c_makefile_star2_O2/LPD-EPFL[P]mctop/src/mctop_topology.c
// Function: mctop_print
void
mctop_print(mctop_t* topo)
{
#define PD_0 "|||||||||"
#define PD_1 "||||||"
#define PD_2 "|||"

  printf(PD_0" MCTOP Topology   / #HW contexts: %u / #Sockets: %u / Socket ref.: %u-xxxx / SMT: %d \n", 
	 topo->n_hwcs, topo->n_sockets, topo->socket_level, topo->is_smt);
  if (topo->cache)
    {
      printf(PD_0" #Cache lvls: %u\n", topo->cache->n_levels - 1);
      for (int i = 1; i < topo->cache->n_levels; i++)
	{
	  printf(PD_1" Level %u / Latency: %-4zu / Size:    OS: %5zu KB     Estimated: %5zu KB\n",
		 i, topo->cache->latencies[i], topo->cache->sizes_OS[i], topo->cache->sizes_estimated[i]);
	}
    }
  if (topo->pow_info)
    {
      mctop_pow_info_t* pi = topo->pow_info;
      printf(PD_0" Power info (Watt)   %-10s %-10s %-10s %-10s %-10s\n", "Cores", "Rest", "Package", "DRAM", "Total");
      printf(PD_1" %-22s "P5DOUBLE"\n", "idle", G5DOUBLE(pi->idle));
      printf(PD_1" %-22s "P5DOUBLE"\n", "1st core cost", G5DOUBLE(pi->first_core));
      printf(PD_1" %-22s "P5DOUBLE"\n", "2nd core cost", G5DOUBLE(pi->second_core));
      printf(PD_1" %-22s "P5DOUBLE"\n", "2nd hw ctx cost", G5DOUBLE(pi->second_hwc_core));
      printf(PD_1" %-22s "P5DOUBLE"\n", "all cores", G5DOUBLE(pi->all_cores));
      printf(PD_1" %-22s "P5DOUBLE"\n", "all hw ctxs", G5DOUBLE(pi->all_hwcs));
    }
  printf(PD_0" #Latency lvls: %u / Latencies: ", topo->n_levels);
  for (int i = 0; i < topo->n_levels; i++)
    {
      printf("%-u ", topo->latencies[i]);
    }
  printf("\n");

  /* hwc level */
  int l = 0;
  printf(PD_1" Level %u / Latency: %-4u / Ref level: %u / Type: %s\n",
	 l, topo->latencies[l], l, mctop_get_type_desc(topo->hwcs[0].type));
  printf(PD_2" Hardware contexts: \n");
  printf(PD_2" ");
  for (int i = 0; i < topo->n_hwcs; i++)
    {
      printf("%-4u ", topo->hwcs[i].id);
      if ((i != (topo->n_hwcs - 1)) && ((i + 1) & 15) == 0)
	{
	  printf("\n"PD_2" ");
	}
    }
  printf("\n");

  for (int l = 1; l <= topo->socket_level; l++)
    {
      hwc_gs_t* gs = mctop_get_first_gs_at_lvl(topo, l);
      printf(PD_1" Level %u / Latency: %-4u / Ref level: %u / Type: %s\n",
	     l, topo->latencies[l], l - 1, mctop_get_type_desc(gs->type));
      printf(PD_2" ID       Members\n");
      while (gs != NULL)
	{
	  printf(PD_2" " MCTOP_ID_PRINTER "   ", MCTOP_ID_PRINT(gs->id));
	  for (int i = 0; i < gs->n_children; i++)
	    {
	      printf(MCTOP_ID_PRINTER "  ", MCTOP_ID_PRINT(gs->children[i]->id));
	      if ((i != (gs->n_children - 1)) && ((i + 1) % 10) == 0)
		{
		  printf("\n"PD_2"          ");
		}
	    }
	  printf("\n");
	  gs = gs->next;
	}

      /* mem. latencies */
      if (topo->has_mem && l == topo->socket_level)
	{
	  printf(PD_2"          Memory latencies (cycles)\n");
	  hwc_gs_t* gs = mctop_get_first_gs_at_lvl(topo, l);
	  while (gs != NULL)
	    {
	      printf(PD_2" " MCTOP_ID_PRINTER "   ", MCTOP_ID_PRINT(gs->id));
	      for (int n = 0; n < gs->n_nodes; n++)
		{
		  printf("%6u%s ", gs->mem_latencies[n], (gs->local_node == n) ? "*" : " ");
		}
	      printf("\n");
	      gs = gs->next;
	    }
	}

      /* mem. bandwidht */
      if (topo->has_mem == BANDWIDTH && l == topo->socket_level)
	{
	  printf(PD_2"          Memory bandwidths (Read / Write) - max (GB/s)\n");
	  hwc_gs_t* gs = mctop_get_first_gs_at_lvl(topo, l);
	  while (gs != NULL)
	    {
	      printf(PD_2" " MCTOP_ID_PRINTER "   ", MCTOP_ID_PRINT(gs->id));
	      for (int n = 0; n < gs->n_nodes; n++)
		{
		  printf("%6.2f /%6.2f%s ",
			 gs->mem_bandwidths_r[n], gs->mem_bandwidths_w[n], (gs->local_node == n) ? "*" : " ");
		}
	      printf("\n");
	      gs = gs->next;
	    }

	  printf(PD_2"          Memory bandwidths (Read / Write) - single thread (GB/s)\n");
	  gs = mctop_get_first_gs_at_lvl(topo, l);
	  while (gs != NULL)
	    {
	      printf(PD_2" " MCTOP_ID_PRINTER "   ", MCTOP_ID_PRINT(gs->id));
	      for (int n = 0; n < gs->n_nodes; n++)
		{
		  printf("%6.2f /%6.2f%s ",
			 gs->mem_bandwidths1_r[n], gs->mem_bandwidths1_w[n], (gs->local_node == n) ? "*" : " ");
		}
	      printf("\n");
	      gs = gs->next;
	    }
	}
    }

  /* siblings */
  for (int l = topo->socket_level + 1; l < topo->n_levels; l++)
    {
      printf(PD_1" Level %u / Latency: %-4u / Ref level: %u / Type: %s\n",
	     l, topo->latencies[l], topo->socket_level, mctop_get_type_desc(CROSS_SOCKET));
      printf(PD_2" ID       Members\n");
      sibling_t* sibling = mctop_get_first_sibling_lvl(topo, l);
      while (sibling != NULL)
	{
	  printf(PD_2" "MCTOP_ID_PRINTER"   "MCTOP_ID_PRINTER"  "MCTOP_ID_PRINTER"\n", 
		 MCTOP_ID_PRINT(sibling->id), MCTOP_ID_PRINT(sibling->left->id), MCTOP_ID_PRINT(sibling->right->id));
	  sibling = sibling->next;
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r13
movl 0x18(%rdi), %edx
movl 0x10(%rdi), %esi
movl 0x14(%rdi), %ecx
movl 0x28(%rdi), %r8d
leaq 0x4994(%rip), %rdi      # 0xbb71
xorl %eax, %eax
callq 0x2100
movq 0x58(%r13), %rax
testq %rax, %rax
je 0x723d
pushq $0x1
popq %rbx
movl (%rax), %esi
decl %esi
leaq 0x49d6(%rip), %rdi      # 0xbbd1
xorl %eax, %eax
callq 0x2100
leaq 0x49e3(%rip), %r14      # 0xbbec
movq 0x58(%r13), %rax
movl (%rax), %ecx
cmpq %rcx, %rbx
jae 0x723d
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rsi
movq (%rcx,%rbx,8), %rdx
movq (%rsi,%rbx,8), %rcx
movq 0x18(%rax), %rax
movq (%rax,%rbx,8), %r8
movq %r14, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x2100
incq %rbx
jmp 0x7209
movq 0x80(%r13), %r14
testq %r14, %r14
je 0x73ce
leaq 0x49e8(%rip), %rdi      # 0xbc3c
leaq 0x4a1e(%rip), %rsi      # 0xbc79
leaq 0x4a1d(%rip), %rdx      # 0xbc7f
leaq 0x4a1b(%rip), %rcx      # 0xbc84
leaq 0x4a1c(%rip), %r8       # 0xbc8c
leaq 0x4a1a(%rip), %r9       # 0xbc91
xorl %eax, %eax
callq 0x2100
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
movsd 0x18(%r14), %xmm3
movsd 0x20(%r14), %xmm4
leaq 0x49f5(%rip), %rbx      # 0xbc97
leaq 0x4a25(%rip), %rsi      # 0xbcce
movq %rbx, %rdi
movb $0x5, %al
callq 0x2100
movsd 0x30(%r14), %xmm0
movsd 0x38(%r14), %xmm1
movsd 0x40(%r14), %xmm2
movsd 0x48(%r14), %xmm3
movsd 0x50(%r14), %xmm4
leaq 0x49fb(%rip), %rsi      # 0xbcd3
movq %rbx, %rdi
movb $0x5, %al
callq 0x2100
movsd 0x60(%r14), %xmm0
movsd 0x68(%r14), %xmm1
movsd 0x70(%r14), %xmm2
movsd 0x78(%r14), %xmm3
movsd 0x80(%r14), %xmm4
leaq 0x49d7(%rip), %rsi      # 0xbce1
movq %rbx, %rdi
movb $0x5, %al
callq 0x2100
movsd 0x90(%r14), %xmm0
movsd 0x98(%r14), %xmm1
movsd 0xa0(%r14), %xmm2
movsd 0xa8(%r14), %xmm3
movsd 0xb0(%r14), %xmm4
leaq 0x49a7(%rip), %rsi      # 0xbcef
movq %rbx, %rdi
movb $0x5, %al
callq 0x2100
movsd 0xc0(%r14), %xmm0
movsd 0xc8(%r14), %xmm1
movsd 0xd0(%r14), %xmm2
movsd 0xd8(%r14), %xmm3
movsd 0xe0(%r14), %xmm4
leaq 0x4979(%rip), %rsi      # 0xbcff
movq %rbx, %rdi
movb $0x5, %al
callq 0x2100
movsd 0xf0(%r14), %xmm0
movsd 0xf8(%r14), %xmm1
movsd 0x100(%r14), %xmm2
movsd 0x108(%r14), %xmm3
movsd 0x110(%r14), %xmm4
leaq 0x4945(%rip), %rsi      # 0xbd09
movq %rbx, %rdi
movb $0x5, %al
callq 0x2100
movl (%r13), %esi
leaq 0x493c(%rip), %rdi      # 0xbd15
xorl %eax, %eax
callq 0x2100
leaq 0x4958(%rip), %rbx      # 0xbd3f
xorl %r14d, %r14d
movl (%r13), %eax
cmpq %rax, %r14
jae 0x740a
movq 0x8(%r13), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2100
incq %r14
jmp 0x73ea
pushq $0xa
popq %rdi
callq 0x2040
movq 0x8(%r13), %rax
movq 0x40(%r13), %rcx
movl (%rax), %edx
movl 0x8(%rcx), %eax
leaq 0x896a(%rip), %rcx      # 0xfd90
movq (%rcx,%rax,8), %r8
leaq 0x4913(%rip), %rdi      # 0xbd44
xorl %esi, %esi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x2100
leaq 0x4a2c(%rip), %rdi      # 0xbe6f
callq 0x2080
leaq 0x4938(%rip), %rdi      # 0xbd87
leaq 0x492a(%rip), %rbx      # 0xbd80
leaq 0x4929(%rip), %r14      # 0xbd86
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x2100
imulq $0x30, %r15, %r12
movl 0x10(%r13), %eax
cmpq %rax, %r15
jae 0x74a9
movq 0x40(%r13), %rax
movl (%rax,%r12), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2100
movl 0x10(%r13), %eax
decl %eax
cmpq %rax, %r15
setne %al
incq %r15
testb $0xf, %r15b
sete %cl
addq $0x30, %r12
testb %cl, %al
je 0x746b
movq %r14, %rdi
jmp 0x7460
pushq $0xa
popq %rdi
callq 0x2040
pushq $0x1
popq %r15
movl $0x2710, %r14d          # imm = 0x2710
leaq 0x48f9(%rip), %r12      # 0xbdbb
leaq 0x48e9(%rip), %rbp      # 0xbdb2
movq %r13, 0x10(%rsp)
movq %r13, %rbx
movl 0x14(%r13), %r13d
cmpq %r13, %r15
ja 0x77a8
movq %rbx, %rdi
movl %r15d, %esi
callq 0x7efa
movq %rax, %r13
movq 0x8(%rbx), %rax
movl (%rax,%r15,4), %edx
leal -0x1(%r15), %ecx
movl 0x8(%r13), %eax
leaq 0x888d(%rip), %rsi      # 0xfd90
movq (%rsi,%rax,8), %r8
leaq 0x4836(%rip), %rdi      # 0xbd44
movq %r15, 0x8(%rsp)
movl %r15d, %esi
xorl %eax, %eax
callq 0x2100
leaq 0x4963(%rip), %rdi      # 0xbe87
callq 0x2080
testq %r13, %r13
je 0x75d3
movl (%r13), %eax
xorl %edx, %edx
divl %r14d
leaq 0x484a(%rip), %rdi      # 0xbd8c
movl %eax, %esi
xorl %eax, %eax
callq 0x2100
pushq $0x1
popq %r15
pushq $-0x1
popq %rbp
xorl %ebx, %ebx
movl %r15d, %eax
xorl %edx, %edx
pushq $0xa
popq %rcx
divl %ecx
movl %eax, %r12d
movl 0x3c(%r13), %eax
cmpq %rax, %rbx
jae 0x75b4
movq 0x40(%r13), %rax
movq (%rax,%rbx,8), %rax
movl (%rax), %eax
xorl %edx, %edx
divl %r14d
leaq 0x481b(%rip), %rdi      # 0xbd9b
movl %eax, %esi
xorl %eax, %eax
callq 0x2100
movl 0x3c(%r13), %eax
decl %eax
cmpq %rax, %rbx
je 0x75aa
imull $0xa, %r12d, %eax
addl %ebp, %eax
jne 0x75aa
leaq 0x4802(%rip), %rdi      # 0xbda5
xorl %eax, %eax
callq 0x2100
decl %ebp
incl %r15d
incq %rbx
jmp 0x7554
pushq $0xa
popq %rdi
callq 0x2040
movq 0x20(%r13), %r13
leaq 0x47f4(%rip), %r12      # 0xbdbb
leaq 0x47e4(%rip), %rbp      # 0xbdb2
jmp 0x7529
movq 0x10(%rsp), %r13
movl 0x30(%r13), %eax
testl %eax, %eax
je 0x779b
movl 0x14(%r13), %ecx
cmpq %rcx, 0x8(%rsp)
jne 0x766d
leaq 0x48a6(%rip), %rdi      # 0xbe9c
callq 0x2080
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x7efa
movq %rax, %r15
testq %r15, %r15
je 0x7669
movl (%r15), %eax
xorl %edx, %edx
divl %r14d
leaq 0x476d(%rip), %rdi      # 0xbd8c
movl %eax, %esi
xorl %eax, %eax
callq 0x2100
xorl %ebx, %ebx
movl 0x70(%r15), %eax
cmpq %rax, %rbx
jae 0x765b
movq 0x78(%r15), %rax
movl (%rax,%rbx,4), %esi
movl 0x6c(%r15), %eax
cmpq %rax, %rbx
movq %rbp, %rdx
cmoveq %r12, %rdx
leaq 0x4765(%rip), %rdi      # 0xbdb4
xorl %eax, %eax
callq 0x2100
incq %rbx
jmp 0x762a
pushq $0xa
popq %rdi
callq 0x2040
movq 0x20(%r15), %r15
jmp 0x760b
movl 0x30(%r13), %eax
cmpl $0x2, %eax
jne 0x779b
movl 0x14(%r13), %eax
cmpq %rax, 0x8(%rsp)
jne 0x779b
leaq 0x4837(%rip), %rdi      # 0xbec3
callq 0x2080
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x7efa
movq %rax, %r15
testq %r15, %r15
je 0x7710
movl (%r15), %eax
xorl %edx, %edx
divl %r14d
leaq 0x46d7(%rip), %rdi      # 0xbd8c
movl %eax, %esi
xorl %eax, %eax
callq 0x2100
xorl %ebx, %ebx
movl 0x70(%r15), %eax
cmpq %rax, %rbx
jae 0x7702
movq 0x80(%r15), %rax
movsd (%rax,%rbx,8), %xmm0
movq 0x90(%r15), %rax
movsd (%rax,%rbx,8), %xmm1
movl 0x6c(%r15), %eax
cmpq %rax, %rbx
movq %rbp, %rsi
cmoveq %r12, %rsi
leaq 0x46c7(%rip), %rdi      # 0xbdbd
movb $0x2, %al
callq 0x2100
incq %rbx
jmp 0x76c0
pushq $0xa
popq %rdi
callq 0x2040
movq 0x20(%r15), %r15
jmp 0x76a1
leaq 0x47e7(%rip), %rdi      # 0xbefe
callq 0x2080
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x7efa
movq %rax, %r15
testq %r15, %r15
je 0x779b
movl (%r15), %eax
xorl %edx, %edx
divl %r14d
leaq 0x464c(%rip), %rdi      # 0xbd8c
movl %eax, %esi
xorl %eax, %eax
callq 0x2100
xorl %ebx, %ebx
movl 0x70(%r15), %eax
cmpq %rax, %rbx
jae 0x778d
movq 0x88(%r15), %rax
movsd (%rax,%rbx,8), %xmm0
movq 0x98(%r15), %rax
movsd (%rax,%rbx,8), %xmm1
movl 0x6c(%r15), %eax
cmpq %rax, %rbx
movq %rbp, %rsi
cmoveq %r12, %rsi
leaq 0x463c(%rip), %rdi      # 0xbdbd
movb $0x2, %al
callq 0x2100
incq %rbx
jmp 0x774b
pushq $0xa
popq %rdi
callq 0x2040
movq 0x20(%r15), %r15
jmp 0x772c
movq 0x8(%rsp), %r15
incq %r15
jmp 0x74ce
leaq 0x46b3(%rip), %r14      # 0xbe62
leaq 0x46d1(%rip), %r15      # 0xbe87
movl $0x2710, %ebx           # imm = 0x2710
leaq 0x460b(%rip), %r12      # 0xbdcd
incl %r13d
movq 0x10(%rsp), %rbp
cmpl (%rbp), %r13d
jae 0x784f
movq 0x8(%rbp), %rax
movslq %r13d, %rcx
movl (%rax,%rcx,4), %edx
movl 0x14(%rbp), %ecx
leaq 0x4560(%rip), %rdi      # 0xbd44
movl %r13d, %esi
movq %r14, %r8
xorl %eax, %eax
callq 0x2100
movq %r15, %rdi
callq 0x2080
movq %rbp, %rdi
movl %r13d, %esi
callq 0x7f12
movq %rax, %rbp
testq %rbp, %rbp
je 0x77c2
movl (%rbp), %eax
xorl %edx, %edx
divl %ebx
movl %eax, %esi
movl %edx, %ecx
movq 0x10(%rbp), %rax
movl (%rax), %eax
xorl %edx, %edx
divl %ebx
movl %eax, %r8d
movl %edx, %r9d
movq 0x18(%rbp), %rax
movl (%rax), %eax
xorl %edx, %edx
divl %ebx
movl %edx, (%rsp)
movq %r12, %rdi
movl %ecx, %edx
movl %r8d, %ecx
movl %r9d, %r8d
movl %eax, %r9d
xorl %eax, %eax
callq 0x2100
movq 0x20(%rbp), %rbp
jmp 0x7807
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq