#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*/ printf(char *);
int /*<<< orphan*/ swap(int *, int *);
int selection_sort(int *array, int left, int right) {
  printf("this is selection_sort\r\n");
  int i, j, length = right - left + 1;
  for (i = 0; i < length - 1; i++) {
    for (j = length - 1; j > i; j--) {
      if (array[j - 1] > array[j])
        swap(&array[j], &array[j - 1]);
    }
  }
  return 1;
}


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)
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11e5 <selection_sort+0xc5>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11d2 <selection_sort+0xb2>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11bf <selection_sort+0x9f>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <swap@plt>
jmp    11c4 <selection_sort+0xa4>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    116b <selection_sort+0x4b>
jmp    11d7 <selection_sort+0xb7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <selection_sort+0x31>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selection_sort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
sub    %ebx,%ebp
test   %ebp,%ebp
jle    1191 <selection_sort+0x71>
mov    %ebp,%r15d
lea    (%r14,%r15,4),%r14
xor    %r12d,%r12d
jmp    1159 <selection_sort+0x39>
nopl   (%rax)
add    $0x1,%r12
cmp    %r15,%r12
je     1191 <selection_sort+0x71>
mov    %r14,%rdi
mov    %r15,%rbp
jmp    1178 <selection_sort+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
cmp    %r12,%rbp
jle    1150 <selection_sort+0x30>
add    $0xffffffffffffffff,%rbp
lea    -0x4(%rdi),%rbx
mov    -0x4(%rdi),%eax
cmp    (%rdi),%eax
jle    1170 <selection_sort+0x50>
mov    %rbx,%rsi
call   1040 <swap@plt>
jmp    1170 <selection_sort+0x50>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"this is selection_sort\0D\0A\00"
define i32 @selection_sort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = sub nsw i32 %11, %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %9
store i32 0, i32* %7
br label %15
15: ; preds = %56, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %9
%18 = sub nsw i32 %17, 1
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %59
20: ; preds = %15
%21 = load i32, i32* %9
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %8
br label %23
23: ; preds = %52, %20
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %55
27: ; preds = %23
%28 = load i32*, i32** %4
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %28, i64 %31
%33 = load i32, i32* %32
%34 = load i32*, i32** %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = icmp sgt i32 %33, %38
br i1 %39, label %40, label %51
40: ; preds = %27
%41 = load i32*, i32** %4
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32*, i32** %4
%46 = load i32, i32* %8
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
%50 = call i32 @swap(i32* %44, i32* %49)
br label %51
51: ; preds = %40, %27
br label %52
52: ; preds = %51
%53 = load i32, i32* %8
%54 = add nsw i32 %53, -1
store i32 %54, i32* %8
br label %23
55: ; preds = %23
br label %56
56: ; preds = %55
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %15
59: ; preds = %15
ret i32 1
}

LLVM IR (-O2):
@str = [24 x i8] c"this is selection_sort\0D\00"
define i32 @selection_sort(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%5 = sub i32 %2, %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %27
7: ; preds = %3
%8 = zext i32 %5 to i64
%9 = zext i32 %5 to i64
br label %10
10: ; preds = %24, %7
%11 = phi i64 [ 0, %7 ], [ %25, %24 ]
br label %12
12: ; preds = %10, %22
%13 = phi i64 [ %8, %10 ], [ %14, %22 ]
%14 = add nsw i64 %13, -1
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = getelementptr inbounds i32, i32* %0, i64 %13
%18 = load i32, i32* %17
%19 = icmp sgt i32 %16, %18
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = tail call i32 @swap(i32* %17, i32* %15)
br label %22
22: ; preds = %12, %20
%23 = icmp sgt i64 %14, %11
br i1 %23, label %12, label %24
24: ; preds = %22
%25 = add nuw nsw i64 %11, 1
%26 = icmp eq i64 %25, %9
br i1 %26, label %27, label %10
27: ; preds = %24, %3
ret i32 1
}