#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, int);
void select_sort(int *a, size_t len) {
  int i, j;
  for (i = 0; i < len - 1; i++) {
    for (j = i + 1; j < len; j++) {
      if (a[i] > a[j]) {
        swap(a, i, j);
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<select_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11a4 <select_sort+0x94>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1191 <select_sort+0x81>
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    117e <select_sort+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <swap@plt>
jmp    1183 <select_sort+0x73>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <select_sort+0x35>
jmp    1196 <select_sort+0x86>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <select_sort+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,(%rsp)
je     1182 <select_sort+0x72>
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x1,%ebp
xor    %r13d,%r13d
jmp    114a <select_sort+0x3a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    (%rsp),%r13
je     1182 <select_sort+0x72>
mov    %r13,%r15
add    $0x1,%r13
cmp    %r14,%r13
jae    1140 <select_sort+0x30>
mov    %rbp,%rbx
jmp    1169 <select_sort+0x59>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %r14,%rbx
jae    1140 <select_sort+0x30>
mov    (%r12,%r15,4),%eax
cmp    (%r12,%rbx,4),%eax
jle    1160 <select_sort+0x50>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1030 <swap@plt>
jmp    1160 <select_sort+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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