#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 */
typedef int /*<<< orphan*/ list;

/* Variables and functions */
int get_min_index(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ swap(int *, int *);
void main() {
  int list[] = {126, 43, 26, 1, 113};
  int int_size = sizeof(int);
  int length = sizeof(list) / int_size;
  int i = 0;
  int j = 0;
  int min_index = 0;
  printf("unsorted = {");
  for (i = 0; i < length; i++) {
    printf("%3d ", list[i]);
  }
  printf("}\n");
  for (i = 0; i < length - 1; i++) {
    min_index = get_min_index(list, i + 1, length - 1);
    if (list[min_index] < list[i])
      swap(&list[i], &list[min_index]);
  }
  printf("sorted   = {");
  for (i = 0; i < length; i++) {
    printf("%3d ", list[i]);
  }
  printf("}\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebc(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x4,-0x24(%rbp)
movslq -0x24(%rbp),%rcx
mov    $0x14,%eax
xor    %edx,%edx
div    %rcx
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11c9 <main+0x99>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1199 <main+0x69>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1253 <main+0x123>
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
mov    -0x28(%rbp),%edx
sub    $0x1,%edx
call   1040 <get_min_index@plt>
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
movslq -0x2c(%rbp),%rcx
cmp    -0x20(%rbp,%rcx,4),%eax
jge    1240 <main+0x110>
movslq -0x2c(%rbp),%rax
lea    -0x20(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
movslq -0x34(%rbp),%rax
lea    -0x20(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
jmp    1245 <main+0x115>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11de <main+0xae>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1298 <main+0x168>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1268 <main+0x138>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0xec5(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb2(%rip),%rbx
mov    %rbx,%rdi
mov    $0x7e,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2b,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1a,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x71,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1050 <get_min_index@plt>
cltq
mov    (%rsp,%rax,4),%ecx
cmp    (%rsp),%ecx
jge    11ee <main+0xae>
lea    (%rsp,%rax,4),%rsi
mov    %rsp,%rdi
call   1060 <swap@plt>
mov    %rsp,%rdi
mov    $0x2,%esi
mov    $0x4,%edx
call   1050 <get_min_index@plt>
cltq
mov    (%rsp,%rax,4),%ecx
cmp    0x4(%rsp),%ecx
jge    1219 <main+0xd9>
lea    0x4(%rsp),%rdi
lea    (%rsp,%rax,4),%rsi
call   1060 <swap@plt>
mov    %rsp,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1050 <get_min_index@plt>
cltq
mov    (%rsp,%rax,4),%ecx
cmp    0x8(%rsp),%ecx
jge    1244 <main+0x104>
lea    0x8(%rsp),%rdi
lea    (%rsp,%rax,4),%rsi
call   1060 <swap@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1050 <get_min_index@plt>
cltq
mov    (%rsp,%rax,4),%ecx
cmp    0xc(%rsp),%ecx
jge    126f <main+0x12f>
lea    0xc(%rsp),%rdi
lea    (%rsp,%rax,4),%rsi
call   1060 <swap@plt>
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
lea    0xd9a(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd63(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.list = [5 x i32] [i32 126, i32 43, i32 26, i32 1, i32 113]
@.str = [13 x i8] c"unsorted = {\00"
@.str.1 = [5 x i8] c"%3d \00"
@.str.2 = [3 x i8] c"}\0A\00"
@.str.3 = [13 x i8] c"sorted = {\00"
define void @main() {
%1 = alloca [5 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [5 x i32]* %1 to i8*
store i32 4, i32* %2
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = udiv i64 20, %9
%11 = trunc i64 %10 to i32
store i32 %11, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %13
13: ; preds = %23, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %17
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %13
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %28
28: ; preds = %58, %26
%29 = load i32, i32* %4
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 1
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %61
33: ; preds = %28
%34 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %3
%38 = sub nsw i32 %37, 1
%39 = call i32 @get_min_index(i32* %34, i32 %36, i32 %38)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = icmp slt i32 %43, %47
br i1 %48, label %49, label %57
49: ; preds = %33
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %51
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %54
%56 = call i32 @swap(i32* %52, i32* %55)
br label %57
57: ; preds = %49, %33
br label %58
58: ; preds = %57
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %28
61: ; preds = %28
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %63
63: ; preds = %73, %61
%64 = load i32, i32* %4
%65 = load i32, i32* %3
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %76
67: ; preds = %63
%68 = load i32, i32* %4
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %67
%74 = load i32, i32* %4
%75 = add nsw i32 %74, 1
store i32 %75, i32* %4
br label %63
76: ; preds = %63
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.main.list = [5 x i32] [i32 126, i32 43, i32 26, i32 1, i32 113]
@.str = [13 x i8] c"unsorted = {\00"
@.str.1 = [5 x i8] c"%3d \00"
@.str.3 = [13 x i8] c"sorted = {\00"
@str.4 = [2 x i8] c"}\00"
define void @main() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 126)
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 43)
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 26)
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 113)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
%14 = call i32 @get_min_index(i32* %4, i32 1, i32 4)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 @swap(i32* %4, i32* %16)
br label %22
22: ; preds = %0, %20
%23 = call i32 @get_min_index(i32* %4, i32 2, i32 4)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @swap(i32* %6, i32* %25)
br label %31
31: ; preds = %29, %22
%32 = call i32 @get_min_index(i32* %4, i32 3, i32 4)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @swap(i32* %8, i32* %34)
br label %40
40: ; preds = %38, %31
%41 = call i32 @get_min_index(i32* %4, i32 4, i32 4)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %10
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = call i32 @swap(i32* %10, i32* %43)
br label %49
49: ; preds = %47, %40
%50 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %4
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %6
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %8
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %10
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %50
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
ret void
}