#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*/ compare_exchg(int *, int *);
void selection_sort_array(int a[], int lo, int hi) {
  int iter1 = 0;
  int iter2 = 0;
  for (iter1 = lo + 1; iter1 < hi; iter1++) {
    for (iter2 = iter1; iter2 > lo; iter2--) {
      compare_exchg(&a[iter2 - 1], &a[iter2]);
    }
  };
}


x86 assembly (clang, -O0):
<selection_sort_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119f <selection_sort_array+0x8f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    118c <selection_sort_array+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <compare_exchg@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <selection_sort_array+0x3b>
jmp    1191 <selection_sort_array+0x81>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <selection_sort_array+0x29>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selection_sort_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
lea    0x1(%r15),%eax
mov    %edx,0x4(%rsp)
cmp    %edx,%eax
jge    117a <selection_sort_array+0x6a>
movslq %eax,%r14
movslq %r15d,%rbx
lea    (%rdi,%r14,4),%r13
jmp    114f <selection_sort_array+0x3f>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
add    $0x4,%r13
cmp    0x4(%rsp),%r14d
jge    117a <selection_sort_array+0x6a>
cmp    %r15d,%r14d
jle    1140 <selection_sort_array+0x30>
mov    %r13,%rsi
mov    %r14,%r12
nopw   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r12
lea    -0x4(%rsi),%rbp
mov    %rbp,%rdi
call   1030 <compare_exchg@plt>
mov    %rbp,%rsi
cmp    %rbx,%r12
jg     1160 <selection_sort_array+0x50>
jmp    1140 <selection_sort_array+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @selection_sort_array(i32* %0, i32 %1, i32 %2) {
%4 = add i32 %1, 1
%5 = icmp slt i32 %4, %2
br i1 %5, label %6, label %24
6: ; preds = %3
%7 = sext i32 %4 to i64
%8 = sext i32 %1 to i64
br label %13
9: ; preds = %17, %13
%10 = add nsw i64 %14, 1
%11 = trunc i64 %10 to i32
%12 = icmp slt i32 %11, %2
br i1 %12, label %13, label %24
13: ; preds = %6, %9
%14 = phi i64 [ %7, %6 ], [ %10, %9 ]
%15 = trunc i64 %14 to i32
%16 = icmp sgt i32 %15, %1
br i1 %16, label %17, label %9
17: ; preds = %13, %17
%18 = phi i64 [ %19, %17 ], [ %14, %13 ]
%19 = add nsw i64 %18, -1
%20 = getelementptr inbounds i32, i32* %0, i64 %19
%21 = getelementptr inbounds i32, i32* %0, i64 %18
%22 = tail call i32 @compare_exchg(i32* %20, i32* %21)
%23 = icmp sgt i64 %19, %8
br i1 %23, label %17, label %9
24: ; preds = %9, %3
ret void
}