// File: /workspace/github_c_makefile_star2_O1/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, %rbp
movl 0x18(%rdi), %edx
movl 0x10(%rdi), %esi
movl 0x14(%rdi), %ecx
movl 0x28(%rdi), %r8d
leaq 0x4e1b(%rip), %rdi      # 0xcb71
xorl %eax, %eax
callq 0x2100
movq 0x58(%rbp), %rax
testq %rax, %rax
je 0x7dbf
movl (%rax), %esi
decl %esi
leaq 0x4e60(%rip), %rdi      # 0xcbd1
xorl %eax, %eax
callq 0x2100
movq 0x58(%rbp), %rax
cmpl $0x2, (%rax)
jb 0x7dbf
movl $0x1, %ebx
leaq 0x4e5f(%rip), %r14      # 0xcbec
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
movq 0x58(%rbp), %rax
movl (%rax), %ecx
cmpq %rcx, %rbx
jb 0x7d8d
movq 0x80(%rbp), %r14
testq %r14, %r14
je 0x7f50
leaq 0x4e66(%rip), %rdi      # 0xcc3c
leaq 0x4e9c(%rip), %rsi      # 0xcc79
leaq 0x4e9b(%rip), %rdx      # 0xcc7f
leaq 0x4e99(%rip), %rcx      # 0xcc84
leaq 0x4e9a(%rip), %r8       # 0xcc8c
leaq 0x4e98(%rip), %r9       # 0xcc91
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 0x4e73(%rip), %rbx      # 0xcc97
leaq 0x4ea3(%rip), %rsi      # 0xccce
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 0x4e79(%rip), %rsi      # 0xccd3
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 0x4e55(%rip), %rsi      # 0xcce1
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 0x4e25(%rip), %rsi      # 0xccef
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 0x4df7(%rip), %rsi      # 0xccff
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 0x4dc3(%rip), %rsi      # 0xcd09
movq %rbx, %rdi
movb $0x5, %al
callq 0x2100
movl (%rbp), %esi
leaq 0x4dbb(%rip), %rdi      # 0xcd15
xorl %eax, %eax
callq 0x2100
cmpl $0x0, (%rbp)
je 0x7f8e
leaq 0x4dd1(%rip), %rbx      # 0xcd3f
xorl %r14d, %r14d
movq 0x8(%rbp), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2100
incq %r14
movl (%rbp), %eax
cmpq %rax, %r14
jb 0x7f71
movl $0xa, %edi
callq 0x2040
movq 0x8(%rbp), %rax
movq 0x40(%rbp), %rcx
movl (%rax), %edx
movl 0x8(%rcx), %eax
leaq 0x8de4(%rip), %rcx      # 0x10d90
movq (%rcx,%rax,8), %r8
leaq 0x4d8d(%rip), %rdi      # 0xcd44
xorl %esi, %esi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x2100
leaq 0x4ea6(%rip), %rdi      # 0xce6f
callq 0x2080
leaq 0x4db2(%rip), %rdi      # 0xcd87
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x10(%rbp)
je 0x8034
leaq 0x4d97(%rip), %rbx      # 0xcd80
leaq 0x4d96(%rip), %r14      # 0xcd86
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x40(%rbp), %rax
movl (%rax,%r15), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2100
movl 0x10(%rbp), %eax
decl %eax
cmpq %rax, %r12
je 0x8025
leal 0x1(%r12), %eax
testb $0xf, %al
jne 0x8025
movq %r14, %rdi
xorl %eax, %eax
callq 0x2100
incq %r12
movl 0x10(%rbp), %eax
addq $0x30, %r15
cmpq %rax, %r12
jb 0x7ff6
movl $0xa, %edi
callq 0x2040
movl 0x14(%rbp), %r15d
testl %r15d, %r15d
movq %rbp, 0x8(%rsp)
je 0x83e5
movl $0x1, %ebx
movl $0xd1b71759, %r13d      # imm = 0xD1B71759
leaq 0x4d52(%rip), %r12      # 0xcdb4
movq %rbp, %rdi
movl %ebx, %esi
callq 0x8c32
movq %rax, %r15
movq 0x8(%rbp), %rax
movl (%rax,%rbx,4), %edx
leal -0x1(%rbx), %ecx
movl 0x8(%r15), %eax
leaq 0x8d0c(%rip), %rsi      # 0x10d90
movq (%rsi,%rax,8), %r8
leaq 0x4cb5(%rip), %rdi      # 0xcd44
movq %rbx, 0x10(%rsp)
movl %ebx, %esi
xorl %eax, %eax
callq 0x2100
leaq 0x4de3(%rip), %rdi      # 0xce87
callq 0x2080
testq %r15, %r15
je 0x816b
movl (%r15), %edx
movq %rdx, %rsi
imulq %r13, %rsi
shrq $0x2d, %rsi
imull $0x2710, %esi, %eax     # imm = 0x2710
subl %eax, %edx
leaq 0x4cbd(%rip), %rdi      # 0xcd8c
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x3c(%r15)
je 0x8158
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x1, %ebx
xorl %r14d, %r14d
movq 0x40(%r15), %rax
movq (%rax,%r14,8), %rax
movl (%rax), %edx
movq %rdx, %rsi
imulq %r13, %rsi
shrq $0x2d, %rsi
imull $0x2710, %esi, %eax     # imm = 0x2710
subl %eax, %edx
leaq 0x4c8d(%rip), %rdi      # 0xcd9b
xorl %eax, %eax
callq 0x2100
movl 0x3c(%r15), %eax
decl %eax
cmpq %rax, %r14
je 0x8148
movl %ebx, %eax
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
imulq %rcx, %rax
shrq $0x23, %rax
leal (%rax,%rax,4), %eax
leal (%rbp,%rax,2), %eax
testl %eax, %eax
jne 0x8148
leaq 0x4c64(%rip), %rdi      # 0xcda5
xorl %eax, %eax
callq 0x2100
incq %r14
movl 0x3c(%r15), %eax
decl %ebp
incl %ebx
cmpq %rax, %r14
jb 0x80ea
movl $0xa, %edi
callq 0x2040
movq 0x20(%r15), %r15
jmp 0x80a9
movq 0x8(%rsp), %rax
cmpl $0x0, 0x30(%rax)
je 0x8229
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
cmpq %rax, 0x10(%rsp)
jne 0x8229
leaq 0x4d08(%rip), %rdi      # 0xce9c
callq 0x2080
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x8c32
testq %rax, %rax
je 0x8229
movq %rax, %r15
movl (%r15), %edx
movq %rdx, %rsi
imulq %r13, %rsi
shrq $0x2d, %rsi
imull $0x2710, %esi, %eax     # imm = 0x2710
subl %eax, %edx
leaq 0x4bbf(%rip), %rdi      # 0xcd8c
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x70(%r15)
leaq 0x4bdb(%rip), %r14      # 0xcdbb
leaq 0x4bcb(%rip), %rbp      # 0xcdb2
je 0x8216
xorl %ebx, %ebx
movq 0x78(%r15), %rax
movl (%rax,%rbx,4), %esi
movl 0x6c(%r15), %eax
cmpq %rax, %rbx
movq %rbp, %rdx
cmoveq %r14, %rdx
movq %r12, %rdi
xorl %eax, %eax
callq 0x2100
incq %rbx
movl 0x70(%r15), %eax
cmpq %rax, %rbx
jb 0x81eb
movl $0xa, %edi
callq 0x2040
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x81b0
movq 0x8(%rsp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x83c3
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
cmpq %rax, 0x10(%rsp)
jne 0x83c3
leaq 0x4c71(%rip), %rdi      # 0xcec3
callq 0x2080
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x8c32
testq %rax, %rax
je 0x8307
movq %rax, %r15
movl (%r15), %edx
movq %rdx, %rsi
imulq %r13, %rsi
shrq $0x2d, %rsi
imull $0x2710, %esi, %eax     # imm = 0x2710
subl %eax, %edx
leaq 0x4afd(%rip), %rdi      # 0xcd8c
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x70(%r15)
leaq 0x4b19(%rip), %r14      # 0xcdbb
leaq 0x4b09(%rip), %rbp      # 0xcdb2
leaq 0x4b0d(%rip), %r12      # 0xcdbd
je 0x82f0
xorl %ebx, %ebx
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 %r14, %rsi
movq %r12, %rdi
movb $0x2, %al
callq 0x2100
incq %rbx
movl 0x70(%r15), %eax
cmpq %rax, %rbx
jb 0x82b4
movl $0xa, %edi
callq 0x2040
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x8272
leaq 0x4bf0(%rip), %rdi      # 0xcefe
callq 0x2080
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x8c32
testq %rax, %rax
je 0x83c3
movq %rax, %r15
movl (%r15), %edx
movq %rdx, %rsi
imulq %r13, %rsi
shrq $0x2d, %rsi
imull $0x2710, %esi, %eax     # imm = 0x2710
subl %eax, %edx
leaq 0x4a41(%rip), %rdi      # 0xcd8c
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x70(%r15)
leaq 0x4a5d(%rip), %r14      # 0xcdbb
leaq 0x4a4d(%rip), %rbp      # 0xcdb2
leaq 0x4a51(%rip), %r12      # 0xcdbd
je 0x83ac
xorl %ebx, %ebx
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 %r14, %rsi
movq %r12, %rdi
movb $0x2, %al
callq 0x2100
incq %rbx
movl 0x70(%r15), %eax
cmpq %rax, %rbx
jb 0x8370
movl $0xa, %edi
callq 0x2040
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x832e
movq 0x10(%rsp), %rcx
leaq 0x1(%rcx), %rbx
movq 0x8(%rsp), %rbp
movl 0x14(%rbp), %r15d
cmpq %r15, %rcx
leaq 0x49d5(%rip), %r12      # 0xcdb4
jb 0x8062
incl %r15d
cmpl (%rbp), %r15d
jae 0x84ba
leaq 0x4a8e(%rip), %r14      # 0xce87
movl $0xd1b71759, %ebx       # imm = 0xD1B71759
leaq 0x49c8(%rip), %r12      # 0xcdcd
movq 0x8(%rbp), %rax
movslq %r15d, %r13
movl (%rax,%r13,4), %edx
movl 0x14(%rbp), %ecx
leaq 0x492a(%rip), %rdi      # 0xcd44
movl %r13d, %esi
leaq 0x4a3e(%rip), %r8       # 0xce62
xorl %eax, %eax
callq 0x2100
movq %r14, %rdi
callq 0x2080
movq %rbp, %rdi
movl %r13d, %esi
callq 0x8c4a
testq %rax, %rax
je 0x84a8
movq %rax, %r13
movl (%r13), %edx
movq %rdx, %rsi
imulq %rbx, %rsi
shrq $0x2d, %rsi
imull $0x2710, %esi, %eax     # imm = 0x2710
subl %eax, %edx
movq 0x10(%r13), %rax
movl (%rax), %r8d
movq %r8, %rcx
imulq %rbx, %rcx
shrq $0x2d, %rcx
imull $0x2710, %ecx, %eax     # imm = 0x2710
subl %eax, %r8d
movq 0x18(%r13), %rax
movl (%rax), %eax
movq %rax, %r9
imulq %rbx, %r9
shrq $0x2d, %r9
imull $0x2710, %r9d, %edi     # imm = 0x2710
subl %edi, %eax
movl %eax, (%rsp)
movq %r12, %rdi
xorl %eax, %eax
callq 0x2100
movq 0x20(%r13), %r13
testq %r13, %r13
jne 0x8446
incl %r15d
movq 0x8(%rsp), %rbp
cmpl (%rbp), %r15d
jb 0x8405
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq