#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*/ print_array(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int array[10], i = 0, j;
  printf("Enter the numbers(10) to sort\n");
  for (i = 0; i < 10; i++) {
    scanf("%d", &array[i]);
  }
  printf("\nBefore Sorting:\n");
  print_array(array);
  for (i = 0; i < 10; i++) {
    for (j = i + 1; j < 10; j++) {
      if (array[i] > array[j]) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
      }
    }
  }
  printf("\nAfter Sorting:\n");
  print_array(array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    118c <main+0x5c>
movslq -0x34(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xea6(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1159 <main+0x29>
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <print_array@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    1227 <main+0xf7>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0xa,-0x38(%rbp)
jge    1214 <main+0xe4>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
movslq -0x38(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jle    1201 <main+0xd1>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x3c(%rbp),%ecx
movslq -0x38(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
jmp    1206 <main+0xd6>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11bb <main+0x8b>
jmp    1219 <main+0xe9>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a8 <main+0x78>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <print_array@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0x1c(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0x24(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <print_array@plt>
mov    $0x1,%eax
xor    %ecx,%ecx
jmp    11fa <main+0xca>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    $0xa,%rcx
je     122c <main+0xfc>
mov    %rcx,%rdx
add    $0x1,%rcx
cmp    $0x8,%rdx
ja     11f0 <main+0xc0>
mov    %rax,%rsi
jmp    121a <main+0xea>
nopl   0x0(%rax)
add    $0x1,%rsi
cmp    $0xa,%rsi
je     11f0 <main+0xc0>
mov    (%rsp,%rdx,4),%edi
mov    (%rsp,%rsi,4),%ebx
cmp    %ebx,%edi
jle    1210 <main+0xe0>
mov    %ebx,(%rsp,%rdx,4)
mov    %edi,(%rsp,%rsi,4)
jmp    1210 <main+0xe0>
lea    0xdff(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1040 <print_array@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Enter the numbers(10) to sort\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"\0ABefore Sorting:\0A\00"
@.str.3 = [17 x i8] c"\0AAfter Sorting:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %12
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %13)
br label %15
15: ; preds = %10
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %7
18: ; preds = %7
%19 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%21 = call i32 @print_array(i32* %20)
store i32 0, i32* %3
br label %22
22: ; preds = %62, %18
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 10
br i1 %24, label %25, label %65
25: ; preds = %22
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %28
28: ; preds = %58, %25
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 10
br i1 %30, label %31, label %61
31: ; preds = %28
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = icmp sgt i32 %35, %39
br i1 %40, label %41, label %57
41: ; preds = %31
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %43
%45 = load i32, i32* %44
store i32 %45, i32* %5
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %51
store i32 %49, i32* %52
%53 = load i32, i32* %5
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %55
store i32 %53, i32* %56
br label %57
57: ; preds = %41, %31
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
br label %62
62: ; preds = %61
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
br label %22
65: ; preds = %22
%66 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%67 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%68 = call i32 @print_array(i32* %67)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [30 x i8] c"Enter the numbers(10) to sort\00"
@str.4 = [17 x i8] c"\0ABefore Sorting:\00"
@str.5 = [16 x i8] c"\0AAfter Sorting:\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%25 = call i32 @print_array(i32* %4)
br label %29
26: ; preds = %43, %29
%27 = add nuw nsw i64 %31, 1
%28 = icmp eq i64 %32, 10
br i1 %28, label %46, label %29
29: ; preds = %0, %26
%30 = phi i64 [ 0, %0 ], [ %32, %26 ]
%31 = phi i64 [ 1, %0 ], [ %27, %26 ]
%32 = add nuw nsw i64 %30, 1
%33 = icmp ult i64 %30, 9
br i1 %33, label %34, label %26
34: ; preds = %29
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %30
br label %36
36: ; preds = %34, %43
%37 = phi i64 [ %31, %34 ], [ %44, %43 ]
%38 = load i32, i32* %35
%39 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %37
%40 = load i32, i32* %39
%41 = icmp sgt i32 %38, %40
br i1 %41, label %42, label %43
42: ; preds = %36
store i32 %40, i32* %35
store i32 %38, i32* %39
br label %43
43: ; preds = %36, %42
%44 = add nuw nsw i64 %37, 1
%45 = icmp eq i64 %44, 10
br i1 %45, label %26, label %36
46: ; preds = %26
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%48 = call i32 @print_array(i32* %4)
ret i32 0
}