// File: /workspace/github_c_makefile_star2_O3/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, %r15
movl 0x18(%rdi), %edx
movl 0x10(%rdi), %esi
movl 0x14(%rdi), %ecx
movl 0x28(%rdi), %r8d
leaq 0x3ed4(%rip), %rdi      # 0xbb71
xorl %eax, %eax
callq 0x2100
movq 0x58(%r15), %rax
testq %rax, %rax
je 0x7d06
movl (%rax), %esi
decl %esi
leaq 0x3f19(%rip), %rdi      # 0xbbd1
xorl %eax, %eax
callq 0x2100
movq 0x58(%r15), %rax
cmpl $0x2, (%rax)
jb 0x7d06
movl $0x1, %ebx
leaq 0x3f18(%rip), %r14      # 0xbbec
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(%r15), %rax
movl (%rax), %ecx
cmpq %rcx, %rbx
jb 0x7cd4
movq %r15, 0x8(%rsp)
movq 0x80(%r15), %r14
testq %r14, %r14
je 0x7e9c
leaq 0x3f1a(%rip), %rdi      # 0xbc3c
leaq 0x3f50(%rip), %rsi      # 0xbc79
leaq 0x3f4f(%rip), %rdx      # 0xbc7f
leaq 0x3f4d(%rip), %rcx      # 0xbc84
leaq 0x3f4e(%rip), %r8       # 0xbc8c
leaq 0x3f4c(%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 0x3f27(%rip), %rbx      # 0xbc97
leaq 0x3f57(%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 0x3f2d(%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 0x3f09(%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 0x3ed9(%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 0x3eab(%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 0x3e77(%rip), %rsi      # 0xbd09
movq %rbx, %rdi
movb $0x5, %al
callq 0x2100
movq 0x8(%rsp), %r15
movl (%r15), %esi
leaq 0x3e6a(%rip), %rdi      # 0xbd15
xorl %eax, %eax
callq 0x2100
cmpl $0x0, (%r15)
je 0x7edf
leaq 0x3e80(%rip), %rbx      # 0xbd3f
xorl %r14d, %r14d
movq 0x8(%r15), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2100
incq %r14
movl (%r15), %eax
cmpq %rax, %r14
jb 0x7ec2
movl $0xa, %edi
callq 0x2040
movq 0x8(%r15), %rax
movq 0x40(%r15), %rcx
movl (%rax), %edx
movl 0x8(%rcx), %eax
leaq 0x7e93(%rip), %rcx      # 0xfd90
movq (%rcx,%rax,8), %r8
leaq 0x3e3c(%rip), %rdi      # 0xbd44
xorl %esi, %esi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x2100
leaq 0x3f55(%rip), %rdi      # 0xbe6f
callq 0x2080
leaq 0x3e61(%rip), %rdi      # 0xbd87
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x10(%r15)
je 0x7f99
leaq 0x3e45(%rip), %rbx      # 0xbd80
leaq 0x3e44(%rip), %r14      # 0xbd86
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r12, %r13
movq 0x8(%rsp), %r12
movq 0x40(%r12), %rax
movl (%rax,%r15), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2100
movl 0x10(%r12), %eax
leal -0x1(%rax), %ecx
leaq 0x1(%r13), %r12
cmpq %rcx, %r13
je 0x7f8e
movl %r12d, %ecx
andl $0xf, %ecx
jne 0x7f8e
movq %r14, %rdi
xorl %eax, %eax
callq 0x2100
movq 0x8(%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, %eax
addq $0x30, %r15
cmpq %rax, %r12
jb 0x7f48
movl $0xa, %edi
callq 0x2040
movq 0x8(%rsp), %r14
cmpl $0x0, 0x14(%r14)
je 0x834c
movl $0x1, %ebx
movl $0xd1b71759, %r13d      # imm = 0xD1B71759
leaq 0x3df8(%rip), %r12      # 0xbdbd
movl $0xcccccccd, %ebp       # imm = 0xCCCCCCCD
movq %r14, %rdi
movl %ebx, %esi
callq 0x8ba6
movq %rax, %r15
movq 0x8(%r14), %rax
movl (%rax,%rbx,4), %edx
leal -0x1(%rbx), %ecx
movl 0x8(%r15), %eax
leaq 0x7da4(%rip), %rsi      # 0xfd90
movq (%rsi,%rax,8), %r8
leaq 0x3d4d(%rip), %rdi      # 0xbd44
movq %rbx, 0x10(%rsp)
movl %ebx, %esi
xorl %eax, %eax
callq 0x2100
leaq 0x3e7b(%rip), %rdi      # 0xbe87
callq 0x2080
movl (%r15), %edx
movq %rdx, %rsi
imulq %r13, %rsi
shrq $0x2d, %rsi
imull $0x2710, %esi, %eax     # imm = 0x2710
subl %eax, %edx
leaq 0x3d5e(%rip), %rdi      # 0xbd8c
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x3c(%r15)
je 0x80b3
movl $0x1, %r14d
xorl %ebx, %ebx
movq 0x40(%r15), %rax
movq (%rax,%rbx,8), %rax
movl (%rax), %edx
movq %rdx, %rsi
imulq %r13, %rsi
shrq $0x2d, %rsi
imull $0x2710, %esi, %eax     # imm = 0x2710
subl %eax, %edx
leaq 0x3d33(%rip), %rdi      # 0xbd9b
xorl %eax, %eax
callq 0x2100
movl 0x3c(%r15), %eax
leal -0x1(%rax), %ecx
cmpq %rcx, %rbx
je 0x80a6
movl %r14d, %ecx
imulq %rbp, %rcx
shrq $0x23, %rcx
leal (%rcx,%rcx,4), %ecx
leal -0x1(,%rcx,2), %ecx
cmpl %ebx, %ecx
jne 0x80a6
leaq 0x3d0a(%rip), %rdi      # 0xbda5
xorl %eax, %eax
callq 0x2100
movl 0x3c(%r15), %eax
incq %rbx
movl %eax, %eax
incl %r14d
cmpq %rax, %rbx
jb 0x8044
movl $0xa, %edi
callq 0x2040
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x8011
movq 0x8(%rsp), %rax
movl 0x30(%rax), %eax
testl %eax, %eax
je 0x8327
movq 0x8(%rsp), %rbx
movl 0x14(%rbx), %ecx
cmpq %rcx, 0x10(%rsp)
jne 0x81a1
leaq 0x3da8(%rip), %rdi      # 0xbe9c
callq 0x2080
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x8ba6
testq %rax, %rax
je 0x8192
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 0x3c5d(%rip), %rdi      # 0xbd8c
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x70(%r15)
leaq 0x3c79(%rip), %r14      # 0xbdbb
leaq 0x3c69(%rip), %rbp      # 0xbdb2
leaq 0x3c64(%rip), %r12      # 0xbdb4
je 0x817f
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 0x8154
movl $0xa, %edi
callq 0x2040
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x8112
movq 0x8(%rsp), %rax
movl 0x30(%rax), %eax
leaq 0x3c1c(%rip), %r12      # 0xbdbd
cmpl $0x2, %eax
jne 0x8327
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
cmpq %rax, 0x10(%rsp)
jne 0x8327
leaq 0x3cff(%rip), %rdi      # 0xbec3
callq 0x2080
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x8ba6
testq %rax, %rax
je 0x8272
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 0x3b8b(%rip), %rdi      # 0xbd8c
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x70(%r15)
leaq 0x3ba7(%rip), %r14      # 0xbdbb
leaq 0x3b97(%rip), %rbp      # 0xbdb2
je 0x825b
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 0x821f
movl $0xa, %edi
callq 0x2040
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x81e4
leaq 0x3c85(%rip), %rdi      # 0xbefe
callq 0x2080
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x8ba6
testq %rax, %rax
je 0x8327
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 0x3ad6(%rip), %rdi      # 0xbd8c
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x70(%r15)
leaq 0x3af2(%rip), %r14      # 0xbdbb
leaq 0x3ae2(%rip), %rbp      # 0xbdb2
je 0x8310
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 0x82d4
movl $0xa, %edi
callq 0x2040
movq 0x20(%r15), %r15
testq %r15, %r15
jne 0x8299
movq 0x10(%rsp), %rcx
leaq 0x1(%rcx), %rbx
movq 0x8(%rsp), %r14
movl 0x14(%r14), %r15d
cmpq %r15, %rcx
movl $0xcccccccd, %ebp       # imm = 0xCCCCCCCD
jb 0x7fca
incl %r15d
jmp 0x8352
movl $0x1, %r15d
cmpl (%r14), %r15d
jae 0x8423
leaq 0x3b25(%rip), %rbp      # 0xbe87
movl $0xd1b71759, %ebx       # imm = 0xD1B71759
leaq 0x3a5f(%rip), %r12      # 0xbdcd
movq 0x8(%r14), %rax
movslq %r15d, %r13
movl (%rax,%r13,4), %edx
movl 0x14(%r14), %ecx
leaq 0x39c0(%rip), %rdi      # 0xbd44
movl %r13d, %esi
leaq 0x3ad4(%rip), %r8       # 0xbe62
xorl %eax, %eax
callq 0x2100
movq %rbp, %rdi
callq 0x2080
movq %r14, %rdi
movl %r13d, %esi
callq 0x8bc0
testq %rax, %rax
je 0x8412
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 0x83b0
incl %r15d
movq 0x8(%rsp), %r14
cmpl (%r14), %r15d
jb 0x836e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq