// File: /workspace/github_c_makefile_star2_O1/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, 0x28(%rsp)
movq %rdi, 0x8(%rsp)
movl 0x18(%rdi), %ebx
cmpl $0x0, 0xef16(%rip)      # 0x11288
jne 0x2395
leaq 0x8fd1(%rip), %rdi      # 0xb34c
xorpd %xmm0, %xmm0
movb $0x1, %al
callq 0x2100
movq 0xec3b(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21e0
movq 0x8(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x25bb
imull %ebx, %ebx
cvtsi2sd %rbx, %xmm0
movsd 0x8c54(%rip), %xmm1     # 0xb008
divsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpl $0x0, 0xeebe(%rip)      # 0x11288
jne 0x25a6
movq 0x8(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
callq 0x8c08
movq %rax, %rdi
callq 0x8d4f
movl (%rax), %ebx
movq %r14, %rdi
movl %ebp, 0x24(%rsp)
movl %ebp, %esi
callq 0x9016
cmpl $0x0, 0x18(%r14)
je 0x2590
xorl %r13d, %r13d
cmpl $0x0, 0xee7c(%rip)      # 0x11288
jne 0x2541
movl $0x8000000, %edi        # imm = 0x8000000
movl %r13d, %esi
callq 0x21f0
testq %rax, %rax
je 0x25e9
movq %rax, %r14
movl $0x8000000, %esi        # imm = 0x8000000
movq %rax, %rdi
callq 0x5cac
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x18(%rsp)
movl $0x98968, %eax          # imm = 0x98968
movq %r14, %rbp
movq (%rbp), %rbp
decq %rax
jne 0x2450
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpl $0x0, 0xee0e(%rip)      # 0x11288
jne 0x2557
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x18(%rsp)
movl $0x4c4b40, %eax         # imm = 0x4C4B40
movq (%rbp), %rbp
decq %rax
jne 0x2495
rdtsc
movl %eax, %eax
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, 0x10(%rsp)
movq 0x10(%rsp), %rax
subq 0x18(%rsp), %rax
xorl %edx, %edx
movl $0x4c4b40, %ecx         # imm = 0x4C4B40
divq %rcx
movq %rax, %r12
cmpl $0x0, 0xedbc(%rip)      # 0x11288
jne 0x257a
movq 0x28(%rsp), %rax
movq (%rax,%rbx,8), %rax
movq %r12, (%rax,%r13,8)
cmpq $0x0, (%rbp)
je 0x2608
movl $0x8000000, %esi        # imm = 0x8000000
movq %r14, %rdi
callq 0x20c0
cmpl $0x0, 0xed8a(%rip)      # 0x11288
jne 0x252b
incl %r15d
cvtsi2sd %r15, %xmm0
mulsd 0x30(%rsp), %xmm0
leaq 0x8e36(%rip), %rdi      # 0xb34b
movb $0x1, %al
callq 0x2100
movq 0xeaa5(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21e0
incq %r13
movq 0x8(%rsp), %rax
movl 0x18(%rax), %eax
cmpq %rax, %r13
jb 0x2405
jmp 0x2590
leaq 0x8dc0(%rip), %rdi      # 0xb308
movl %r13d, %esi
xorl %eax, %eax
callq 0x2100
jmp 0x2412
subq %rcx, %rax
xorl %edx, %edx
movl $0x4c4b40, %ecx         # imm = 0x4C4B40
divq %rcx
leaq 0x955e(%rip), %rdi      # 0xbac9
movq %rax, %rsi
xorl %eax, %eax
callq 0x2100
jmp 0x2480
leaq 0x9569(%rip), %rdi      # 0xbaea
movq %r12, %rsi
xorl %eax, %eax
callq 0x2100
jmp 0x24d2
movl 0x24(%rsp), %ebp
incl %ebp
movq 0x8(%rsp), %rax
cmpl 0x18(%rax), %ebp
jb 0x23c3
jmp 0x25bb
leaq 0x8d42(%rip), %rdi      # 0xb2ef
movl %ebp, %esi
xorl %eax, %eax
callq 0x2100
jmp 0x23d0
cmpl $0x0, 0xecc6(%rip)      # 0x11288
jne 0x25cc
pushq $0xa
popq %rdi
callq 0x2040
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7a12
leaq 0xad56(%rip), %rdi      # 0xd346
leaq 0x8c2a(%rip), %rsi      # 0xb221
leaq 0x9495(%rip), %rcx      # 0xba93
movl $0x5d0, %edx            # imm = 0x5D0
callq 0x2110
leaq 0x94e8(%rip), %rdi      # 0xbaf7
leaq 0x8c0b(%rip), %rsi      # 0xb221
leaq 0x9476(%rip), %rcx      # 0xba93
movl $0x5e7, %edx            # imm = 0x5E7
callq 0x2110