// File: /workspace/github_c_makefile_star2_O2/LPD-EPFL[P]mctop/src/mctop_topology.c
// Function: mctop_free
void
mctop_free(mctop_t* topo)
{
  /* free siblings */
  for (int l = topo->socket_level + 1; l < topo->n_levels; l++)
    {
      sibling_t* sibling = mctop_get_first_sibling_lvl(topo, l);
      do
	{
	  sibling_t* next = sibling->next;
	  free(sibling);
	  sibling = next;
	}
      while (sibling != NULL);
    }

  /* free groups */
  for (int l = 1; l < topo->socket_level; l++)
    {
      hwc_gs_t* gs = mctop_get_first_gs_at_lvl(topo, l);
      do
	{
	  hwc_gs_t* next = gs->next;
	  free(gs->hwcs);
	  free(gs->children);
	  free(gs);
	  gs = next;
	}
      while (gs != NULL);
    }

  /* free socket stuff */
  for (int s = 0; s < topo->n_sockets; s++)
    {
      socket_t* socket = topo->sockets + s;
      free(socket->hwcs);
      free(socket->children);
      if (socket->n_siblings > 0)
	{
	  free(socket->siblings);
	  if (socket->siblings_in)
	    {
	      free(socket->siblings_in);
	    }
	}
      if (topo->has_mem >= LATENCY)
	{
	  free(socket->mem_latencies);
	}
      if (topo->has_mem == BANDWIDTH)
	{
	  free(socket->mem_bandwidths_r);
	  free(socket->mem_bandwidths1_r);
	}
      if (socket->pow_info)
	{
	  free(socket->pow_info);
	}
    }

  /* free topo */
  free(topo->latencies);
  free(topo->sockets);
  free(topo->hwcs);
  if (topo->n_siblings > 0)
    {
      free(topo->siblings);
    }
  if (topo->has_mem)
    {
      free(topo->node_to_socket);
      if (topo->has_mem == BANDWIDTH)
	{
	  free(topo->mem_bandwidths_r);
	  free(topo->mem_bandwidths1_r);
	  free(topo->mem_bandwidths_w);
	  free(topo->mem_bandwidths1_w);
	}
    }
  if (topo->pow_info)
    {
      free(topo->pow_info);
    }
  free(topo);
  topo = NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl 0x14(%rdi), %ebp
incl %ebp
cmpl (%rbx), %ebp
jae 0x7076
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7f12
movq %rax, %rdi
movq 0x20(%rdi), %r14
callq 0x2030
movq %r14, %rdi
testq %r14, %r14
jne 0x7063
jmp 0x7050
pushq $0x1
popq %rbp
cmpl 0x14(%rbx), %ebp
jae 0x70b5
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7efa
movq %rax, %r14
movq 0x20(%r14), %r15
movq 0x30(%r14), %rdi
callq 0x2030
movq 0x40(%r14), %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %r15, %r14
testq %r15, %r15
jne 0x708b
incl %ebp
jmp 0x7079
movl $0xa0, %r14d
xorl %r15d, %r15d
movl 0x18(%rbx), %eax
cmpq %rax, %r15
jae 0x7139
movq 0x20(%rbx), %r12
movq -0x70(%r12,%r14), %rdi
callq 0x2030
movq -0x60(%r12,%r14), %rdi
callq 0x2030
cmpl $0x0, -0x50(%r12,%r14)
je 0x70fa
movq -0x48(%r12,%r14), %rdi
callq 0x2030
movq -0x40(%r12,%r14), %rdi
callq 0x2030
cmpl $0x0, 0x30(%rbx)
je 0x7124
movq -0x28(%r12,%r14), %rdi
callq 0x2030
cmpl $0x2, 0x30(%rbx)
jne 0x7124
movq -0x20(%r12,%r14), %rdi
callq 0x2030
movq -0x18(%r12,%r14), %rdi
callq 0x2030
movq (%r12,%r14), %rdi
callq 0x2030
incq %r15
addq $0xa8, %r14
jmp 0x70be
movq 0x8(%rbx), %rdi
callq 0x2030
movq 0x20(%rbx), %rdi
callq 0x2030
movq 0x40(%rbx), %rdi
callq 0x2030
cmpl $0x0, 0x48(%rbx)
je 0x7163
movq 0x50(%rbx), %rdi
callq 0x2030
cmpl $0x0, 0x30(%rbx)
je 0x719c
movq 0x38(%rbx), %rdi
callq 0x2030
cmpl $0x2, 0x30(%rbx)
jne 0x719c
movq 0x60(%rbx), %rdi
callq 0x2030
movq 0x68(%rbx), %rdi
callq 0x2030
movq 0x70(%rbx), %rdi
callq 0x2030
movq 0x78(%rbx), %rdi
callq 0x2030
movq 0x80(%rbx), %rdi
callq 0x2030
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2030