#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 sorting(int array[10]) {
  printf("Now I will sort for you the array in ascending order my Lord!\n");
  int foundIt = 0;
  for (int i = 0; i < 10; ++i) {
    for (int j = i + 1; j < 10; ++j) {
      if (array[i] > array[j]) {
        foundIt = array[i];
        array[i] = array[j];
        array[j] = foundIt;
      }
    }
  }
  printf("\nNow I will print the array for you!\n ");
  for (int i = 0; i < 10; i++) {
    printf("The number in position [%d] is %d\n", i, array[i]);
  }
}


x86 assembly (clang, -O0):
<sorting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    11c9 <sorting+0xb9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11b6 <sorting+0xa6>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11a3 <sorting+0x93>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11a8 <sorting+0x98>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <sorting+0x3b>
jmp    11bb <sorting+0xab>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1138 <sorting+0x28>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    1212 <sorting+0x102>
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11de <sorting+0xce>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorting>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xf1c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
xor    %r8d,%r8d
jmp    114a <sorting+0x2a>
nopl   (%rax)
add    $0x1,%rax
cmp    $0xa,%r8
je     117c <sorting+0x5c>
mov    %r8,%rdx
add    $0x1,%r8
cmp    $0x8,%rdx
ja     1140 <sorting+0x20>
mov    %rax,%rsi
jmp    116a <sorting+0x4a>
nopl   0x0(%rax)
add    $0x1,%rsi
cmp    $0xa,%rsi
je     1140 <sorting+0x20>
mov    (%rbx,%rdx,4),%edi
mov    (%rbx,%rsi,4),%ecx
cmp    %ecx,%edi
jle    1160 <sorting+0x40>
mov    %ecx,(%rbx,%rdx,4)
mov    %edi,(%rbx,%rsi,4)
jmp    1160 <sorting+0x40>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edx
lea    0xe94(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%edx
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%edx
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%edx
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%edx
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rbx),%edx
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%edx
mov    %r14,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rbx),%edx
mov    %r14,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%edx
mov    %r14,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rbx),%edx
mov    %r14,%rdi
mov    $0x9,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [63 x i8] c"Now I will sort for you the array in ascending order my Lord!\0A\00"
@.str.1 = [39 x i8] c"\0ANow I will print the array for you!\0A \00"
@.str.2 = [35 x i8] c"The number in position [%d] is %d\0A\00"
define void @sorting(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %54, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %57
11: ; preds = %8
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
br label %14
14: ; preds = %50, %11
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 10
br i1 %16, label %17, label %53
17: ; preds = %14
%18 = load i32*, i32** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = load i32*, i32** %2
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = icmp sgt i32 %22, %27
br i1 %28, label %29, label %49
29: ; preds = %17
%30 = load i32*, i32** %2
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
store i32 %34, i32* %3
%35 = load i32*, i32** %2
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = load i32*, i32** %2
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
%44 = load i32, i32* %3
%45 = load i32*, i32** %2
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %44, i32* %48
br label %49
49: ; preds = %29, %17
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %14
53: ; preds = %14
br label %54
54: ; preds = %53
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %8
57: ; preds = %8
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %59
59: ; preds = %70, %57
%60 = load i32, i32* %6
%61 = icmp slt i32 %60, 10
br i1 %61, label %62, label %73
62: ; preds = %59
%63 = load i32, i32* %6
%64 = load i32*, i32** %2
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %63, i32 %68)
br label %70
70: ; preds = %62
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
br label %59
73: ; preds = %59
ret void
}

LLVM IR (-O2):
@.str.1 = [39 x i8] c"\0ANow I will print the array for you!\0A \00"
@.str.2 = [35 x i8] c"The number in position [%d] is %d\0A\00"
@str = [62 x i8] c"Now I will sort for you the array in ascending order my Lord!\00"
define void @sorting(i32* nocapture %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
br label %37
3: ; preds = %51, %37
%4 = add nuw nsw i64 %39, 1
%5 = icmp eq i64 %40, 10
br i1 %5, label %6, label %37
6: ; preds = %3
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 %8)
%10 = getelementptr inbounds i32, i32* %0, i64 1
%11 = load i32, i32* %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %11)
%13 = getelementptr inbounds i32, i32* %0, i64 2
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 %14)
%16 = getelementptr inbounds i32, i32* %0, i64 3
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %17)
%19 = getelementptr inbounds i32, i32* %0, i64 4
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 4, i32 %20)
%22 = getelementptr inbounds i32, i32* %0, i64 5
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 %23)
%25 = getelementptr inbounds i32, i32* %0, i64 6
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 6, i32 %26)
%28 = getelementptr inbounds i32, i32* %0, i64 7
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 7, i32 %29)
%31 = getelementptr inbounds i32, i32* %0, i64 8
%32 = load i32, i32* %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 8, i32 %32)
%34 = getelementptr inbounds i32, i32* %0, i64 9
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 9, i32 %35)
ret void
37: ; preds = %1, %3
%38 = phi i64 [ 0, %1 ], [ %40, %3 ]
%39 = phi i64 [ 1, %1 ], [ %4, %3 ]
%40 = add nuw nsw i64 %38, 1
%41 = icmp ult i64 %38, 9
br i1 %41, label %42, label %3
42: ; preds = %37
%43 = getelementptr inbounds i32, i32* %0, i64 %38
br label %44
44: ; preds = %42, %51
%45 = phi i64 [ %39, %42 ], [ %52, %51 ]
%46 = load i32, i32* %43
%47 = getelementptr inbounds i32, i32* %0, i64 %45
%48 = load i32, i32* %47
%49 = icmp sgt i32 %46, %48
br i1 %49, label %50, label %51
50: ; preds = %44
store i32 %48, i32* %43
store i32 %46, i32* %47
br label %51
51: ; preds = %44, %50
%52 = add nuw nsw i64 %45, 1
%53 = icmp eq i64 %52, 10
br i1 %53, label %3, label %44
}