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


x86 assembly (clang, -O0):
<selectionsort>:
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    1198 <selectionsort+0x88>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1185 <selectionsort+0x75>
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
jle    1172 <selectionsort+0x62>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <swap@plt>
jmp    1177 <selectionsort+0x67>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <selectionsort+0x2b>
jmp    118a <selectionsort+0x7a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <selectionsort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selectionsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1172 <selectionsort+0x62>
mov    %rdi,%r15
mov    %esi,%r12d
mov    $0x1,%r13d
xor    %ebp,%ebp
jmp    1139 <selectionsort+0x29>
nop
add    $0x1,%r13
cmp    %r12,%rbp
je     1172 <selectionsort+0x62>
mov    %rbp,%r14
add    $0x1,%rbp
cmp    %r12,%rbp
jae    1130 <selectionsort+0x20>
mov    %r13,%rbx
jmp    1159 <selectionsort+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1130 <selectionsort+0x20>
mov    (%r15,%r14,4),%eax
cmp    (%r15,%rbx,4),%eax
jle    1150 <selectionsort+0x40>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <swap@plt>
jmp    1150 <selectionsort+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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