#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*/ printf(char *, ...);
void SelectionSort(int a[], int array_size) {
  int x, index_of_min, y, temp, k;
  for (x = 0; x < array_size; x++) {
    int index_of_min = x;
    for (y = x; y < array_size; y++) {
      if (a[index_of_min] > a[y])
        index_of_min = y;
    }
    int temp = a[x];
    a[x] = a[index_of_min];
    a[index_of_min] = temp;
    printf("[ ");
    for (k = 0; k < array_size; ++k) {
      printf("%d", a[k]);
      if (k != array_size - 1)
        printf(", ");
    }
    printf(" ]\n");
  }
  if ('T' < 's')
    printf("T < s\n");
  else
    printf("FAIL\n");
}


x86 assembly (clang, -O0):
<SelectionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1239 <SelectionSort+0x129>
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117f <SelectionSort+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    116c <SelectionSort+0x5c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1171 <SelectionSort+0x61>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <SelectionSort+0x2e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121d <SelectionSort+0x10d>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     120a <SelectionSort+0xfa>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <SelectionSort+0xff>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c6 <SelectionSort+0xb6>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <SelectionSort+0x16>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SelectionSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1200 <SelectionSort+0xe0>
mov    %rdi,%rbx
lea    -0x1(%rsi),%ebp
mov    %esi,%r14d
lea    0xec0(%rip),%r15
xor    %r12d,%r12d
jmp    1169 <SelectionSort+0x49>
nopl   0x0(%rax,%rax,1)
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r12
cmp    %r14,%r12
je     1200 <SelectionSort+0xe0>
mov    %r12,%rax
mov    %r12d,%ecx
jmp    118b <SelectionSort+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
mov    %edx,%ecx
cmp    %rax,%r14
je     11a0 <SelectionSort+0x80>
movslq %ecx,%rdx
mov    (%rbx,%rdx,4),%esi
mov    %eax,%edx
cmp    (%rbx,%rax,4),%esi
jg     1180 <SelectionSort+0x60>
mov    %ecx,%edx
jmp    1180 <SelectionSort+0x60>
nopl   0x0(%rax)
mov    (%rbx,%r12,4),%eax
movslq %edx,%rcx
mov    (%rbx,%rcx,4),%edx
mov    %edx,(%rbx,%r12,4)
mov    %eax,(%rbx,%rcx,4)
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %r13d,%r13d
jmp    11dd <SelectionSort+0xbd>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
cmp    %r13,%r14
je     1150 <SelectionSort+0x30>
mov    (%rbx,%r13,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r13,%rbp
je     11d0 <SelectionSort+0xb0>
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d0 <SelectionSort+0xb0>
lea    0xe02(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"[ \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c", \00"
@.str.3 = [4 x i8] c" ]\0A\00"
@.str.4 = [7 x i8] c"T < s\0A\00"
define void @SelectionSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %12
12: ; preds = %85, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %88
16: ; preds = %12
%17 = load i32, i32* %5
store i32 %17, i32* %10
%18 = load i32, i32* %5
store i32 %18, i32* %7
br label %19
19: ; preds = %38, %16
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %41
23: ; preds = %19
%24 = load i32*, i32** %3
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %3
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = icmp sgt i32 %28, %33
br i1 %34, label %35, label %37
35: ; preds = %23
%36 = load i32, i32* %7
store i32 %36, i32* %10
br label %37
37: ; preds = %35, %23
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %19
41: ; preds = %19
%42 = load i32*, i32** %3
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
store i32 %46, i32* %11
%47 = load i32*, i32** %3
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = load i32*, i32** %3
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
store i32 %51, i32* %55
%56 = load i32, i32* %11
%57 = load i32*, i32** %3
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
store i32 %56, i32* %60
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %9
br label %62
62: ; preds = %80, %41
%63 = load i32, i32* %9
%64 = load i32, i32* %4
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %83
66: ; preds = %62
%67 = load i32*, i32** %3
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = load i32, i32* %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %9
%74 = load i32, i32* %4
%75 = sub nsw i32 %74, 1
%76 = icmp ne i32 %73, %75
br i1 %76, label %77, label %79
77: ; preds = %66
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %79
79: ; preds = %77, %66
br label %80
80: ; preds = %79
%81 = load i32, i32* %9
%82 = add nsw i32 %81, 1
store i32 %82, i32* %9
br label %62
83: ; preds = %62
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %85
85: ; preds = %83
%86 = load i32, i32* %5
%87 = add nsw i32 %86, 1
store i32 %87, i32* %5
br label %12
88: ; preds = %12
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"[ \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c", \00"
@str = [6 x i8] c"T < s\00"
@str.5 = [3 x i8] c" ]\00"
define void @SelectionSort(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %46
4: ; preds = %2
%5 = add nsw i32 %1, -1
%6 = zext i32 %5 to i64
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %42, %4
%9 = phi i64 [ 0, %4 ], [ %44, %42 ]
%10 = trunc i64 %9 to i32
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ %9, %8 ], [ %22, %11 ]
%13 = phi i32 [ %10, %8 ], [ %21, %11 ]
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = getelementptr inbounds i32, i32* %0, i64 %12
%18 = load i32, i32* %17
%19 = icmp sgt i32 %16, %18
%20 = trunc i64 %12 to i32
%21 = select i1 %19, i32 %20, i32 %13
%22 = add nuw nsw i64 %12, 1
%23 = icmp eq i64 %22, %7
br i1 %23, label %24, label %11
24: ; preds = %11
%25 = getelementptr inbounds i32, i32* %0, i64 %9
%26 = load i32, i32* %25
%27 = sext i32 %21 to i64
%28 = getelementptr inbounds i32, i32* %0, i64 %27
%29 = load i32, i32* %28
store i32 %29, i32* %25
store i32 %26, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %24, %39
%32 = phi i64 [ 0, %24 ], [ %40, %39 ]
%33 = getelementptr inbounds i32, i32* %0, i64 %32
%34 = load i32, i32* %33
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = icmp eq i64 %32, %6
br i1 %36, label %39, label %37
37: ; preds = %31
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %31, %37
%40 = add nuw nsw i64 %32, 1
%41 = icmp eq i64 %40, %7
br i1 %41, label %42, label %31
42: ; preds = %39
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%44 = add nuw nsw i64 %9, 1
%45 = icmp eq i64 %44, %7
br i1 %45, label %46, label %8
46: ; preds = %42, %2
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret void
}