// File: /workspace/github_c_makefile_star2_O2/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 0xd68d(%rip), %rcx      # 0x102c8
movq %rax, (%rcx,%rbx,8)
movq 0xd682(%rip), %rax      # 0x102c8
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2e12
movl $0x20000000, %esi       # imm = 0x20000000
callq 0x5559
testl %ebx, %ebx
jne 0x2e04
cmpl $0x2, 0xd5bc(%rip)      # 0x10228
jl 0x2e04
movq 0xd64f(%rip), %rax      # 0x102c8
movq 0x8(%rax), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x54f1
movq %rax, %rbx
movq 0xd637(%rip), %rax      # 0x102c8
movq 0x8(%rax), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x54f1
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 0x738d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
shrq %rcx
subpd 0x7392(%rip), %xmm0     # 0xa060
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
cvtsi2sd %rcx, %xmm0
mulsd 0x7339(%rip), %xmm0     # 0xa020
ucomisd %xmm0, %xmm1
jbe 0x2e04
leaq 0x7576(%rip), %rdi      # 0xa26e
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2100
pushq $0x1
popq %rsi
movl $0x20000000, %edi       # imm = 0x20000000
callq 0x21f0
testq %rax, %rax
je 0x2e31
movq %rax, %r14
movl $0x20000000, %esi       # imm = 0x20000000
movq %rax, %rdi
callq 0x5559
movq 0xd596(%rip), %rax      # 0x102c8
movq 0x8(%rax), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x54f1
movq %rax, %rbx
movl $0x20000000, %esi       # imm = 0x20000000
movq %r14, %rdi
callq 0x20c0
pushq $0x1
popq %rsi
movl $0x20000000, %edi       # imm = 0x20000000
callq 0x21f0
testq %rax, %rax
je 0x2e50
movq %rax, %r15
movl $0x20000000, %esi       # imm = 0x20000000
movq %rax, %rdi
callq 0x5559
movq 0xd54b(%rip), %rax      # 0x102c8
movq 0x8(%rax), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x54f1
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 0x7294(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
shrq %rax
subpd 0x7299(%rip), %xmm0     # 0xa060
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
cvtsi2sd %rax, %xmm0
mulsd 0x7240(%rip), %xmm0     # 0xa020
ucomisd %xmm1, %xmm0
jbe 0x2e04
leaq 0x74ba(%rip), %rdi      # 0xa2a7
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2100
movl $0x1, 0xd4a4(%rip)      # 0x102a8
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x7428(%rip), %rdi      # 0xa241
leaq 0x7401(%rip), %rsi      # 0xa221
leaq 0x7430(%rip), %rcx      # 0xa257
movl $0x15d, %edx            # imm = 0x15D
callq 0x2110
leaq 0x9510(%rip), %rdi      # 0xc348
leaq 0x73e2(%rip), %rsi      # 0xa221
leaq 0x7411(%rip), %rcx      # 0xa257
movl $0x16b, %edx            # imm = 0x16B
callq 0x2110
leaq 0x94f1(%rip), %rdi      # 0xc348
leaq 0x73c3(%rip), %rsi      # 0xa221
leaq 0x73f2(%rip), %rcx      # 0xa257
movl $0x171, %edx            # imm = 0x171
callq 0x2110