// File: /workspace/github_c_makefile_star2_O3/LPD-EPFL[P]mctop/src/cdf.c
// Function: cdf_calc
cdf_t*
cdf_calc(uint64_t* vals, size_t n_vals)
{
  cdf_t* cdf = calloc(1, sizeof(cdf_t));
  assert(cdf != NULL);

  cdf_point_t* points = malloc(n_vals * sizeof(cdf_point_t));
  assert(points != NULL);

  uint64_t* vals_sorted = malloc(n_vals * sizeof(uint64_t));
  assert(vals_sorted != NULL);
  memcpy(vals_sorted, vals, n_vals * sizeof(uint64_t));
  qsort(vals_sorted, n_vals, sizeof(uint64_t), cdf_comp);

  size_t n_points = 0;
  uint64_t curr = vals_sorted[0];
  for (size_t i = 1; i < n_vals; i++)
    {
      if (vals_sorted[i] != curr)
	{
	  points[n_points].val = curr;
	  points[n_points].percentile = (100.0 * i) / n_vals;
	  n_points++;
	  curr = vals_sorted[i];
	}
    }
  points[n_points].val = curr;
  points[n_points].percentile = 100.0;
  n_points++;

  cdf->n_points = n_points;
  cdf->points = malloc(n_points * sizeof(cdf_point_t));
  assert(cdf->points != NULL);
  memcpy(cdf->points, points, n_points * sizeof(cdf_point_t));

  free(points);
  free(vals_sorted);
  return cdf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %r13
movl $0x1, %edi
movl $0x10, %esi
callq 0x2150
testq %rax, %rax
je 0x614f
movq %rax, %rbx
movq %r12, %rdi
shlq $0x4, %rdi
callq 0x21d0
testq %rax, %rax
je 0x616e
movq %rax, %r14
leaq (,%r12,8), %rbp
movq %rbp, %rdi
callq 0x21d0
testq %rax, %rax
je 0x618d
movq %rax, %r15
movq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2190
leaq 0x19a(%rip), %rcx       # 0x61cb
movl $0x8, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x20a0
movq (%r15), %rax
cmpq $0x2, %r12
jb 0x60e3
movq %r12, %xmm1
punpckldq 0x3ff5(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3ffd(%rip), %xmm1     # 0xa060
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movl $0x1, %ecx
xorl %r13d, %r13d
movq 0x3fd1(%rip), %xmm1     # 0xa050
movapd 0x3fd9(%rip), %xmm2     # 0xa060
movsd 0x3f79(%rip), %xmm3     # 0xa008
movq %rax, %rdx
movq (%r15,%rcx,8), %rax
cmpq %rdx, %rax
jne 0x60a0
movq %rdx, %rax
jmp 0x60d9
movq %r13, %rsi
shlq $0x4, %rsi
movq %rdx, (%r14,%rsi)
movq %rcx, %xmm4
punpckldq %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subpd %xmm2, %xmm4
movapd %xmm4, %xmm5
unpckhpd %xmm4, %xmm5            # xmm5 = xmm5[1],xmm4[1]
addsd %xmm4, %xmm5
mulsd %xmm3, %xmm5
divsd %xmm0, %xmm5
movsd %xmm5, 0x8(%r14,%rsi)
incq %r13
movq %rax, %rdx
incq %rcx
cmpq %rcx, %r12
jne 0x6092
jmp 0x60e6
xorl %r13d, %r13d
movq %r13, %rcx
shlq $0x4, %rcx
movq %rax, (%r14,%rcx)
movabsq $0x4059000000000000, %rax # imm = 0x4059000000000000
movq %rax, 0x8(%r14,%rcx)
incq %r13
movq %r13, (%rbx)
shlq $0x4, %r13
movq %r13, %rdi
callq 0x21d0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x61ac
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2190
movq %r14, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2030
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5799(%rip), %rdi      # 0xb8ef
leaq 0x579e(%rip), %rsi      # 0xb8fb
leaq 0x57a1(%rip), %rcx      # 0xb905
movl $0x18, %edx
callq 0x2110
leaq 0x57cd(%rip), %rdi      # 0xb942
leaq 0x577f(%rip), %rsi      # 0xb8fb
leaq 0x5782(%rip), %rcx      # 0xb905
movl $0x1b, %edx
callq 0x2110
leaq 0x5795(%rip), %rdi      # 0xb929
leaq 0x5760(%rip), %rsi      # 0xb8fb
leaq 0x5763(%rip), %rcx      # 0xb905
movl $0x1e, %edx
callq 0x2110
leaq 0x578a(%rip), %rdi      # 0xb93d
leaq 0x5741(%rip), %rsi      # 0xb8fb
leaq 0x5744(%rip), %rcx      # 0xb905
movl $0x34, %edx
callq 0x2110