// File: /workspace/github_c_makefile_star2_O3/LPD-EPFL[P]mctop/src/mctop.c
// Function: mctop_mem_latencies_calc
void
mctop_mem_latencies_calc(mctop_t* topo, uint64_t** mem_lat_table)
{
  const size_t test_mem_size = 128 * 1024 * 1024LL;
  const size_t test_mem_reps = 5e6;

  double progress_step = 100.0 / (topo->n_sockets * topo->n_sockets);
  uint progress = 0;
  NOT_VERBOSE(printf("# Progress : %6.1f%%", 0.0); fflush(stdout));

  for (int s = 0; s < topo->n_sockets; s++)
    {
      VERBOSE(printf(" ######## Run Socket %d\n", s););
      uint hwc_id = mctop_socket_get_first_hwc(mctop_get_socket(topo, s))->id;
      mctop_run_on_socket(topo, s);
      for (int n = 0; n < topo->n_sockets; n++)
	{
	  VERBOSE(printf(" #### Mem Node %d\n", n););
	  volatile uint64_t* mem = numa_alloc_onnode(test_mem_size, n);
	  assert(mem != NULL);
	  ll_random_create(mem, test_mem_size);
	  volatile uint64_t* l = mem;

	  volatile ticks __s = getticks();
	  for (size_t r = 0; r < test_mem_reps >> 3; r++)
	    {
	      l = (uint64_t*) *l;
	    }
	  volatile ticks __e = getticks();
	  uint64_t lat = (__e - __s) / test_mem_reps;
	  VERBOSE(printf("  Latency       : warmup: %zu / ", lat););

	  __s = getticks();
	  for (size_t r = 0; r < test_mem_reps; r++)
	    {
	      l = (uint64_t*) *l;
	    }
	  __e = getticks();
	  lat = (__e - __s) / test_mem_reps;
	  VERBOSE(printf("normal: %zu\n", lat););

	  mem_lat_table[hwc_id][n] = lat;
	  assert(*l != 0);

	  numa_free((void*) mem, test_mem_size);
	  NOT_VERBOSE(printf("\r# Progress : %6.1f%%", ++progress * progress_step); fflush(stdout););
	}
    }

  NOT_VERBOSE(printf("\n"););
  mctop_mem_latencies_add(topo, mem_lat_table);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, %r12
movl 0x18(%rdi), %ebx
cmpl $0x0, 0xdf28(%rip)      # 0x10288
movl %ebx, %eax
jne 0x238a
leaq 0x7fe1(%rip), %rdi      # 0xa34c
xorpd %xmm0, %xmm0
movb $0x1, %al
callq 0x2100
movq 0xdc4b(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21e0
movl 0x18(%r12), %eax
testl %eax, %eax
je 0x25b2
imull %ebx, %ebx
cvtsi2sd %rbx, %xmm0
movsd 0x7c66(%rip), %xmm1     # 0xa008
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpl $0x0, 0xded0(%rip)      # 0x10288
jne 0x259d
movq %r12, %rdi
movl %ebx, %esi
callq 0x8b7c
movq %rax, %rdi
callq 0x8cb4
movl (%rax), %eax
movq %rax, 0x30(%rsp)
movq %r12, %rdi
movl %ebx, %esi
callq 0x8f7b
cmpl $0x0, 0x18(%r12)
je 0x25b2
movl %ebx, 0x1c(%rsp)
movl 0xde91(%rip), %eax      # 0x10288
xorl %r13d, %r13d
testl %eax, %eax
jne 0x253e
movl $0x8000000, %edi        # imm = 0x8000000
movl %r13d, %esi
callq 0x21f0
testq %rax, %rax
je 0x25fd
movq %rax, %r14
movl $0x8000000, %esi        # imm = 0x8000000
movq %rax, %rdi
callq 0x5c88
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x10(%rsp)
movl $0x98968, %eax          # imm = 0x98968
movq %r14, %rbp
movq (%rbp), %rbp
decq %rax
jne 0x2440
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
cmpl $0x0, 0xde1e(%rip)      # 0x10288
jne 0x2554
movq %r12, %rbx
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x10(%rsp)
movl $0x4c4b40, %eax         # imm = 0x4C4B40
movq (%rbp), %rbp
decq %rax
jne 0x2488
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x8(%rsp)
movq 0x8(%rsp), %rax
subq 0x10(%rsp), %rax
xorl %edx, %edx
movl $0x4c4b40, %ecx         # imm = 0x4C4B40
divq %rcx
movq %rax, %r12
cmpl $0x0, 0xddc9(%rip)      # 0x10288
jne 0x2577
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %r12, (%rax,%r13,8)
cmpq $0x0, (%rbp)
je 0x25de
movl $0x8000000, %esi        # imm = 0x8000000
movq %r14, %rdi
callq 0x20c0
movl 0xdd93(%rip), %eax      # 0x10288
testl %eax, %eax
jne 0x252a
incl %r15d
cvtsi2sd %r15, %xmm0
mulsd 0x28(%rsp), %xmm0
leaq 0x7e3d(%rip), %rdi      # 0xa34b
movb $0x1, %al
callq 0x2100
movq 0xdaac(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21e0
movl 0xdd5e(%rip), %eax      # 0x10288
movq %rbx, %r12
incq %r13
movl 0x18(%rbx), %ecx
cmpq %rcx, %r13
jb 0x23fa
jmp 0x258d
leaq 0x7dc3(%rip), %rdi      # 0xa308
movl %r13d, %esi
xorl %eax, %eax
callq 0x2100
jmp 0x2402
subq %rcx, %rax
xorl %edx, %edx
movl $0x4c4b40, %ecx         # imm = 0x4C4B40
divq %rcx
leaq 0x8561(%rip), %rdi      # 0xaac9
movq %rax, %rsi
xorl %eax, %eax
callq 0x2100
jmp 0x2470
leaq 0x856c(%rip), %rdi      # 0xaaea
movq %r12, %rsi
xorl %eax, %eax
callq 0x2100
jmp 0x24c5
movl 0x1c(%rsp), %ebx
incl %ebx
cmpl %ecx, %ebx
jb 0x23b1
jmp 0x25b2
leaq 0x7d4b(%rip), %rdi      # 0xa2ef
movl %ebx, %esi
xorl %eax, %eax
callq 0x2100
jmp 0x23be
cmpl $0x0, 0xdccf(%rip)      # 0x10288
jne 0x25c3
pushq $0xa
popq %rdi
callq 0x2040
movq %r12, %rdi
movq 0x20(%rsp), %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7964
leaq 0x8512(%rip), %rdi      # 0xaaf7
leaq 0x7c35(%rip), %rsi      # 0xa221
leaq 0x84a0(%rip), %rcx      # 0xaa93
movl $0x5e7, %edx            # imm = 0x5E7
callq 0x2110
leaq 0x9d42(%rip), %rdi      # 0xc346
leaq 0x7c16(%rip), %rsi      # 0xa221
leaq 0x8481(%rip), %rcx      # 0xaa93
movl $0x5d0, %edx            # imm = 0x5D0
callq 0x2110