#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 selectSort(int arr[]) {
  int i, j, temp, min;
  int pass = 0, comp = 0, swap = 0;
  for (i = 0; i < 40 - 1; i++) {
    pass++;
    min = i;
    for (j = i + 1; j < 40; j++) {
      comp++;
      if (arr[j] < arr[min]) {
        min = j;
      }
    }
    temp = arr[min];
    arr[min] = arr[i];
    arr[i] = temp;
    swap++;
  }
  printf("\n\nSelection Sort:\n");
  printf("Passes: %d\nComparisons: %d\nSwaps: %d\n", pass, comp, swap);
}


x86 assembly (clang, -O0):
<selectSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x27,-0xc(%rbp)
jge    11eb <selectSort+0xdb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x28,-0x10(%rbp)
jge    11a2 <selectSort+0x92>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    118f <selectSort+0x7f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1194 <selectSort+0x84>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115a <selectSort+0x4a>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <selectSort+0x28>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selectSort>:
push   %rax
mov    $0x1,%r9d
xor    %r10d,%r10d
jmp    114e <selectSort+0x2e>
nopl   0x0(%rax)
movslq %r11d,%rax
mov    (%rdi,%rax,4),%ecx
mov    (%rdi,%r10,4),%edx
mov    %edx,(%rdi,%rax,4)
mov    %ecx,(%rdi,%r10,4)
add    $0x1,%r9
mov    %r8,%r10
cmp    $0x27,%r8
je     1180 <selectSort+0x60>
lea    0x1(%r10),%r8
mov    %r9,%rsi
mov    %r10d,%edx
jmp    116d <selectSort+0x4d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rsi
mov    %r11d,%edx
cmp    $0x28,%rsi
je     1130 <selectSort+0x10>
mov    (%rdi,%rsi,4),%ecx
movslq %edx,%rax
mov    %esi,%r11d
cmp    (%rdi,%rax,4),%ecx
jl     1160 <selectSort+0x40>
mov    %edx,%r11d
jmp    1160 <selectSort+0x40>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6d(%rip),%rdi
mov    $0x27,%esi
mov    $0x30c,%edx
mov    $0x27,%ecx
xor    %eax,%eax
pop    %r8
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str.1 = [38 x i8] c"Passes: %d\0AComparisons: %d\0ASwaps: %d\0A\00"
@str = [18 x i8] c"\0A\0ASelection Sort:\00"
define void @selectSort(i32* nocapture %0) {
br label %2
2: ; preds = %20, %1
%3 = phi i64 [ 0, %1 ], [ %5, %20 ]
%4 = phi i64 [ 1, %1 ], [ %26, %20 ]
%5 = add nuw nsw i64 %3, 1
%6 = trunc i64 %3 to i32
br label %7
7: ; preds = %2, %7
%8 = phi i64 [ %4, %2 ], [ %18, %7 ]
%9 = phi i32 [ %6, %2 ], [ %17, %7 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %8
%11 = load i32, i32* %10
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = icmp slt i32 %11, %14
%16 = trunc i64 %8 to i32
%17 = select i1 %15, i32 %16, i32 %9
%18 = add nuw nsw i64 %8, 1
%19 = icmp eq i64 %18, 40
br i1 %19, label %20, label %7
20: ; preds = %7
%21 = sext i32 %17 to i64
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = getelementptr inbounds i32, i32* %0, i64 %3
%25 = load i32, i32* %24
store i32 %25, i32* %22
store i32 %23, i32* %24
%26 = add nuw nsw i64 %4, 1
%27 = icmp eq i64 %5, 39
br i1 %27, label %28, label %2
28: ; preds = %20
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 39, i32 780, i32 39)
ret void
}