void eigenvalsort_reverse(double d[3], double (*v)[3]) {
  int i, j, k;
  double p;
  for (i = 0; i < 3 - 1; i++) {
    k = i;
    p = d[k];
    for (j = i + 1; j < 3; j++) {
      if (d[j] < p) {
        k = j;
        p = d[k];
      }
    }
    if (k != i) {
      d[k] = d[i];
      d[i] = p;
      for (j = 0; j < 3; j++) {
        p = v[j][i];
        v[j][i] = v[j][k];
        v[j][k] = p;
      }
    }
  }
}


x86 assembly (clang, -O0):
<eigenvalsort_reverse>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    1268 <eigenvalsort_reverse+0x168>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    118f <eigenvalsort_reverse+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    117c <eigenvalsort_reverse+0x7c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1181 <eigenvalsort_reverse+0x81>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <eigenvalsort_reverse+0x3e>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1255 <eigenvalsort_reverse+0x155>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    1250 <eigenvalsort_reverse+0x150>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ce <eigenvalsort_reverse+0xce>
jmp    1255 <eigenvalsort_reverse+0x155>
jmp    125a <eigenvalsort_reverse+0x15a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1113 <eigenvalsort_reverse+0x13>
pop    %rbp
ret

x86 assembly (clang, -O2):
<eigenvalsort_reverse>:
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
xor    %ecx,%ecx
ucomisd %xmm1,%xmm0
seta   %cl
minsd  %xmm0,%xmm1
movsd  0x10(%rdi),%xmm2
ucomisd %xmm2,%xmm1
mov    $0x2,%eax
cmovbe %rcx,%rax
test   %rax,%rax
je     1178 <eigenvalsort_reverse+0x78>
minsd  %xmm1,%xmm2
movsd  %xmm0,(%rdi,%rax,8)
movsd  %xmm2,(%rdi)
movsd  (%rsi),%xmm0
movsd  (%rsi,%rax,8),%xmm1
movsd  %xmm1,(%rsi)
movsd  %xmm0,(%rsi,%rax,8)
movsd  0x18(%rsi),%xmm0
movsd  0x18(%rsi,%rax,8),%xmm1
movsd  %xmm1,0x18(%rsi)
movsd  %xmm0,0x18(%rsi,%rax,8)
movsd  0x30(%rsi),%xmm0
movsd  0x30(%rsi,%rax,8),%xmm1
movsd  %xmm1,0x30(%rsi)
movsd  %xmm0,0x30(%rsi,%rax,8)
movsd  0x8(%rdi),%xmm0
movsd  0x10(%rdi),%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %cl
ucomisd %xmm1,%xmm0
jbe    11e1 <eigenvalsort_reverse+0xe1>
mov    %cl,%al
add    $0x1,%rax
movsd  %xmm0,(%rdi,%rax,8)
movsd  %xmm1,0x8(%rdi)
movsd  0x8(%rsi),%xmm0
movsd  (%rsi,%rax,8),%xmm1
movsd  %xmm1,0x8(%rsi)
movsd  %xmm0,(%rsi,%rax,8)
movsd  0x20(%rsi),%xmm0
movsd  0x18(%rsi,%rax,8),%xmm1
movsd  %xmm1,0x20(%rsi)
movsd  %xmm0,0x18(%rsi,%rax,8)
movsd  0x38(%rsi),%xmm0
movsd  0x30(%rsi,%rax,8),%xmm1
movsd  %xmm1,0x38(%rsi)
movsd  %xmm0,0x30(%rsi,%rax,8)
ret

