#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 *, ...);
void main() {
  int orders[10] = {8, 27, 30, 4, 5, 2, 17, 19, 24, 35};
  int i, j, amount = 10, min, ex, position;
  printf("Order before:");
  for (i = 0; i < amount; i++) {
    printf("%5d", orders[i]);
  }
  for (i = 0; i < amount - 1; i++) {
    min = orders[i];
    for (j = i + 1; j < amount; j++) {
      if (orders[j] < min) {
        min = orders[j];
        position = j;
      }
    }
    ex = orders[position];
    orders[position] = orders[i];
    orders[i] = ex;
  }
  printf("\nOrder after:");
  for (i = 0; i < amount; i++) {
    printf("%5d", orders[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x30(%rbp),%rdi
lea    0xecd(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0xa,-0x3c(%rbp)
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1189 <main+0x69>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1159 <main+0x39>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    122a <main+0x10a>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    11f6 <main+0xd6>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
cmp    -0x40(%rbp),%eax
jge    11e3 <main+0xc3>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    11e8 <main+0xc8>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11b5 <main+0x95>
movslq -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x44(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
movslq -0x48(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x44(%rbp),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1190 <main+0x70>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    126f <main+0x14f>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    123f <main+0x11f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xeff(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xee3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec7(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xee4(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee1(%rip),%r14
mov    $0x8,%ebp
mov    %r14,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x1b,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x11,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x13,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x18,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x23,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%r15),%rdx
mov    %rax,%rsi
mov    %ebp,%edi
nopl   0x0(%rax)
mov    (%rsp,%rsi,4),%ebx
cmp    %edi,%ebx
cmovl  %ebx,%edi
cmovl  %esi,%ecx
add    $0x1,%rsi
cmp    $0xa,%rsi
jne    1210 <main+0x100>
movslq %ecx,%rsi
mov    (%rsp,%rsi,4),%edi
mov    %ebp,(%rsp,%rsi,4)
mov    %edi,(%rsp,%r15,4)
cmp    $0x9,%rdx
je     1244 <main+0x134>
add    $0x1,%rax
mov    (%rsp,%rdx,4),%ebp
mov    %rdx,%r15
jmp    1200 <main+0xf0>
lea    0xdef(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%esi
lea    0xdda(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

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

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