void spr_sort_ints(int *iarr, int size, int *r_iarr) {
  int *indices = ((int *)malloc((size) * sizeof(int)));
  double *farr = mk_farr_from_iarr(iarr, size);
  spr_indices_sort_realnums(farr, size, indices);
  if (iarr == r_iarr) {
    int *temp = ((int *)malloc((size) * sizeof(int)));
    ints_permute(iarr, indices, temp, size);
    copy_ints(temp, r_iarr, size);
    free(temp);
  } else
    ints_permute(iarr, indices, r_iarr, size);
  free(indices);
  free(farr);
}


x86 assembly (clang, -O0):
<spr_sort_ints>:
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   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x0,%al
call   1080 <mk_farr_from_iarr@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1060 <spr_indices_sort_realnums@plt>
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11ff <spr_sort_ints+0x9f>
movslq -0xc(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x0,%al
call   1040 <ints_permute@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x0,%al
call   1070 <copy_ints@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1215 <spr_sort_ints+0xb5>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x0,%al
call   1040 <ints_permute@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spr_sort_ints>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%rbp
movslq %esi,%r14
lea    0x0(,%r14,4),%r13
mov    %r13,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1080 <mk_farr_from_iarr@plt>
movslq %eax,%rdi
mov    %rdi,(%rsp)
mov    %r14d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <spr_indices_sort_realnums@plt>
cmp    %r12,%rbp
je     11c5 <spr_sort_ints+0x65>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <ints_permute@plt>
jmp    11fb <spr_sort_ints+0x9b>
mov    %r13,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <ints_permute@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <copy_ints@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @spr_sort_ints(i32* %0, i32 %1, i32* %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 (i32*, i32, ...) bitcast (i32 (...)* @mk_farr_from_iarr to i32 (i32*, i32, ...)*)(i32* %0, i32 %1)
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to double*
%11 = tail call i32 (double*, i32, i32*, ...) bitcast (i32 (...)* @spr_indices_sort_realnums to i32 (double*, i32, i32*, ...)*)(double* %10, i32 %1, i32* %7)
%12 = icmp eq i32* %0, %2
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = tail call i8* @malloc(i64 %5)
%15 = bitcast i8* %14 to i32*
%16 = tail call i32 (i32*, i32*, i32*, i32, ...) bitcast (i32 (...)* @ints_permute to i32 (i32*, i32*, i32*, i32, ...)*)(i32* %0, i32* %7, i32* %15, i32 %1)
%17 = tail call i32 (i32*, i32*, i32, ...) bitcast (i32 (...)* @copy_ints to i32 (i32*, i32*, i32, ...)*)(i32* %15, i32* %0, i32 %1)
tail call void @free(i8* %14)
br label %20
18: ; preds = %3
%19 = tail call i32 (i32*, i32*, i32*, i32, ...) bitcast (i32 (...)* @ints_permute to i32 (i32*, i32*, i32*, i32, ...)*)(i32* %0, i32* %7, i32* %2, i32 %1)
br label %20
20: ; preds = %18, %13
tail call void @free(i8* %6)
%21 = inttoptr i64 %9 to i8*
tail call void @free(i8* %21)
ret void
}