#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*/ exchange(int *, int *);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ print_graph(int *, int, char **);
int /*<<< orphan*/ print_graph_exchange(int *, int, int, int, char **);
void selectoin_sort(int *A, int A_length) {
  int i, j, min;
  char graph[8][8] = {' '};
  print_graph(A, A_length, graph);
  for (i = 0; i < (A_length - 1); i++) {
    min = i;
    for (j = i + 1; j < A_length; j++) {
      if (A[j] < A[min])
        min = j;
    }
    print_graph_exchange(A, A_length, i, min, graph);
    print_array(A, A_length);
    exchange(A + i, A + min);
  }
}


x86 assembly (clang, -O0):
<selectoin_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
movb   $0x20,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x60(%rbp),%rdx
call   1030 <print_graph@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    123e <selectoin_sort+0xee>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11eb <selectoin_sort+0x9b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    11d8 <selectoin_sort+0x88>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11dd <selectoin_sort+0x8d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11aa <selectoin_sort+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    -0x60(%rbp),%r8
call   1070 <print_graph_exchange@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <print_array@plt>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1060 <exchange@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118a <selectoin_sort+0x3a>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selectoin_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movb   $0x20,0x20(%rsp)
lea    0x20(%rsp),%rdx
call   1030 <print_graph@plt>
mov    %rbp,0x8(%rsp)
cmp    $0x2,%ebp
jl     122c <selectoin_sort+0xec>
mov    0x8(%rsp),%rax
lea    -0x1(%rax),%ecx
mov    %rcx,0x10(%rsp)
mov    %eax,%r15d
mov    $0x1,%r13d
xor    %r12d,%r12d
mov    0x8(%rsp),%r14
jmp    11f3 <selectoin_sort+0xb3>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12d,%edx
mov    %ebp,%ecx
lea    0x20(%rsp),%r8
call   1060 <print_graph_exchange@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <print_array@plt>
lea    (%rbx,%r12,4),%rdi
movslq %ebp,%rax
lea    (%rbx,%rax,4),%rsi
call   1050 <exchange@plt>
add    $0x1,%r13
mov    0x18(%rsp),%rax
mov    %rax,%r12
cmp    0x10(%rsp),%rax
je     122c <selectoin_sort+0xec>
lea    0x1(%r12),%rax
mov    %r12d,%ebp
mov    %rax,0x18(%rsp)
cmp    %r15,%rax
jae    11b0 <selectoin_sort+0x70>
mov    %r13,%rax
mov    %r12d,%ecx
jmp    121b <selectoin_sort+0xdb>
nopl   (%rax)
add    $0x1,%rax
mov    %ebp,%ecx
cmp    %rax,%r15
je     11b0 <selectoin_sort+0x70>
mov    (%rbx,%rax,4),%edx
movslq %ecx,%rsi
mov    %eax,%ebp
cmp    (%rbx,%rsi,4),%edx
jl     1210 <selectoin_sort+0xd0>
mov    %ecx,%ebp
jmp    1210 <selectoin_sort+0xd0>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @selectoin_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8 x [8 x i8]]
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = bitcast [8 x [8 x i8]]* %8 to i8*
%10 = bitcast i8* %9 to [8 x [8 x i8]]*
%11 = getelementptr inbounds [8 x [8 x i8]], [8 x [8 x i8]]* %10, i32 0, i32 0
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i32 0, i32 0
store i8 32, i8* %12
%13 = load i32*, i32** %3
%14 = load i32, i32* %4
%15 = getelementptr inbounds [8 x [8 x i8]], [8 x [8 x i8]]* %8, i64 0, i64 0
%16 = bitcast [8 x i8]* %15 to i8**
%17 = call i32 @print_graph(i32* %13, i32 %14, i8** %16)
store i32 0, i32* %5
br label %18
18: ; preds = %69, %2
%19 = load i32, i32* %5
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %72
23: ; preds = %18
%24 = load i32, i32* %5
store i32 %24, i32* %7
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %27
27: ; preds = %46, %23
%28 = load i32, i32* %6
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %49
31: ; preds = %27
%32 = load i32*, i32** %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = load i32*, i32** %3
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = icmp slt i32 %36, %41
br i1 %42, label %43, label %45
43: ; preds = %31
%44 = load i32, i32* %6
store i32 %44, i32* %7
br label %45
45: ; preds = %43, %31
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %27
49: ; preds = %27
%50 = load i32*, i32** %3
%51 = load i32, i32* %4
%52 = load i32, i32* %5
%53 = load i32, i32* %7
%54 = getelementptr inbounds [8 x [8 x i8]], [8 x [8 x i8]]* %8, i64 0, i64 0
%55 = bitcast [8 x i8]* %54 to i8**
%56 = call i32 @print_graph_exchange(i32* %50, i32 %51, i32 %52, i32 %53, i8** %55)
%57 = load i32*, i32** %3
%58 = load i32, i32* %4
%59 = call i32 @print_array(i32* %57, i32 %58)
%60 = load i32*, i32** %3
%61 = load i32, i32* %5
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32*, i32** %3
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = call i32 @exchange(i32* %63, i32* %67)
br label %69
69: ; preds = %49
%70 = load i32, i32* %5
%71 = add nsw i32 %70, 1
store i32 %71, i32* %5
br label %18
72: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @selectoin_sort(i32* %0, i32 %1) {
%3 = alloca [8 x [8 x i8]]
%4 = getelementptr inbounds [8 x [8 x i8]], [8 x [8 x i8]]* %3, i64 0, i64 0, i64 0
store i8 32, i8* %4
%5 = bitcast [8 x [8 x i8]]* %3 to i8**
%6 = call i32 @print_graph(i32* %0, i32 %1, i8** %5)
%7 = icmp sgt i32 %1, 1
br i1 %7, label %8, label %42
8: ; preds = %2
%9 = add nsw i32 %1, -1
%10 = zext i32 %1 to i64
%11 = zext i32 %9 to i64
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %8, %32
%14 = phi i64 [ 0, %8 ], [ %16, %32 ]
%15 = phi i64 [ 1, %8 ], [ %40, %32 ]
%16 = add nuw nsw i64 %14, 1
%17 = icmp ult i64 %16, %10
%18 = trunc i64 %14 to i32
br i1 %17, label %19, label %32
19: ; preds = %13, %19
%20 = phi i64 [ %30, %19 ], [ %15, %13 ]
%21 = phi i32 [ %29, %19 ], [ %18, %13 ]
%22 = getelementptr inbounds i32, i32* %0, i64 %20
%23 = load i32, i32* %22
%24 = sext i32 %21 to i64
%25 = getelementptr inbounds i32, i32* %0, i64 %24
%26 = load i32, i32* %25
%27 = icmp slt i32 %23, %26
%28 = trunc i64 %20 to i32
%29 = select i1 %27, i32 %28, i32 %21
%30 = add nuw nsw i64 %20, 1
%31 = icmp eq i64 %30, %12
br i1 %31, label %32, label %19
32: ; preds = %19, %13
%33 = phi i32 [ %18, %13 ], [ %29, %19 ]
%34 = call i32 @print_graph_exchange(i32* %0, i32 %1, i32 %18, i32 %33, i8** %5)
%35 = call i32 @print_array(i32* %0, i32 %1)
%36 = getelementptr inbounds i32, i32* %0, i64 %14
%37 = sext i32 %33 to i64
%38 = getelementptr inbounds i32, i32* %0, i64 %37
%39 = call i32 @exchange(i32* %36, i32* %38)
%40 = add nuw nsw i64 %15, 1
%41 = icmp eq i64 %16, %11
br i1 %41, label %42, label %13
42: ; preds = %32, %2
ret void
}