// File: /workspace/github_c_makefile_star2_O0/LPD-EPFL[P]mctop/src/mctop_topology.c
// Function: mctop_fix_children_links
void
mctop_fix_children_links(mctop_t* topo)
{
  for (int s = 0; s < topo->n_sockets; s++)
    {
      socket_t* socket = topo->sockets + s;
      darray_t* children = darray_create();
      darray_t* parents = darray_create();
      darray_t* contents = darray_create();
      for (int h = 0; h < socket->n_hwcs; h++)
      	{
      	  hw_context_t* hwc = socket->hwcs[h];
      	  darray_add_uniq(children, (uintptr_t) hwc);
      	}

      for (int lvl = 0; lvl < topo->socket_level; lvl++)
	{
	  /* get parents */
	  DARRAY_FOR_EACH(children, i)
	    {
	      hwc_gs_t* gs = (hwc_gs_t*) DARRAY_GET_N(children, i);
	      gs->socket = socket;
	      darray_add_uniq(parents, (uintptr_t) gs->parent);
	    }
	  DARRAY_FOR_EACH(parents, p)
	    {
	      hwc_gs_t* gsp = (hwc_gs_t*) DARRAY_GET_N(parents, p);
	      DARRAY_FOR_EACH(children, c)
		{
		  hwc_gs_t* gsc = (hwc_gs_t*) DARRAY_GET_N(children, c);
		  gsc->socket = socket;
		  if (gsc->parent == gsp)
		    {
		      darray_add(contents, (uintptr_t) gsc);
		    }
		}

	      gsp->n_children = darray_get_num_elems(contents);
	      gsp->children = malloc_assert(gsp->n_children * sizeof(hwc_gs_t*));
	      DARRAY_FOR_EACH(contents, c)
		{
		  gsp->children[c] = (hwc_gs_t*) DARRAY_GET_N(contents, c);
		}

	      if (gsp->children[0]->type == CORE) /* set n_cores for socket */
		{
		  socket->n_cores = gsp->n_children;
		}

	      darray_empty(contents);
	    }

	  darray_copy(children, parents);
	  darray_empty(parents);
	}

      darray_free(children);
      darray_free(parents);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x9af7
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movb $0x0, %al
callq 0x80e0
movq %rax, -0x20(%rbp)
movb $0x0, %al
callq 0x80e0
movq %rax, -0x28(%rbp)
movb $0x0, %al
callq 0x80e0
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jae 0x9920
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x8410
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x98e8
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x9ad7
movl $0x0, -0x48(%rbp)
movslq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x9987
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rdi
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x8410
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x993e
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x9ab3
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x9a0f
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x60(%rbp), %rax
jne 0x9a02
movq -0x30(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x8260
jmp 0x9a04
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x99ba
movq -0x30(%rbp), %rdi
callq 0x88a0
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0x60(%rbp), %rax
movl 0x3c(%rax), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x93f0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x40(%rax)
movl $0x0, -0x74(%rbp)
movslq -0x74(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x9a7d
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x60(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x74(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x9a45
movq -0x60(%rbp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
jne 0x9a9c
movq -0x60(%rbp), %rax
movl 0x3c(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x30(%rbp), %rdi
callq 0x8240
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x998e
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x81b0
movq -0x28(%rbp), %rdi
callq 0x8240
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x9927
movq -0x20(%rbp), %rdi
callq 0x8210
movq -0x28(%rbp), %rdi
callq 0x8210
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x9896
addq $0x80, %rsp
popq %rbp
retq