#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*/ inverseArray(int *, int);
int /*<<< orphan*/ swap(int *, int *);
void selectionSort(int *array, int n, bool isOrderASC) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (array[i] > array[j]) {
        swap(&array[i], &array[j]);
      }
    }
  }
  if (!isOrderASC) {
    inverseArray(array, n);
  }
}


x86 assembly (clang, -O0):
<selectionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bf <selectionSort+0x9f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ac <selectionSort+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1199 <selectionSort+0x79>
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   1040 <swap@plt>
jmp    119e <selectionSort+0x7e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114e <selectionSort+0x2e>
jmp    11b1 <selectionSort+0x91>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <selectionSort+0x19>
cmpl   $0x0,-0x10(%rbp)
jne    11d5 <selectionSort+0xb5>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <inverseArray@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selectionSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,0x1c(%rsp)
mov    %rdi,0x10(%rsp)
mov    %esi,0xc(%rsp)
test   %esi,%esi
jle    11c1 <selectionSort+0xa1>
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%rax
lea    0x4(%rax),%r14
mov    $0x1,%r15d
xor    %r12d,%r12d
mov    %rcx,0x20(%rsp)
jmp    1172 <selectionSort+0x52>
add    $0x1,%r15
add    $0x4,%r14
mov    0x20(%rsp),%rcx
cmp    %rcx,%r12
je     11c1 <selectionSort+0xa1>
mov    %r12,%rax
add    $0x1,%r12
cmp    %rcx,%r12
jae    1160 <selectionSort+0x40>
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,4),%rbp
mov    0x20(%rsp),%r13
mov    %r14,%rbx
jmp    11ad <selectionSort+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x4,%rbx
add    $0xffffffffffffffff,%r13
cmp    %r13,%r15
je     1160 <selectionSort+0x40>
mov    0x0(%rbp),%eax
cmp    (%rbx),%eax
jle    11a0 <selectionSort+0x80>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <swap@plt>
jmp    11a0 <selectionSort+0x80>
cmpl   $0x0,0x1c(%rsp)
je     11d7 <selectionSort+0xb7>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <inverseArray@plt>

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

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