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


x86 assembly (clang, -O0):
<Array_selection_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11be <Array_selection_sort+0xae>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118d <Array_selection_sort+0x7d>
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    117a <Array_selection_sort+0x6a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    117f <Array_selection_sort+0x6f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <Array_selection_sort+0x3c>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <Array_selection_sort+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Array_selection_sort>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
jle    117c <Array_selection_sort+0x6c>
mov    %rdi,%rbx
mov    %esi,%r14d
xor    %r15d,%r15d
jmp    1149 <Array_selection_sort+0x39>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rbx,%r15,4),%rdi
movslq %edx,%rax
lea    (%rbx,%rax,4),%rsi
call   1030 <swap@plt>
add    $0x1,%r15
cmp    %r14,%r15
je     117c <Array_selection_sort+0x6c>
mov    %r15,%rax
mov    %r15d,%ecx
jmp    116b <Array_selection_sort+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
mov    %edx,%ecx
cmp    %rax,%r14
je     1130 <Array_selection_sort+0x20>
mov    (%rbx,%rax,4),%esi
movslq %ecx,%rdi
mov    %eax,%edx
cmp    (%rbx,%rdi,4),%esi
jl     1160 <Array_selection_sort+0x50>
mov    %ecx,%edx
jmp    1160 <Array_selection_sort+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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