// File: /workspace/github_c_makefile_star2_O1/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 0x61b3
movq %rax, %rbx
movq %r12, %rdi
shlq $0x4, %rdi
callq 0x21d0
testq %rax, %rax
je 0x61d2
movq %rax, %r14
leaq (,%r12,8), %rbp
movq %rbp, %rdi
callq 0x21d0
testq %rax, %rax
je 0x61f1
movq %rax, %r15
movq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2190
leaq 0x19a(%rip), %rcx       # 0x622f
movl $0x8, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x20a0
movq (%r15), %rax
cmpq $0x2, %r12
jb 0x6147
movq %r12, %xmm1
punpckldq 0x4f91(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4f99(%rip), %xmm1     # 0xb060
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movl $0x1, %ecx
xorl %r13d, %r13d
movq 0x4f6d(%rip), %xmm1     # 0xb050
movapd 0x4f75(%rip), %xmm2     # 0xb060
movsd 0x4f15(%rip), %xmm3     # 0xb008
movq %rax, %rdx
movq (%r15,%rcx,8), %rax
cmpq %rdx, %rax
jne 0x6104
movq %rdx, %rax
jmp 0x613d
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 0x60f6
jmp 0x614a
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 0x6210
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 0x6735(%rip), %rdi      # 0xc8ef
leaq 0x673a(%rip), %rsi      # 0xc8fb
leaq 0x673d(%rip), %rcx      # 0xc905
movl $0x18, %edx
callq 0x2110
leaq 0x6769(%rip), %rdi      # 0xc942
leaq 0x671b(%rip), %rsi      # 0xc8fb
leaq 0x671e(%rip), %rcx      # 0xc905
movl $0x1b, %edx
callq 0x2110
leaq 0x6731(%rip), %rdi      # 0xc929
leaq 0x66fc(%rip), %rsi      # 0xc8fb
leaq 0x66ff(%rip), %rcx      # 0xc905
movl $0x1e, %edx
callq 0x2110
leaq 0x6726(%rip), %rdi      # 0xc93d
leaq 0x66dd(%rip), %rsi      # 0xc8fb
leaq 0x66e0(%rip), %rcx      # 0xc905
movl $0x34, %edx
callq 0x2110