// File: /workspace/github_c_makefile_star2_O1/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 0x7707
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 0x66e4
movq %rax, %r14
xorl %eax, %eax
callq 0x66e4
movq %rax, 0x10(%rsp)
xorl %eax, %eax
callq 0x66e4
movq %rax, %r12
cmpl $0x0, 0x28(%rbx,%r15)
je 0x75c7
xorl %ebx, %ebx
movq 0x30(%rbp), %rax
movq (%rax,%rbx,8), %rsi
movq %r14, %rdi
callq 0x27c3
incq %rbx
movl 0x28(%rbp), %eax
cmpq %rax, %rbx
jb 0x75ac
cmpl $0x0, 0x14(%r13)
movq 0x10(%rsp), %r15
je 0x76e2
xorl %eax, %eax
movl %eax, 0xc(%rsp)
cmpq $0x0, (%r14)
je 0x7605
xorl %ebx, %ebx
movq 0x10(%r14), %rax
movq (%rax,%rbx,8), %rax
movq %rbp, 0x10(%rax)
movq 0x18(%rax), %rsi
movq %r15, %rdi
callq 0x27c3
incq %rbx
cmpq %rbx, (%r14)
ja 0x75e5
cmpq $0x0, (%r15)
je 0x76ba
xorl %ebx, %ebx
movq 0x10(%r15), %rax
movq (%rax,%rbx,8), %r15
cmpq $0x0, (%r14)
je 0x7644
xorl %r13d, %r13d
movq 0x10(%r14), %rax
movq (%rax,%r13,8), %rsi
movq %rbp, 0x10(%rsi)
cmpq %r15, 0x18(%rsi)
jne 0x763c
movq %r12, %rdi
callq 0x67b9
incq %r13
cmpq %r13, (%r14)
ja 0x7622
movq %r12, %rdi
callq 0x69ff
movq %rax, %r13
movl %r13d, 0x3c(%r15)
movl %r13d, %edi
shlq $0x3, %rdi
callq 0x21d0
testq %rax, %rax
je 0x7716
movq %rax, 0x40(%r15)
movq (%r12), %rax
testq %rax, %rax
je 0x7690
xorl %ecx, %ecx
movq 0x10(%r12), %rdx
movq (%rdx,%rcx,8), %rdx
movq 0x40(%r15), %rsi
movq %rdx, (%rsi,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x7677
movq 0x40(%r15), %rax
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
jne 0x76a1
movl %r13d, 0x38(%rbp)
movq %r12, %rdi
callq 0x67b1
incq %rbx
movq 0x10(%rsp), %r15
cmpq %rbx, (%r15)
ja 0x7611
movq %r14, %rdi
movq %r15, %rsi
callq 0x6762
movq %r15, %rdi
callq 0x67b1
movl 0xc(%rsp), %eax
incl %eax
movq 0x20(%rsp), %r13
cmpl 0x14(%r13), %eax
jb 0x75d9
movq %r14, %rdi
callq 0x679b
movq %r15, %rdi
callq 0x679b
movq 0x18(%rsp), %rcx
incq %rcx
movl 0x18(%r13), %eax
cmpq %rax, %rcx
jb 0x756e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5c2b(%rip), %rdi      # 0xd348
leaq 0x43db(%rip), %rsi      # 0xbaff
leaq 0x43ed(%rip), %rcx      # 0xbb18
movl $0x59, %edx
callq 0x2110