#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 arr[], int len) {
  int i, j;
  int k;
  for (i = 0; i < len; i++) {
    k = i;
    for (j = i + 1; j < len; j++)
      if (arr[j] < arr[k])
        k = j;
    swap(arr, i, k);
  }
}


x86 assembly (clang, -O0):
<select_sort>:
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    119f <select_sort+0x8f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1182 <select_sort+0x72>
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
jge    116f <select_sort+0x5f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1174 <select_sort+0x64>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <select_sort+0x31>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <select_sort+0x16>
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
test   %esi,%esi
jle    118c <select_sort+0x7c>
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%r13d
xor    %esi,%esi
mov    $0x1,%r15d
jmp    1154 <select_sort+0x44>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <swap@plt>
add    $0x1,%r15
mov    %r12d,%esi
cmp    %r14d,%r12d
je     118c <select_sort+0x7c>
lea    0x1(%rsi),%r12d
mov    %esi,%edx
cmp    %r14d,%r12d
jge    1140 <select_sort+0x30>
mov    %r15,%rax
mov    %esi,%ecx
jmp    117b <select_sort+0x6b>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rax
mov    %edx,%ecx
cmp    %rax,%r13
je     1140 <select_sort+0x30>
mov    (%rbx,%rax,4),%edi
movslq %ecx,%rbp
mov    %eax,%edx
cmp    (%rbx,%rbp,4),%edi
jl     1170 <select_sort+0x60>
mov    %ecx,%edx
jmp    1170 <select_sort+0x60>
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, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %43, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %46
12: ; preds = %8
%13 = load i32, i32* %5
store i32 %13, i32* %7
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %6
br label %16
16: ; preds = %35, %12
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load i32*, i32** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = load i32*, i32** %3
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = icmp slt i32 %25, %30
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = load i32, i32* %6
store i32 %33, i32* %7
br label %34
34: ; preds = %32, %20
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %16
38: ; preds = %16
%39 = load i32*, i32** %3
%40 = load i32, i32* %5
%41 = load i32, i32* %7
%42 = call i32 @swap(i32* %39, i32 %40, i32 %41)
br label %43
43: ; preds = %38
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %8
46: ; preds = %8
ret void
}

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