// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x8000000, -0x18(%rbp) # imm = 0x8000000
movq $0x4c4b40, -0x20(%rbp)  # imm = 0x4C4B40
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
imull %eax, %eax
cvtsi2sd %rax, %xmm1
movsd 0x9851(%rip), %xmm0     # 0xf008
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x0, 0xfaca(%rip)      # 0x15298
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5804
leaq 0x9d27(%rip), %rdi      # 0xf512
xorps %xmm0, %xmm0
movb $0x1, %al
callq 0x20d0
movq 0xf7d4(%rip), %rax      # 0x14fd0
movq (%rax), %rdi
callq 0x21b0
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x5ac3
cmpl $0x0, 0xfa76(%rip)      # 0x15298
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5847
movl -0x30(%rbp), %esi
leaq 0x9c75(%rip), %rdi      # 0xf4b5
movb $0x0, %al
callq 0x20d0
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0xba60
movq %rax, %rdi
callq 0xbe60
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0xc880
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x5ab3
cmpl $0x0, 0xfa0e(%rip)      # 0x15298
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x58af
movl -0x38(%rbp), %esi
leaq 0x9c26(%rip), %rdi      # 0xf4ce
movb $0x0, %al
callq 0x20d0
movl -0x38(%rbp), %esi
movl $0x8000000, %edi        # imm = 0x8000000
callq 0x21c0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x58c9
jmp 0x58e8
leaq 0xbc56(%rip), %rdi      # 0x11526
leaq 0x9b10(%rip), %rsi      # 0xf3e7
movl $0x5d0, %edx            # imm = 0x5D0
leaq 0xaf9a(%rip), %rcx      # 0x1087d
callq 0x20e0
movq -0x40(%rbp), %rdi
movl $0x8000000, %esi        # imm = 0x8000000
callq 0x6f20
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
callq 0x66f0
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
cmpq $0x98968, -0x58(%rbp)   # imm = 0x98968
jae 0x5932
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x590f
callq 0x66f0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
movl $0x4c4b40, %ecx         # imm = 0x4C4B40
xorl %edx, %edx
divq %rcx
movq %rax, -0x68(%rbp)
cmpl $0x0, 0xf93d(%rip)      # 0x15298
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5981
movq -0x68(%rbp), %rsi
leaq 0xaf39(%rip), %rdi      # 0x108b3
movb $0x0, %al
callq 0x20d0
callq 0x66f0
movq %rax, -0x50(%rbp)
movq $0x0, -0x70(%rbp)
cmpq $0x4c4b40, -0x70(%rbp)  # imm = 0x4C4B40
jae 0x59b5
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x5992
callq 0x66f0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
movl $0x4c4b40, %ecx         # imm = 0x4C4B40
xorl %edx, %edx
divq %rcx
movq %rax, -0x68(%rbp)
cmpl $0x0, 0xf8ba(%rip)      # 0x15298
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5a04
movq -0x68(%rbp), %rsi
leaq 0xaed7(%rip), %rdi      # 0x108d4
movb $0x0, %al
callq 0x20d0
movq -0x68(%rbp), %rdx
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, %rax
je 0x5a2a
jmp 0x5a49
leaq 0xaeb0(%rip), %rdi      # 0x108e1
leaq 0x99af(%rip), %rsi      # 0xf3e7
movl $0x5e7, %edx            # imm = 0x5E7
leaq 0xae39(%rip), %rcx      # 0x1087d
callq 0x20e0
movq -0x40(%rbp), %rdi
movl $0x8000000, %esi        # imm = 0x8000000
callq 0x2090
cmpl $0x0, 0xf83a(%rip)      # 0x15298
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5aa3
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cvtsi2sd %rax, %xmm0
mulsd -0x28(%rbp), %xmm0
leaq 0x9a84(%rip), %rdi      # 0xf511
movb $0x1, %al
callq 0x20d0
movq 0xf535(%rip), %rax      # 0x14fd0
movq (%rax), %rdi
callq 0x21b0
jmp 0x5aa5
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x5873
jmp 0x5ab5
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x580b
cmpl $0x0, 0xf7ce(%rip)      # 0x15298
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x5aee
leaq 0x9984(%rip), %rdi      # 0xf46b
movb $0x0, %al
callq 0x20d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xa020
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)