#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*/ swap(double *, double *);
void selection_sort(double *array, size_t size) {
  for (size_t i = 0; i < size; ++i) {
    size_t min = i;
    for (size_t j = i; j < size; ++j) {
      if (array[j] < array[min]) {
        min = j;
      }
    }
    swap(array + i, array + min);
  }
}


x86 assembly (clang, -O0):
<selection_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ca <selection_sort+0xba>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1196 <selection_sort+0x86>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1180 <selection_sort+0x70>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1185 <selection_sort+0x75>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1146 <selection_sort+0x36>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <selection_sort+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selection_sort>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1170 <selection_sort+0x60>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r15d,%r15d
jmp    1146 <selection_sort+0x36>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rbx,%r15,8),%rdi
lea    (%rbx,%rcx,8),%rsi
call   1030 <swap@plt>
add    $0x1,%r15
cmp    %r14,%r15
je     1170 <selection_sort+0x60>
mov    %r15,%rax
mov    %r15,%rdx
jmp    115c <selection_sort+0x4c>
xchg   %ax,%ax
add    $0x1,%rax
mov    %rcx,%rdx
cmp    %r14,%rax
jae    1130 <selection_sort+0x20>
movsd  (%rbx,%rdx,8),%xmm0
ucomisd (%rbx,%rax,8),%xmm0
mov    %rax,%rcx
ja     1150 <selection_sort+0x40>
mov    %rdx,%rcx
jmp    1150 <selection_sort+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @selection_sort(double* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %6, label %4
4: ; preds = %2, %7
%5 = phi i64 [ %11, %7 ], [ 0, %2 ]
br label %13
6: ; preds = %7, %2
ret void
7: ; preds = %13
%8 = getelementptr inbounds double, double* %0, i64 %5
%9 = getelementptr inbounds double, double* %0, i64 %21
%10 = tail call i32 @swap(double* %8, double* %9)
%11 = add nuw i64 %5, 1
%12 = icmp eq i64 %11, %1
br i1 %12, label %6, label %4
13: ; preds = %4, %13
%14 = phi i64 [ %22, %13 ], [ %5, %4 ]
%15 = phi i64 [ %21, %13 ], [ %5, %4 ]
%16 = getelementptr inbounds double, double* %0, i64 %14
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %0, i64 %15
%19 = load double, double* %18
%20 = fcmp olt double %17, %19
%21 = select i1 %20, i64 %14, i64 %15
%22 = add nuw i64 %14, 1
%23 = icmp ult i64 %22, %1
br i1 %23, label %13, label %7
}