#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 minimum(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
void selectionSort(int a[], int size) {
  int i, loc, temp, k;
  for (i = 0; i < size; i++) {
    loc = minimum(a, i, size);
    temp = a[i];
    a[i] = a[loc];
    a[loc] = temp;
    printf("\nResult after Pass %d -->\n", i + 1);
    for (k = 0; k < size; k++) {
      printf(" %d", a[k]);
    }
  }
}


x86 assembly (clang, -O0):
<selectionSort>:
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    11e3 <selectionSort+0xc3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <minimum@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d0 <selectionSort+0xb0>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119f <selectionSort+0x7f>
jmp    11d5 <selectionSort+0xb5>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <selectionSort+0x16>
add    $0x20,%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    11aa <selectionSort+0x8a>
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%ebp
xor    %r12d,%r12d
lea    0xeda(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
call   1030 <minimum@plt>
mov    (%rbx,%r12,4),%ecx
cltq
mov    (%rbx,%rax,4),%edx
mov    %edx,(%rbx,%r12,4)
mov    %ecx,(%rbx,%rax,4)
add    $0x1,%r12
lea    0xe87(%rip),%rdi
mov    %r12d,%esi
call   1040 <printf@plt>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx,%r15,4),%esi
mov    %r13,%rdi
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1190 <selectionSort+0x70>
cmp    %rbp,%r12
jne    1150 <selectionSort+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"\0AResult after Pass %d -->\0A\00"
@.str.1 = [4 x i8] c" %d\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
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %55, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %58
13: ; preds = %9
%14 = load i32*, i32** %3
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = call i32 @minimum(i32* %14, i32 %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32*, i32** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
store i32 %22, i32* %7
%23 = load i32*, i32** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = load i32*, i32** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
%32 = load i32, i32* %7
%33 = load i32*, i32** %3
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
%39 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %38)
store i32 0, i32* %8
br label %40
40: ; preds = %51, %13
%41 = load i32, i32* %8
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %54
44: ; preds = %40
%45 = load i32*, i32** %3
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %40
54: ; preds = %40
br label %55
55: ; preds = %54
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
br label %9
58: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"\0AResult after Pass %d -->\0A\00"
@.str.1 = [4 x i8] c" %d\00"
define void @selectionSort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %27
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %8
6: ; preds = %20
%7 = icmp eq i64 %17, %5
br i1 %7, label %27, label %8
8: ; preds = %6, %4
%9 = phi i64 [ 0, %4 ], [ %17, %6 ]
%10 = trunc i64 %9 to i32
%11 = tail call i32 @minimum(i32* %0, i32 %10, i32 %1)
%12 = getelementptr inbounds i32, i32* %0, i64 %9
%13 = load i32, i32* %12
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
store i32 %16, i32* %12
store i32 %13, i32* %15
%17 = add nuw nsw i64 %9, 1
%18 = trunc i64 %17 to i32
%19 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %8, %20
%21 = phi i64 [ 0, %8 ], [ %25, %20 ]
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %5
br i1 %26, label %6, label %20
27: ; preds = %6, %2
ret void
}