// File: /workspace/github_c_makefile_star2_O2/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 %rdi, %r14
movl 0x18(%rdi), %eax
movl %eax, %ecx
imull %ecx, %ecx
cvtsi2sd %rcx, %xmm1
movq %rsi, 0x30(%rsp)
movsd 0x599b(%rip), %xmm0     # 0xa008
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, 0xbc0e(%rip)      # 0x10288
jne 0x46ac
leaq 0x5cc9(%rip), %rdi      # 0xa34c
xorps %xmm0, %xmm0
movb $0x1, %al
movsd %xmm1, 0x10(%rsp)
callq 0x2100
movq 0xb92e(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21e0
movsd 0x10(%rsp), %xmm1
movl 0x18(%r14), %eax
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
xorl %r15d, %r15d
movl 0xbbc1(%rip), %ecx      # 0x10288
cmpl %eax, %ebx
jae 0x48b6
testl %ecx, %ecx
jne 0x48a1
movq %r14, %rdi
movl %ebx, %esi
callq 0x7ed0
movq %rax, %rdi
callq 0x801a
movl (%rax), %eax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movl %ebx, 0x2c(%rsp)
movl %ebx, %esi
callq 0x83b6
xorl %r13d, %r13d
movl 0x18(%r14), %eax
cmpq %rax, %r13
jae 0x4896
cmpl $0x0, 0xbb73(%rip)      # 0x10288
jne 0x4847
movl $0x8000000, %edi        # imm = 0x8000000
movl %r13d, %esi
callq 0x21f0
testq %rax, %rax
je 0x48dd
movq %rax, %rbx
movl $0x8000000, %esi        # imm = 0x8000000
movq %rax, %rdi
callq 0x5559
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x20(%rsp)
movl $0x98968, %eax          # imm = 0x98968
movq %rbx, %rbp
subq $0x1, %rax
jb 0x4765
movq (%rbp), %rbp
jmp 0x4759
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
cmpl $0x0, 0xbb02(%rip)      # 0x10288
jne 0x485d
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x20(%rsp)
movl $0x4c4b40, %eax         # imm = 0x4C4B40
subq $0x1, %rax
jb 0x47ad
movq (%rbp), %rbp
jmp 0x47a1
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x18(%rsp)
movq 0x18(%rsp), %rax
subq 0x20(%rsp), %rax
xorl %edx, %edx
movl $0x4c4b40, %ecx         # imm = 0x4C4B40
divq %rcx
movq %rax, %r12
cmpl $0x0, 0xbaad(%rip)      # 0x10288
jne 0x4880
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %r12, (%rax,%r13,8)
cmpq $0x0, (%rbp)
je 0x48fc
movl $0x8000000, %esi        # imm = 0x8000000
movq %rbx, %rdi
callq 0x20c0
cmpl $0x0, 0xba76(%rip)      # 0x10288
jne 0x483f
incl %r15d
cvtsi2sd %r15, %xmm0
mulsd 0x8(%rsp), %xmm0
leaq 0x5b22(%rip), %rdi      # 0xa34b
movb $0x1, %al
callq 0x2100
movq 0xb791(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21e0
incq %r13
jmp 0x4701
leaq 0x5aba(%rip), %rdi      # 0xa308
movl %r13d, %esi
xorl %eax, %eax
callq 0x2100
jmp 0x471b
subq %rcx, %rax
xorl %edx, %edx
movl $0x4c4b40, %ecx         # imm = 0x4C4B40
divq %rcx
leaq 0x6258(%rip), %rdi      # 0xaac9
movq %rax, %rsi
xorl %eax, %eax
callq 0x2100
jmp 0x478c
leaq 0x6263(%rip), %rdi      # 0xaaea
movq %r12, %rsi
xorl %eax, %eax
callq 0x2100
jmp 0x47e1
movl 0x2c(%rsp), %ebx
incl %ebx
jmp 0x46c1
leaq 0x5a47(%rip), %rdi      # 0xa2ef
movl %ebx, %esi
xorl %eax, %eax
callq 0x2100
jmp 0x46d7
testl %ecx, %ecx
jne 0x48c2
pushq $0xa
popq %rdi
callq 0x2040
movq %r14, %rdi
movq 0x30(%rsp), %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6f3b
leaq 0x7a62(%rip), %rdi      # 0xc346
leaq 0x5936(%rip), %rsi      # 0xa221
leaq 0x61a1(%rip), %rcx      # 0xaa93
movl $0x5d0, %edx            # imm = 0x5D0
callq 0x2110
leaq 0x61f4(%rip), %rdi      # 0xaaf7
leaq 0x5917(%rip), %rsi      # 0xa221
leaq 0x6182(%rip), %rcx      # 0xaa93
movl $0x5e7, %edx            # imm = 0x5E7
callq 0x2110