LLVM IR (-O0):
define void @eigenvalsort_reverse(double* %0, [3 x double]* %1) {
%3 = alloca double*
%4 = alloca [3 x double]*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store double* %0, double** %3
store [3 x double]* %1, [3 x double]** %4
store i32 0, i32* %5
br label %9
9: ; preds = %102, %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %105
12: ; preds = %9
%13 = load i32, i32* %5
store i32 %13, i32* %7
%14 = load double*, double** %3
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
store double %18, double* %8
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %21
21: ; preds = %40, %12
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 3
br i1 %23, label %24, label %43
24: ; preds = %21
%25 = load double*, double** %3
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double, double* %8
%31 = fcmp olt double %29, %30
br i1 %31, label %32, label %39
32: ; preds = %24
%33 = load i32, i32* %6
store i32 %33, i32* %7
%34 = load double*, double** %3
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
store double %38, double* %8
br label %39
39: ; preds = %32, %24
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %21
43: ; preds = %21
%44 = load i32, i32* %7
%45 = load i32, i32* %5
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %101
47: ; preds = %43
%48 = load double*, double** %3
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = load double*, double** %3
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
store double %52, double* %56
%57 = load double, double* %8
%58 = load double*, double** %3
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
store double %57, double* %61
store i32 0, i32* %6
br label %62
62: ; preds = %97, %47
%63 = load i32, i32* %6
%64 = icmp slt i32 %63, 3
br i1 %64, label %65, label %100
65: ; preds = %62
%66 = load [3 x double]*, [3 x double]** %4
%67 = load i32, i32* %6
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [3 x double], [3 x double]* %66, i64 %68
%70 = load i32, i32* %5
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [3 x double], [3 x double]* %69, i64 0, i64 %71
%73 = load double, double* %72
store double %73, double* %8
%74 = load [3 x double]*, [3 x double]** %4
%75 = load i32, i32* %6
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [3 x double], [3 x double]* %74, i64 %76
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [3 x double], [3 x double]* %77, i64 0, i64 %79
%81 = load double, double* %80
%82 = load [3 x double]*, [3 x double]** %4
%83 = load i32, i32* %6
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [3 x double], [3 x double]* %82, i64 %84
%86 = load i32, i32* %5
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [3 x double], [3 x double]* %85, i64 0, i64 %87
store double %81, double* %88
%89 = load double, double* %8
%90 = load [3 x double]*, [3 x double]** %4
%91 = load i32, i32* %6
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [3 x double], [3 x double]* %90, i64 %92
%94 = load i32, i32* %7
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [3 x double], [3 x double]* %93, i64 0, i64 %95
store double %89, double* %96
br label %97
97: ; preds = %65
%98 = load i32, i32* %6
%99 = add nsw i32 %98, 1
store i32 %99, i32* %6
br label %62
100: ; preds = %62
br label %101
101: ; preds = %100, %43
br label %102
102: ; preds = %101
%103 = load i32, i32* %5
%104 = add nsw i32 %103, 1
store i32 %104, i32* %5
br label %9
105: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @eigenvalsort_reverse(double* nocapture %0, [3 x double]* nocapture %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = fcmp olt double %5, %3
%7 = select i1 %6, double %5, double %3
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = fcmp olt double %9, %7
%11 = zext i1 %6 to i64
%12 = select i1 %10, i64 2, i64 %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %2
%15 = select i1 %10, double %9, double %7
%16 = getelementptr inbounds double, double* %0, i64 %12
store double %3, double* %16
store double %15, double* %0
%17 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%18 = load double, double* %17
%19 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 %12
%20 = load double, double* %19
store double %20, double* %17
store double %18, double* %19
%21 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 0
%22 = load double, double* %21
%23 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 %12
%24 = load double, double* %23
store double %24, double* %21
store double %22, double* %23
%25 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 0
%26 = load double, double* %25
%27 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 %12
%28 = load double, double* %27
store double %28, double* %25
store double %26, double* %27
br label %29
29: ; preds = %14, %2
%30 = getelementptr inbounds double, double* %0, i64 1
%31 = load double, double* %30
%32 = getelementptr inbounds double, double* %0, i64 2
%33 = load double, double* %32
%34 = fcmp olt double %33, %31
%35 = select i1 %34, i64 2, i64 1
br i1 %34, label %36, label %50
36: ; preds = %29
%37 = getelementptr inbounds double, double* %0, i64 %35
store double %31, double* %37
store double %33, double* %30
%38 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 1
%39 = load double, double* %38
%40 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 %35
%41 = load double, double* %40
store double %41, double* %38
store double %39, double* %40
%42 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 1
%43 = load double, double* %42
%44 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 %35
%45 = load double, double* %44
store double %45, double* %42
store double %43, double* %44
%46 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 1
%47 = load double, double* %46
%48 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 %35
%49 = load double, double* %48
store double %49, double* %46
store double %47, double* %48
br label %50
50: ; preds = %36, %29
ret void
}