#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 find_minimal_index(int *, int, int);
int /*<<< orphan*/ swap(int *, int, int);
void sort(int data[], int size) {
  int first_unsorted_index = 0;
  const int last_index = size - 1;
  while (first_unsorted_index < last_index) {
    int current_minimal_index =
        find_minimal_index(data, size, first_unsorted_index);
    swap(data, current_minimal_index, first_unsorted_index);
    ++first_unsorted_index;
  }
}


x86 assembly (clang, -O0):
<sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117a <sort+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <find_minimal_index@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113f <sort+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     1161 <sort+0x41>
mov    %esi,%r14d
mov    %rdi,%rbx
lea    -0x1(%r14),%r15d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <find_minimal_index@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1040 <swap@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1140 <sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @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
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %6
br label %10
10: ; preds = %14, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = call i32 @find_minimal_index(i32* %15, i32 %16, i32 %17)
store i32 %18, i32* %7
%19 = load i32*, i32** %3
%20 = load i32, i32* %7
%21 = load i32, i32* %5
%22 = call i32 @swap(i32* %19, i32 %20, i32 %21)
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %10
25: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @sort(i32* %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %11
5: ; preds = %2, %5
%6 = phi i32 [ %9, %5 ], [ 0, %2 ]
%7 = tail call i32 @find_minimal_index(i32* %0, i32 %1, i32 %6)
%8 = tail call i32 @swap(i32* %0, i32 %7, i32 %6)
%9 = add nuw nsw i32 %6, 1
%10 = icmp eq i32 %9, %3
br i1 %10, label %11, label %5
11: ; preds = %5, %2
ret void
}