#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);
int /*<<< orphan*/ printf(char *, ...);
void selection_sort(int A[], int start, int end) {
  int x = start, y = start;
  for (y = start; y < end; y++) {
    for (x = y + 1; x <= end; x++) {
      printf("%d %d \t", y, x);
      _swap(A, y, x);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<selection_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b2 <selection_sort+0x92>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1196 <selection_sort+0x76>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <_swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <selection_sort+0x39>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1144 <selection_sort+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selection_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,%esi
jge    1194 <selection_sort+0x64>
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xeb2(%rip),%r15
xchg   %ax,%ax
lea    0x1(%rbx),%r13d
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <_swap@plt>
cmp    %r12d,%ebp
jl     1160 <selection_sort+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13d,%ebx
cmp    %r12d,%r13d
jne    1150 <selection_sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%d %d \09\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @selection_sort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
store i32 %9, i32* %7
%10 = load i32, i32* %5
store i32 %10, i32* %8
%11 = load i32, i32* %5
store i32 %11, i32* %8
br label %12
12: ; preds = %36, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %39
16: ; preds = %12
%17 = load i32, i32* %8
%18 = add nsw i32 %17, 1
store i32 %18, i32* %7
br label %19
19: ; preds = %31, %16
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i32*, i32** %4
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = call i32 @_swap(i32* %27, i32 %28, i32 %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %19
34: ; preds = %19
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %12
39: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%d %d \09\00"
define void @selection_sort(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %17
5: ; preds = %3, %14
%6 = phi i32 [ %7, %14 ], [ %1, %3 ]
%7 = add i32 %6, 1
br label %8
8: ; preds = %5, %8
%9 = phi i32 [ %12, %8 ], [ %7, %5 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
%11 = tail call i32 @_swap(i32* %0, i32 %6, i32 %9)
%12 = add nsw i32 %9, 1
%13 = icmp slt i32 %9, %2
br i1 %13, label %8, label %14
14: ; preds = %8
%15 = tail call i32 @putchar(i32 10)
%16 = icmp eq i32 %7, %2
br i1 %16, label %17, label %5
17: ; preds = %14, %3
ret void
}