// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x0, 0x18(%rdi)
je 0x7652
movq %rdi, %r13
xorl %ecx, %ecx
movq %rdi, 0x20(%rsp)
movq 0x20(%r13), %rbx
movq %rcx, 0x18(%rsp)
imulq $0xa8, %rcx, %r15
leaq (%rbx,%r15), %rbp
xorl %eax, %eax
callq 0x6640
movq %rax, %r14
xorl %eax, %eax
callq 0x6640
movq %rax, 0x10(%rsp)
xorl %eax, %eax
callq 0x6640
movq %rax, %r12
cmpl $0x0, 0x28(%rbx,%r15)
je 0x750d
xorl %ebx, %ebx
movq 0x30(%rbp), %rax
movq (%rax,%rbx,8), %rsi
movq %r14, %rdi
callq 0x27e4
incq %rbx
movl 0x28(%rbp), %eax
cmpq %rax, %rbx
jb 0x74f2
cmpl $0x0, 0x14(%r13)
movq 0x10(%rsp), %r15
je 0x762d
xorl %eax, %eax
movl %eax, 0xc(%rsp)
cmpq $0x0, (%r14)
je 0x754b
xorl %ebx, %ebx
movq 0x10(%r14), %rax
movq (%rax,%rbx,8), %rax
movq %rbp, 0x10(%rax)
movq 0x18(%rax), %rsi
movq %r15, %rdi
callq 0x27e4
incq %rbx
cmpq %rbx, (%r14)
ja 0x752b
cmpq $0x0, (%r15)
je 0x7605
xorl %ebx, %ebx
movq 0x10(%r15), %rax
movq (%rax,%rbx,8), %r15
movq (%r14), %rax
testq %rax, %rax
je 0x758f
xorl %r13d, %r13d
movq 0x10(%r14), %rcx
movq (%rcx,%r13,8), %rsi
movq %rbp, 0x10(%rsi)
cmpq %r15, 0x18(%rsi)
jne 0x7587
movq %r12, %rdi
callq 0x6715
movq (%r14), %rax
incq %r13
cmpq %r13, %rax
ja 0x756a
movq %r12, %rdi
callq 0x6951
movq %rax, %r13
movl %r13d, 0x3c(%r15)
movl %r13d, %edi
shlq $0x3, %rdi
callq 0x21d0
testq %rax, %rax
je 0x7661
movq %rax, 0x40(%r15)
movq (%r12), %rcx
testq %rcx, %rcx
je 0x75df
xorl %eax, %eax
movq 0x10(%r12), %rdx
movq (%rdx,%rax,8), %rdx
movq 0x40(%r15), %rsi
movq %rdx, (%rsi,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x75c2
movq 0x40(%r15), %rax
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
jne 0x75ec
movl %r13d, 0x38(%rbp)
movq %r12, %rdi
callq 0x670d
incq %rbx
movq 0x10(%rsp), %r15
cmpq %rbx, (%r15)
ja 0x7557
movq %r14, %rdi
movq %r15, %rsi
callq 0x66be
movq %r15, %rdi
callq 0x670d
movl 0xc(%rsp), %eax
incl %eax
movq 0x20(%rsp), %r13
cmpl 0x14(%r13), %eax
jb 0x751f
movq %r14, %rdi
callq 0x66f7
movq %r15, %rdi
callq 0x66f7
movq 0x18(%rsp), %rcx
incq %rcx
movl 0x18(%r13), %eax
cmpq %rax, %rcx
jb 0x74b4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4ce0(%rip), %rdi      # 0xc348
leaq 0x3490(%rip), %rsi      # 0xaaff
leaq 0x34a2(%rip), %rcx      # 0xab18
movl $0x59, %edx
callq 0x2110