#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int n;

/* Variables and functions */
int /*<<< orphan*/ CSPL_Sort_mergesort(double *, long const);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ memcpy(double *, double const *, int);
void CSPL_Stats_tCDF(const double *datain, double *cdfout, const long n) {
  long i, count;
  double *incopy;
  {
    incopy = (double *)calloc((n) - (0) + 1, sizeof(double));
    memcpy((incopy), &(datain)[(0)], sizeof(double) * ((n) - (0) + 1));
  };
  CSPL_Sort_mergesort(incopy, n);
  for (i = 0; i < n; i++) {
    count = 0;
    while (incopy[count] <= incopy[i]) {
      count++;
      if ((n) <= count)
        break;
    }
    cdfout[i] = (double)count / (double)n;
  }
  free(incopy);
}


x86 assembly (clang, -O0):
<CSPL_Stats_tCDF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
sub    $0x0,%rax
add    $0x1,%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <CSPL_Sort_mergesort@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1230 <CSPL_Stats_tCDF+0xf0>
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1202 <CSPL_Stats_tCDF+0xc2>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jg     11fd <CSPL_Stats_tCDF+0xbd>
jmp    1202 <CSPL_Stats_tCDF+0xc2>
jmp    11ba <CSPL_Stats_tCDF+0x7a>
cvtsi2sdq -0x28(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a4 <CSPL_Stats_tCDF+0x64>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CSPL_Stats_tCDF>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x1(%rdx),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
lea    0x8(,%r15,8),%edx
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <memcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <CSPL_Sort_mergesort@plt>
test   %r15,%r15
jle    11d6 <CSPL_Stats_tCDF+0x96>
cvtsi2sd %r15,%xmm0
xor    %eax,%eax
jmp    11ab <CSPL_Stats_tCDF+0x6b>
nopl   (%rax)
xorps  %xmm1,%xmm1
cvtsi2sd %rcx,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%rax,8)
add    $0x1,%rax
cmp    %r15,%rax
je     11d6 <CSPL_Stats_tCDF+0x96>
movsd  (%rbx,%rax,8),%xmm1
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
ucomisd (%rbx,%rcx,8),%xmm1
jb     1190 <CSPL_Stats_tCDF+0x50>
add    $0x1,%rcx
cmp    %rcx,%r15
jne    11c0 <CSPL_Stats_tCDF+0x80>
movapd %xmm0,%xmm1
jmp    1198 <CSPL_Stats_tCDF+0x58>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @CSPL_Stats_tCDF(double* %0, double* %1, i64 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca double*
store double* %0, double** %4
store double* %1, double** %5
store i64 %2, i64* %6
%10 = load i64, i64* %6
%11 = sub nsw i64 %10, 0
%12 = add nsw i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @calloc(i32 %13, i32 8)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %9
%16 = load double*, double** %9
%17 = load double*, double** %4
%18 = getelementptr inbounds double, double* %17, i64 0
%19 = load i64, i64* %6
%20 = sub nsw i64 %19, 0
%21 = add nsw i64 %20, 1
%22 = mul i64 8, %21
%23 = trunc i64 %22 to i32
%24 = call i32 @memcpy(double* %16, double* %18, i32 %23)
%25 = load double*, double** %9
%26 = load i64, i64* %6
%27 = call i32 @CSPL_Sort_mergesort(double* %25, i64 %26)
store i64 0, i64* %7
br label %28
28: ; preds = %60, %3
%29 = load i64, i64* %7
%30 = load i64, i64* %6
%31 = icmp slt i64 %29, %30
br i1 %31, label %32, label %63
32: ; preds = %28
store i64 0, i64* %8
br label %33
33: ; preds = %50, %32
%34 = load double*, double** %9
%35 = load i64, i64* %8
%36 = getelementptr inbounds double, double* %34, i64 %35
%37 = load double, double* %36
%38 = load double*, double** %9
%39 = load i64, i64* %7
%40 = getelementptr inbounds double, double* %38, i64 %39
%41 = load double, double* %40
%42 = fcmp ole double %37, %41
br i1 %42, label %43, label %51
43: ; preds = %33
%44 = load i64, i64* %8
%45 = add nsw i64 %44, 1
store i64 %45, i64* %8
%46 = load i64, i64* %6
%47 = load i64, i64* %8
%48 = icmp sle i64 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %43
br label %51
50: ; preds = %43
br label %33
51: ; preds = %49, %33
%52 = load i64, i64* %8
%53 = sitofp i64 %52 to double
%54 = load i64, i64* %6
%55 = sitofp i64 %54 to double
%56 = fdiv double %53, %55
%57 = load double*, double** %5
%58 = load i64, i64* %7
%59 = getelementptr inbounds double, double* %57, i64 %58
store double %56, double* %59
br label %60
60: ; preds = %51
%61 = load i64, i64* %7
%62 = add nsw i64 %61, 1
store i64 %62, i64* %7
br label %28
63: ; preds = %28
%64 = load double*, double** %9
%65 = call i32 @free(double* %64)
ret void
}

LLVM IR (-O2):
define void @CSPL_Stats_tCDF(double* %0, double* nocapture writeonly %1, i64 %2) {
%4 = trunc i64 %2 to i32
%5 = add i32 %4, 1
%6 = tail call i64 @calloc(i32 %5, i32 8)
%7 = inttoptr i64 %6 to double*
%8 = shl i32 %5, 3
%9 = tail call i32 @memcpy(double* %7, double* %0, i32 %8)
%10 = tail call i32 @CSPL_Sort_mergesort(double* %7, i64 %2)
%11 = icmp sgt i64 %2, 0
br i1 %11, label %12, label %34
12: ; preds = %3
%13 = sitofp i64 %2 to double
br label %14
14: ; preds = %12, %28
%15 = phi i64 [ 0, %12 ], [ %32, %28 ]
%16 = getelementptr inbounds double, double* %7, i64 %15
%17 = load double, double* %16
br label %18
18: ; preds = %14, %25
%19 = phi i64 [ %26, %25 ], [ 0, %14 ]
%20 = getelementptr inbounds double, double* %7, i64 %19
%21 = load double, double* %20
%22 = fcmp ugt double %21, %17
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = sitofp i64 %19 to double
br label %28
25: ; preds = %18
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, %2
br i1 %27, label %28, label %18
28: ; preds = %25, %23
%29 = phi double [ %24, %23 ], [ %13, %25 ]
%30 = fdiv double %29, %13
%31 = getelementptr inbounds double, double* %1, i64 %15
store double %30, double* %31
%32 = add nuw nsw i64 %15, 1
%33 = icmp eq i64 %32, %2
br i1 %33, label %34, label %14
34: ; preds = %28, %3
%35 = tail call i32 @free(double* %7)
ret void
}