// File: /workspace/github_c_makefile_star2_O0/LPD-EPFL[P]mctop/src/mctop_topology.c
// Function: mctop_fix_siblings_by_bandwidth
static void
mctop_fix_siblings_by_bandwidth(mctop_t* topo)
{
  for (int s = 0; s < topo->n_sockets; s++)
    {
      socket_t* socket = &topo->sockets[s];
      socket->siblings_in = malloc_assert(socket->n_siblings * sizeof(sibling_t*));
      for (int i = 0; i < socket->n_siblings; i++)
	{
	  socket->siblings_in[i] = socket->siblings[i];
	}

      uint swaps = 0;
      do
	{
	  swaps = 0;
	  for (int i = 1; i < socket->n_siblings; i++)
	    {
	      sibling_t* sia = socket->siblings[i - 1];
	      sibling_t* sib = socket->siblings[i];
	      if (sia->latency == sib->latency)
		{
		  socket_t* soa = mctop_sibling_get_other_socket(sia, socket);
		  socket_t* sob = mctop_sibling_get_other_socket(sib, socket);
		  //if bw from socket to sob > bw from socket to soa, swap
		  if (mctop_socket_get_bw_to(socket, sob) > mctop_socket_get_bw_to(socket, soa))
		    {
		      socket->siblings[i - 1] = sib;
		      socket->siblings[i] = sia;
		      swaps++;
		    }
		}

	      sia = socket->siblings_in[i - 1];
	      sib = socket->siblings_in[i];
	      if (sia->latency == sib->latency)
		{
		  socket_t* soa = mctop_sibling_get_other_socket(sia, socket);
		  socket_t* sob = mctop_sibling_get_other_socket(sib, socket);
		  //if bw from sob to socket > bw soa to socket, swap
		  if (mctop_socket_get_bw_to(sob, socket) > mctop_socket_get_bw_to(soa, socket))
		    {
		      socket->siblings_in[i - 1] = sib;
		      socket->siblings_in[i] = sia;
		      swaps++;
		    }
		}

	    }
	}
      while (swaps > 0);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0xb6f9
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x93f0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x60(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jae 0xb518
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xb4e1
movl $0x0, -0x20(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jae 0xb6dd
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0xb605
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xc150
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xc150
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xc0a0
movsd %xmm0, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xc0a0
movaps %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xb603
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xb605
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0xb6cd
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xc150
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xc150
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xc0a0
movsd %xmm0, -0x68(%rbp)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xc0a0
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xb6cb
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xb6cd
jmp 0xb6cf
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xb52d
jmp 0xb6df
cmpl $0x0, -0x20(%rbp)
ja 0xb51f
jmp 0xb6eb
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xb493
addq $0x70, %rsp
popq %rbp
retq
nop