#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 findSmallestDouble(double *, int, int);
int /*<<< orphan*/ swapDoubleElements(double *, int, int);
void sortDoubleArray(double array[], int n) {
  int lh, rh;
  for (lh = 0; lh < n; lh++) {
    rh = findSmallestDouble(array, lh, n - 1);
    swapDoubleElements(array, lh, rh);
  }
}


x86 assembly (clang, -O0):
<sortDoubleArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1174 <sortDoubleArray+0x54>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1040 <findSmallestDouble@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <swapDoubleElements@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <sortDoubleArray+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortDoubleArray>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1161 <sortDoubleArray+0x41>
mov    %esi,%r14d
mov    %rdi,%rbx
lea    -0x1(%r14),%r15d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1040 <findSmallestDouble@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <swapDoubleElements@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1140 <sortDoubleArray+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sortDoubleArray(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %21, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load double*, double** %3
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = sub nsw i32 %14, 1
%16 = call i32 @findSmallestDouble(double* %12, i32 %13, i32 %15)
store i32 %16, i32* %6
%17 = load double*, double** %3
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = call i32 @swapDoubleElements(double* %17, i32 %18, i32 %19)
br label %21
21: ; preds = %11
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %7
24: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @sortDoubleArray(double* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = add nsw i32 %1, -1
br label %6
6: ; preds = %4, %6
%7 = phi i32 [ 0, %4 ], [ %10, %6 ]
%8 = tail call i32 @findSmallestDouble(double* %0, i32 %7, i32 %5)
%9 = tail call i32 @swapDoubleElements(double* %0, i32 %7, i32 %8)
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %10, %1
br i1 %11, label %12, label %6
12: ; preds = %6, %2
ret void
}