void spr_sort_realnums(double *farr, int size, double *r_farr) {
  int *indices = ((int *)malloc((size) * sizeof(int)));
  spr_indices_sort_realnums(farr, size, indices);
  if (farr == r_farr) {
    double *temp = ((double *)malloc((size) * sizeof(double)));
    realnums_permute(farr, indices, temp, size);
    copy_realnums(temp, r_farr, size);
    free(temp);
  } else
    realnums_permute(farr, indices, r_farr, size);
  free(indices);
}


x86 assembly (clang, -O0):
<spr_sort_realnums>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movslq -0xc(%rbp),%rdi
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1050 <spr_indices_sort_realnums@plt>
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11db <spr_sort_realnums+0x8b>
movslq -0xc(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x0,%al
call   1060 <realnums_permute@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x0,%al
call   1070 <copy_realnums@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    11f1 <spr_sort_realnums+0xa1>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x0,%al
call   1060 <realnums_permute@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spr_sort_realnums>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbp
movslq %esi,%rbx
lea    0x0(,%rbx,4),%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <spr_indices_sort_realnums@plt>
cmp    %r15,%rbp
je     119d <spr_sort_realnums+0x4d>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <realnums_permute@plt>
jmp    11d7 <spr_sort_realnums+0x87>
shl    $0x3,%rbx
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <realnums_permute@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <copy_realnums@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @spr_sort_realnums(double* %0, i32 %1, double* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32*
%8 = alloca double*
store double* %0, double** %4
store i32 %1, i32* %5
store double* %2, double** %6
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = call i8* @malloc(i64 %11)
%13 = bitcast i8* %12 to i32*
store i32* %13, i32** %7
%14 = load double*, double** %4
%15 = load i32, i32* %5
%16 = load i32*, i32** %7
%17 = call i32 (double*, i32, i32*, ...) bitcast (i32 (...)* @spr_indices_sort_realnums to i32 (double*, i32, i32*, ...)*)(double* %14, i32 %15, i32* %16)
%18 = load double*, double** %4
%19 = load double*, double** %6
%20 = icmp eq double* %18, %19
br i1 %20, label %21, label %38
21: ; preds = %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = call i8* @malloc(i64 %24)
%26 = bitcast i8* %25 to double*
store double* %26, double** %8
%27 = load double*, double** %4
%28 = load i32*, i32** %7
%29 = load double*, double** %8
%30 = load i32, i32* %5
%31 = call i32 (double*, i32*, double*, i32, ...) bitcast (i32 (...)* @realnums_permute to i32 (double*, i32*, double*, i32, ...)*)(double* %27, i32* %28, double* %29, i32 %30)
%32 = load double*, double** %8
%33 = load double*, double** %6
%34 = load i32, i32* %5
%35 = call i32 (double*, double*, i32, ...) bitcast (i32 (...)* @copy_realnums to i32 (double*, double*, i32, ...)*)(double* %32, double* %33, i32 %34)
%36 = load double*, double** %8
%37 = bitcast double* %36 to i8*
br label %44
38: ; preds = %3
%39 = load double*, double** %4
%40 = load i32*, i32** %7
%41 = load double*, double** %6
%42 = load i32, i32* %5
%43 = call i32 (double*, i32*, double*, i32, ...) bitcast (i32 (...)* @realnums_permute to i32 (double*, i32*, double*, i32, ...)*)(double* %39, i32* %40, double* %41, i32 %42)
br label %44
44: ; preds = %38, %21
%45 = load i32*, i32** %7
%46 = bitcast i32* %45 to i8*
ret void
}

LLVM IR (-O2):
define void @spr_sort_realnums(double* %0, i32 %1, double* %2) {
%4 = sext i32 %1 to i64
%5 = shl nsw i64 %4, 2
%6 = tail call i8* @malloc(i64 %5)
%7 = bitcast i8* %6 to i32*
%8 = tail call i32 (double*, i32, i32*, ...) bitcast (i32 (...)* @spr_indices_sort_realnums to i32 (double*, i32, i32*, ...)*)(double* %0, i32 %1, i32* %7)
%9 = icmp eq double* %0, %2
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = shl nsw i64 %4, 3
%12 = tail call i8* @malloc(i64 %11)
%13 = bitcast i8* %12 to double*
%14 = tail call i32 (double*, i32*, double*, i32, ...) bitcast (i32 (...)* @realnums_permute to i32 (double*, i32*, double*, i32, ...)*)(double* %0, i32* %7, double* %13, i32 %1)
%15 = tail call i32 (double*, double*, i32, ...) bitcast (i32 (...)* @copy_realnums to i32 (double*, double*, i32, ...)*)(double* %13, double* %0, i32 %1)
tail call void @free(i8* %12)
br label %18
16: ; preds = %3
%17 = tail call i32 (double*, i32*, double*, i32, ...) bitcast (i32 (...)* @realnums_permute to i32 (double*, i32*, double*, i32, ...)*)(double* %0, i32* %7, double* %2, i32 %1)
br label %18
18: ; preds = %16, %10
tail call void @free(i8* %6)
ret void
}