#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(int *, int *);
void select_sort(int array[], size_t array_length) {
  for (int ordered_index = 0; ordered_index < array_length; ++ordered_index) {
    int max_number_index = ordered_index;
    for (int element_index = ordered_index; element_index < array_length;
         ++element_index) {
      if (array[element_index] > array[max_number_index]) {
        max_number_index = element_index;
      }
    }
    swap(array + ordered_index, array + max_number_index);
  }
}


x86 assembly (clang, -O0):
<select_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b5 <select_sort+0xa5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1184 <select_sort+0x74>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1171 <select_sort+0x61>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1176 <select_sort+0x66>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <select_sort+0x31>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <select_sort+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_sort>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     117c <select_sort+0x6c>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r15d,%r15d
jmp    1149 <select_sort+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rbx,%r15,4),%rdi
movslq %edx,%rax
lea    (%rbx,%rax,4),%rsi
call   1030 <swap@plt>
add    $0x1,%r15
cmp    %r14,%r15
je     117c <select_sort+0x6c>
mov    %r15,%rax
mov    %r15d,%ecx
jmp    116b <select_sort+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
mov    %edx,%ecx
cmp    %r14,%rax
jae    1130 <select_sort+0x20>
mov    (%rbx,%rax,4),%esi
movslq %ecx,%rdi
mov    %eax,%edx
cmp    (%rbx,%rdi,4),%esi
jg     1160 <select_sort+0x50>
mov    %ecx,%edx
jmp    1160 <select_sort+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @select_sort(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
store i32 0, i32* %5
br label %8
8: ; preds = %49, %2
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = load i64, i64* %4
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %52
13: ; preds = %8
%14 = load i32, i32* %5
store i32 %14, i32* %6
%15 = load i32, i32* %5
store i32 %15, i32* %7
br label %16
16: ; preds = %36, %13
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = load i64, i64* %4
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %39
21: ; preds = %16
%22 = load i32*, i32** %3
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32*, i32** %3
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = icmp sgt i32 %26, %31
br i1 %32, label %33, label %35
33: ; preds = %21
%34 = load i32, i32* %7
store i32 %34, i32* %6
br label %35
35: ; preds = %33, %21
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %16
39: ; preds = %16
%40 = load i32*, i32** %3
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32*, i32** %3
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = call i32 @swap(i32* %43, i32* %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 @select_sort(i32* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %7, label %4
4: ; preds = %2, %8
%5 = phi i64 [ %13, %8 ], [ 0, %2 ]
%6 = trunc i64 %5 to i32
br label %15
7: ; preds = %8, %2
ret void
8: ; preds = %15
%9 = getelementptr inbounds i32, i32* %0, i64 %5
%10 = sext i32 %25 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = tail call i32 @swap(i32* %9, i32* %11)
%13 = add nuw i64 %5, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %7, label %4
15: ; preds = %4, %15
%16 = phi i64 [ %5, %4 ], [ %26, %15 ]
%17 = phi i32 [ %6, %4 ], [ %25, %15 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %16
%19 = load i32, i32* %18
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i32, i32* %0, i64 %20
%22 = load i32, i32* %21
%23 = icmp sgt i32 %19, %22
%24 = trunc i64 %16 to i32
%25 = select i1 %23, i32 %24, i32 %17
%26 = add nuw i64 %16, 1
%27 = icmp ult i64 %26, %1
br i1 %27, label %15, label %8
}