// File: /workspace/github_c_makefile_star2_O1/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 (%rdi), %ebp
jae 0x7bce
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8c4a
movq %rax, %rdi
movq 0x20(%rdi), %r14
callq 0x2030
movq %r14, %rdi
testq %r14, %r14
jne 0x7bb7
incl %ebp
cmpl (%rbx), %ebp
jb 0x7baa
cmpl $0x2, 0x14(%rbx)
jb 0x7c13
movl $0x1, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8c32
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 0x7be6
incl %ebp
cmpl 0x14(%rbx), %ebp
jb 0x7bd9
cmpl $0x0, 0x18(%rbx)
je 0x7cad
movl $0xa0, %r14d
xorl %r15d, %r15d
movq 0x20(%rbx), %r12
movq -0x70(%r12,%r14), %rdi
callq 0x2030
movq -0x60(%r12,%r14), %rdi
callq 0x2030
cmpl $0x0, -0x50(%r12,%r14)
je 0x7c5f
movq -0x48(%r12,%r14), %rdi
callq 0x2030
movq -0x40(%r12,%r14), %rdi
testq %rdi, %rdi
je 0x7c5f
callq 0x2030
cmpl $0x0, 0x30(%rbx)
je 0x7c6f
movq -0x28(%r12,%r14), %rdi
callq 0x2030
cmpl $0x2, 0x30(%rbx)
jne 0x7c89
movq -0x20(%r12,%r14), %rdi
callq 0x2030
movq -0x18(%r12,%r14), %rdi
callq 0x2030
movq (%r12,%r14), %rdi
testq %rdi, %rdi
je 0x7c97
callq 0x2030
incq %r15
movl 0x18(%rbx), %eax
addq $0xa8, %r14
cmpq %rax, %r15
jb 0x7c26
movq 0x8(%rbx), %rdi
callq 0x2030
movq 0x20(%rbx), %rdi
callq 0x2030
movq 0x40(%rbx), %rdi
callq 0x2030
cmpl $0x0, 0x48(%rbx)
je 0x7cd7
movq 0x50(%rbx), %rdi
callq 0x2030
cmpl $0x0, 0x30(%rbx)
je 0x7d10
movq 0x38(%rbx), %rdi
callq 0x2030
cmpl $0x2, 0x30(%rbx)
jne 0x7d10
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
testq %rdi, %rdi
je 0x7d21
callq 0x2030
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2030