#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 */
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ swap(double *, double *);
void selectionSort(double arr[], int32_t n) {
  int32_t i, j, min_idx;
  for (i = 0; i < n - 1; i++) {
    min_idx = i;
    for (j = i + 1; j < n; j++)
      if (arr[j] < arr[min_idx])
        min_idx = j;
    swap(&arr[min_idx], &arr[i]);
  }
}


x86 assembly (clang, -O0):
<selectionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c0 <selectionSort+0xb0>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118f <selectionSort+0x7f>
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    117c <selectionSort+0x6c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1181 <selectionSort+0x71>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <selectionSort+0x36>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <selectionSort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selectionSort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%esi
jl     1190 <selectionSort+0x80>
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%r15d
add    $0xffffffff,%r14d
mov    $0x1,%r12d
xor    %eax,%eax
jmp    115e <selectionSort+0x4e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edx
movslq %edx,%rcx
lea    (%rbx,%rcx,8),%rdi
lea    (%rbx,%rax,8),%rsi
call   1030 <swap@plt>
add    $0x1,%r12
mov    %r13,%rax
cmp    %r14,%r13
je     1190 <selectionSort+0x80>
lea    0x1(%rax),%r13
cmp    %r15,%r13
jae    1140 <selectionSort+0x30>
mov    %r12,%rcx
mov    %eax,%esi
jmp    117b <selectionSort+0x6b>
xchg   %ax,%ax
add    $0x1,%rcx
mov    %edx,%esi
cmp    %rcx,%r15
je     1142 <selectionSort+0x32>
movslq %esi,%rdx
movsd  (%rbx,%rdx,8),%xmm0
ucomisd (%rbx,%rcx,8),%xmm0
mov    %ecx,%edx
ja     1170 <selectionSort+0x60>
mov    %esi,%edx
jmp    1170 <selectionSort+0x60>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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