int UniqueDouble(int M, double *list, double *uni_list, int *uni_i, int *uni_j,
                 int *cnt) {
  double *sorted;
  int *sort_idx;
  int u;
  sorted = (double *)malloc(M * sizeof(double));
  sort_idx = (int *)malloc(M * sizeof(int));
  SortUnstableDouble(M, list, sorted, sort_idx);
  u = CountSortedDouble(M, sorted, sort_idx, uni_list, uni_i, uni_j, cnt);
  free(sorted);
  free(sort_idx);
  return u;
}


x86 assembly (clang, -O0):
<UniqueDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x0,%al
call   1040 <SortUnstableDouble@plt>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%rax
mov    %rax,(%rsp)
mov    $0x0,%al
call   1060 <CountSortedDouble@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UniqueDouble>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r13
mov    %r8,0x10(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rdx,%r12
mov    %rsi,%rbp
movslq %edi,%r14
lea    0x0(,%r14,8),%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0x0(,%r14,4),%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <SortUnstableDouble@plt>
mov    %r13,(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    0x8(%rsp),%r8
mov    0x10(%rsp),%r9
xor    %eax,%eax
call   1060 <CountSortedDouble@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @UniqueDouble(i32 %0, double* %1, double* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca double*
%14 = alloca i32*
%15 = alloca i32
store i32 %0, i32* %7
store double* %1, double** %8
store double* %2, double** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 8
%19 = call i8* @malloc(i64 %18)
%20 = bitcast i8* %19 to double*
store double* %20, double** %13
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = call i8* @malloc(i64 %23)
%25 = bitcast i8* %24 to i32*
store i32* %25, i32** %14
%26 = load i32, i32* %7
%27 = load double*, double** %8
%28 = load double*, double** %13
%29 = load i32*, i32** %14
%30 = call i32 (i32, double*, double*, i32*, ...) bitcast (i32 (...)* @SortUnstableDouble to i32 (i32, double*, double*, i32*, ...)*)(i32 %26, double* %27, double* %28, i32* %29)
%31 = load i32, i32* %7
%32 = load double*, double** %13
%33 = load i32*, i32** %14
%34 = load double*, double** %9
%35 = load i32*, i32** %10
%36 = load i32*, i32** %11
%37 = load i32*, i32** %12
%38 = call i32 (i32, double*, i32*, double*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @CountSortedDouble to i32 (i32, double*, i32*, double*, i32*, i32*, i32*, ...)*)(i32 %31, double* %32, i32* %33, double* %34, i32* %35, i32* %36, i32* %37)
store i32 %38, i32* %15
%39 = load double*, double** %13
%40 = bitcast double* %39 to i8*
%41 = load i32*, i32** %14
%42 = bitcast i32* %41 to i8*
%43 = load i32, i32* %15
ret i32 %43
}

LLVM IR (-O2):
define i32 @UniqueDouble(i32 %0, double* %1, double* %2, i32* %3, i32* %4, i32* %5) {
%7 = sext i32 %0 to i64
%8 = shl nsw i64 %7, 3
%9 = tail call i8* @malloc(i64 %8)
%10 = bitcast i8* %9 to double*
%11 = shl nsw i64 %7, 2
%12 = tail call i8* @malloc(i64 %11)
%13 = bitcast i8* %12 to i32*
%14 = tail call i32 (i32, double*, double*, i32*, ...) bitcast (i32 (...)* @SortUnstableDouble to i32 (i32, double*, double*, i32*, ...)*)(i32 %0, double* %1, double* %10, i32* %13)
%15 = tail call i32 (i32, double*, i32*, double*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @CountSortedDouble to i32 (i32, double*, i32*, double*, i32*, i32*, i32*, ...)*)(i32 %0, double* %10, i32* %13, double* %2, i32* %3, i32* %4, i32* %5)
tail call void @free(i8* %9)
tail call void @free(i8* %12)
ret i32 %15
}