// File: /workspace/github_c_makefile_star2_O3/LPD-EPFL[P]mctop/src/mctop.c
// Function: init_mem
void*
init_mem(void* param)
{
  const int tid = *(int*) param;
  numa_run_on_node(tid);
  node_mem[tid] = numa_alloc_onnode(test_mem_size, tid);
  assert(node_mem[tid] != NULL);
  volatile uint64_t* m = node_mem[tid];
  ll_random_create(m, test_mem_size);
  if (tid == 0 && test_num_sockets > 1)
    {
      ticks t1 = ll_random_traverse(node_mem[!tid], test_mem_reps);
      ticks t2 = ll_random_traverse(node_mem[!tid], test_mem_reps);
      ticks df = abs_sub(t1, t2);
      ticks avg = (t1 + t2) / 2;
      if (df > (0.2 * avg))
	{
	  printf("## Memory measurements inaccurate (try 1: %zu, 2: %zu) \n", t1, t2);

	  volatile uint64_t* m = numa_alloc_onnode(test_mem_size, !tid);
	  assert(m != NULL);
	  ll_random_create(m, test_mem_size);
	  ticks t1 = ll_random_traverse(node_mem[!tid], test_mem_reps);
	  numa_free((void*) m, test_mem_size);

	  m = numa_alloc_onnode(test_mem_size, !tid);
	  assert(m != NULL);
	  ll_random_create(m, test_mem_size);
	  ticks t2 = ll_random_traverse(node_mem[!tid], test_mem_reps);
	  numa_free((void*) m, test_mem_size);

	  ticks df = abs_sub(t1, t2);
	  ticks avg = (t1 + t2) / 2;
	  if (df < (0.2 * avg))
	    {
	      printf("## Will use on-demand memory allocation (try 1: %zu, 2: %zu) \n", t1, t2);
	      test_mem_on_demand = 1;
	    }
	}
    }
  return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movslq (%rdi), %rbx
movl %ebx, %edi
callq 0x2220
movl $0x20000000, %edi       # imm = 0x20000000
movl %ebx, %esi
callq 0x21f0
movq 0xcf09(%rip), %rcx      # 0x102c8
movq %rax, (%rcx,%rbx,8)
movq 0xcefe(%rip), %rax      # 0x102c8
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x35a0
movl $0x20000000, %esi       # imm = 0x20000000
callq 0x5c88
testl %ebx, %ebx
jne 0x3592
cmpl $0x2, 0xce38(%rip)      # 0x10228
jl 0x3592
movq 0xcecb(%rip), %rax      # 0x102c8
movq 0x8(%rax), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x5c1c
movq %rax, %rbx
movq 0xceb3(%rip), %rax      # 0x102c8
movq 0x8(%rax), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x5c1c
movq %rax, %rcx
subq %rbx, %rcx
negq %rcx
movq %rax, %rdx
subq %rbx, %rdx
cmovbq %rcx, %rdx
leaq (%rax,%rbx), %rcx
movq %rdx, %xmm0
punpckldq 0x6c09(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
shrq %rcx
subpd 0x6c0e(%rip), %xmm0     # 0xa060
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x6bb2(%rip), %xmm0     # 0xa020
ucomisd %xmm0, %xmm1
jbe 0x3592
leaq 0x6def(%rip), %rdi      # 0xa26e
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2100
movl $0x20000000, %edi       # imm = 0x20000000
movl $0x1, %esi
callq 0x21f0
testq %rax, %rax
je 0x35bf
movq %rax, %r14
movl $0x20000000, %esi       # imm = 0x20000000
movq %rax, %rdi
callq 0x5c88
movq 0xce0d(%rip), %rax      # 0x102c8
movq 0x8(%rax), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x5c1c
movq %rax, %rbx
movl $0x20000000, %esi       # imm = 0x20000000
movq %r14, %rdi
callq 0x20c0
movl $0x20000000, %edi       # imm = 0x20000000
movl $0x1, %esi
callq 0x21f0
testq %rax, %rax
je 0x35de
movq %rax, %r15
movl $0x20000000, %esi       # imm = 0x20000000
movq %rax, %rdi
callq 0x5c88
movq 0xcdc0(%rip), %rax      # 0x102c8
movq 0x8(%rax), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x5c1c
movq %rax, %r14
subq %rbx, %rax
negq %rax
movq %r14, %r12
subq %rbx, %r12
cmovbq %rax, %r12
movl $0x20000000, %esi       # imm = 0x20000000
movq %r15, %rdi
callq 0x20c0
leaq (%r14,%rbx), %rax
movq %r12, %xmm0
punpckldq 0x6b09(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
shrq %rax
subpd 0x6b0e(%rip), %xmm0     # 0xa060
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x6ab2(%rip), %xmm0     # 0xa020
ucomisd %xmm1, %xmm0
jbe 0x3592
leaq 0x6d2c(%rip), %rdi      # 0xa2a7
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2100
movl $0x1, 0xcd16(%rip)      # 0x102a8
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x6c9a(%rip), %rdi      # 0xa241
leaq 0x6c73(%rip), %rsi      # 0xa221
leaq 0x6ca2(%rip), %rcx      # 0xa257
movl $0x15d, %edx            # imm = 0x15D
callq 0x2110
leaq 0x8d82(%rip), %rdi      # 0xc348
leaq 0x6c54(%rip), %rsi      # 0xa221
leaq 0x6c83(%rip), %rcx      # 0xa257
movl $0x16b, %edx            # imm = 0x16B
callq 0x2110
leaq 0x8d63(%rip), %rdi      # 0xc348
leaq 0x6c35(%rip), %rsi      # 0xa221
leaq 0x6c64(%rip), %rcx      # 0xa257
movl $0x171, %edx            # imm = 0x171
callq 0x2110