#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sort_indices(double *, int *, int);
void test_sort_indices() {
  double x[10] = {0, 90, 70, 40, 20, 10, 30, 80, 50, 60};
  int idx[10];
  sort_indices(x, idx, 10);
  printf("x[idx] = [ ");
  int i;
  for (i = 0; i < 10; i++)
    printf("%f ", x[idx[i]]);
  printf("]\n");
}


x86 assembly (clang, -O0):
<test_sort_indices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x50(%rbp),%rdi
lea    0xeba(%rip),%rsi
mov    $0x50,%edx
call   1040 <memcpy@plt>
lea    -0x50(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0xa,%edx
call   1050 <sort_indices@plt>
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x84(%rbp)
cmpl   $0xa,-0x84(%rbp)
jge    11bb <test_sort_indices+0x8b>
movslq -0x84(%rbp),%rax
movslq -0x80(%rbp,%rax,4),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
lea    0xebc(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    117a <test_sort_indices+0x4a>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sort_indices>:
push   %rbx
sub    $0x80,%rsp
movaps 0xf01(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xee5(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xead(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe91(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x30(%rsp),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <sort_indices@plt>
lea    0xec3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq (%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
lea    0xeb7(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x4(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x8(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0xc(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x10(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x14(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x18(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x1c(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x20(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movslq 0x24(%rsp),%rax
movsd  0x30(%rsp,%rax,8),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xded(%rip),%rdi
call   1030 <puts@plt>
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_sort_indices.x = [10 x double] [double 0.000000e+00, double 9.000000e+01, double 7.000000e+01, double 4.000000e+01, double 2.000000e+01, double 1.000000e+01, double 3.000000e+01, double 8.000000e+01, double 5.000000e+01, double 6.000000e+01]
@.str = [12 x i8] c"x[idx] = [ \00"
@.str.1 = [4 x i8] c"%f \00"
@.str.2 = [3 x i8] c"]\0A\00"
define void @test_sort_indices() {
%1 = alloca [10 x double]
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = bitcast [10 x double]* %1 to i8*
%5 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 0
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%7 = call i32 @sort_indices(double* %5, i32* %6, i32 10)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %9
9: ; preds = %21, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %17
%19 = load double, double* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %19)
br label %21
21: ; preds = %12
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %9
24: ; preds = %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.test_sort_indices.x = [10 x double] [double 0.000000e+00, double 9.000000e+01, double 7.000000e+01, double 4.000000e+01, double 2.000000e+01, double 1.000000e+01, double 3.000000e+01, double 8.000000e+01, double 5.000000e+01, double 6.000000e+01]
@.str = [12 x i8] c"x[idx] = [ \00"
@.str.1 = [4 x i8] c"%f \00"
@str = [2 x i8] c"]\00"
define void @test_sort_indices() {
%1 = alloca [10 x double]
%2 = alloca [10 x i32]
%3 = bitcast [10 x double]* %1 to i8*
%4 = bitcast [10 x i32]* %2 to i8*
%5 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 0
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%7 = call i32 @sort_indices(double* %5, i32* %6, i32 10)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %10
%12 = load double, double* %11
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %12)
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 1
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %16
%18 = load double, double* %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %18)
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 2
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %22
%24 = load double, double* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %24)
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 3
%27 = load i32, i32* %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %28
%30 = load double, double* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %30)
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 4
%33 = load i32, i32* %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %34
%36 = load double, double* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %36)
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 5
%39 = load i32, i32* %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %40
%42 = load double, double* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %42)
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 6
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %46
%48 = load double, double* %47
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %48)
%50 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 7
%51 = load i32, i32* %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %52
%54 = load double, double* %53
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %54)
%56 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 8
%57 = load i32, i32* %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %58
%60 = load double, double* %59
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %60)
%62 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 9
%63 = load i32, i32* %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 %64
%66 = load double, double* %65
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %66)
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}