#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 selection_sort(int a[]) {
  int i, j, min_idx;
  for (i = 0; i < 10; i++) {
    min_idx = i;
    for (j = i + 1; j < 10; j++) {
      if (a[j] < a[min_idx]) {
        min_idx = j;
      }
    }
    swap(&a[min_idx], &a[i]);
  }
}


x86 assembly (clang, -O0):
<selection_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11ac <selection_sort+0x9c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    117b <selection_sort+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1168 <selection_sort+0x58>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    116d <selection_sort+0x5d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <selection_sort+0x2c>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <selection_sort+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selection_sort>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x1,%r14d
xor    %r8d,%r8d
jmp    1150 <selection_sort+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r8d,%edx
movslq %edx,%rax
lea    (%rbx,%rax,4),%rdi
lea    (%rbx,%r8,4),%rsi
call   1030 <swap@plt>
add    $0x1,%r14
mov    %r15,%r8
cmp    $0xa,%r15
je     118d <selection_sort+0x7d>
lea    0x1(%r8),%r15
cmp    $0x8,%r8
ja     1130 <selection_sort+0x20>
mov    %r14,%rcx
mov    %r8d,%esi
jmp    117c <selection_sort+0x6c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rcx
mov    %edx,%esi
cmp    $0xa,%rcx
je     1133 <selection_sort+0x23>
mov    (%rbx,%rcx,4),%edi
movslq %esi,%rax
mov    %ecx,%edx
cmp    (%rbx,%rax,4),%edi
jl     1170 <selection_sort+0x60>
mov    %esi,%edx
jmp    1170 <selection_sort+0x60>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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