// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x758c
jmp 0x75ab
leaq 0x952c(%rip), %rdi      # 0x10abf
leaq 0x9531(%rip), %rsi      # 0x10acb
movl $0x18, %edx
leaq 0x952f(%rip), %rcx      # 0x10ad5
callq 0x20e0
movq -0x10(%rbp), %rdi
shlq $0x4, %rdi
callq 0x21a0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x75c5
jmp 0x75e4
leaq 0x9546(%rip), %rdi      # 0x10b12
leaq 0x94f8(%rip), %rsi      # 0x10acb
movl $0x1b, %edx
leaq 0x94f6(%rip), %rcx      # 0x10ad5
callq 0x20e0
movq -0x10(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x75fe
jmp 0x761d
leaq 0x94f4(%rip), %rdi      # 0x10af9
leaq 0x94bf(%rip), %rsi      # 0x10acb
movl $0x1e, %edx
leaq 0x94bd(%rip), %rcx      # 0x10ad5
callq 0x20e0
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
shlq $0x3, %rdx
callq 0x2160
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x8, %edx
leaq 0x1ba(%rip), %rcx       # 0x7800
callq 0x2070
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x1, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x7730
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x38(%rbp), %rax
je 0x771d
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
movq %rdx, (%rax,%rcx)
movaps 0x79ab(%rip), %xmm3     # 0xf050
movq -0x40(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x79aa(%rip), %xmm2     # 0xf060
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x793b(%rip), %xmm1     # 0xf008
mulsd %xmm1, %xmm0
movq -0x10(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
jmp 0x771f
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x7666
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x78ab(%rip), %xmm0     # 0xf008
movsd %xmm0, 0x8(%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
shlq $0x4, %rdi
callq 0x21a0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x779e
jmp 0x77bd
leaq 0x9368(%rip), %rdi      # 0x10b0d
leaq 0x931f(%rip), %rsi      # 0x10acb
movl $0x34, %edx
leaq 0x931d(%rip), %rcx      # 0x10ad5
callq 0x20e0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
shlq $0x4, %rdx
callq 0x2160
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)