void selectionSortDouble(double *values, const int arraySize) {
  int i = 0;
  int j = 0;
  int minIndex = 0;
  double temp = 0;
  for (i = 0; i < arraySize - 1; ++i) {
    minIndex = i + 1;
    for (j = i; j < arraySize; j++)
      if (values[j] < values[minIndex])
        minIndex = j;
    temp = values[i];
    values[i] = values[minIndex];
    values[minIndex] = temp;
  }
}


x86 assembly (clang, -O0):
<selectionSortDouble>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11e4 <selectionSortDouble+0xe4>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1198 <selectionSortDouble+0x98>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1185 <selectionSortDouble+0x85>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    118a <selectionSortDouble+0x8a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <selectionSortDouble+0x4f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112f <selectionSortDouble+0x2f>
pop    %rbp
ret

x86 assembly (clang, -O2):
<selectionSortDouble>:
cmp    $0x2,%esi
jl     1170 <selectionSortDouble+0x70>
mov    %esi,%r10d
add    $0xffffffff,%esi
xor    %r9d,%r9d
jmp    1133 <selectionSortDouble+0x33>
mov    %r8d,%eax
movsd  (%rdi,%r9,8),%xmm0
cltq
movsd  (%rdi,%rax,8),%xmm1
movsd  %xmm1,(%rdi,%r9,8)
movsd  %xmm0,(%rdi,%rax,8)
mov    %r8,%r9
cmp    %rsi,%r8
je     1170 <selectionSortDouble+0x70>
lea    0x1(%r9),%r8
cmp    %r10,%r9
jae    1110 <selectionSortDouble+0x10>
mov    %r9,%rcx
mov    %r8d,%edx
jmp    115b <selectionSortDouble+0x5b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rcx
mov    %eax,%edx
cmp    %rcx,%r10
je     1113 <selectionSortDouble+0x13>
movslq %edx,%rax
movsd  (%rdi,%rax,8),%xmm0
ucomisd (%rdi,%rcx,8),%xmm0
mov    %ecx,%eax
ja     1150 <selectionSortDouble+0x50>
mov    %edx,%eax
jmp    1150 <selectionSortDouble+0x50>
ret

LLVM IR (-O0):
define void @selectionSortDouble(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %5
br label %9
9: ; preds = %60, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %63
14: ; preds = %9
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
%17 = load i32, i32* %5
store i32 %17, i32* %6
br label %18
18: ; preds = %37, %14
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %40
22: ; preds = %18
%23 = load double*, double** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double*, double** %3
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fcmp olt double %27, %32
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = load i32, i32* %6
store i32 %35, i32* %7
br label %36
36: ; preds = %34, %22
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %18
40: ; preds = %18
%41 = load double*, double** %3
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
store double %45, double* %8
%46 = load double*, double** %3
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double*, double** %3
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
store double %50, double* %54
%55 = load double, double* %8
%56 = load double*, double** %3
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
store double %55, double* %59
br label %60
60: ; preds = %40
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %9
63: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @selectionSortDouble(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %35
4: ; preds = %2
%5 = add nsw i32 %1, -1
%6 = zext i32 %1 to i64
%7 = zext i32 %5 to i64
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %4, %27
%10 = phi i64 [ 0, %4 ], [ %11, %27 ]
%11 = add nuw nsw i64 %10, 1
%12 = icmp ult i64 %10, %6
%13 = trunc i64 %11 to i32
br i1 %12, label %14, label %27
14: ; preds = %9, %14
%15 = phi i64 [ %25, %14 ], [ %10, %9 ]
%16 = phi i32 [ %24, %14 ], [ %13, %9 ]
%17 = getelementptr inbounds double, double* %0, i64 %15
%18 = load double, double* %17
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = load double, double* %20
%22 = fcmp olt double %18, %21
%23 = trunc i64 %15 to i32
%24 = select i1 %22, i32 %23, i32 %16
%25 = add nuw nsw i64 %15, 1
%26 = icmp eq i64 %25, %8
br i1 %26, label %27, label %14
27: ; preds = %14, %9
%28 = phi i32 [ %13, %9 ], [ %24, %14 ]
%29 = getelementptr inbounds double, double* %0, i64 %10
%30 = load double, double* %29
%31 = sext i32 %28 to i64
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = load double, double* %32
store double %33, double* %29
store double %30, double* %32
%34 = icmp eq i64 %11, %7
br i1 %34, label %35, label %9
35: ; preds = %27, %2
ret void
}