#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, const char *argv[]) {
  int number;
  printf("===== Exercise 12 =====\n");
  printf("Ascending Order!\n");
  printf("Enter the number of the integer array: ");
  scanf("%i", &number);
  int array[number];
  for (int i = 0; i < number; i++) {
    printf("Enter number%i: ", i + 1);
    scanf("%i", &array[i]);
  }
  printf("--> Ascending Order:\n");
  for (int j = 0; j < number; j++) {
    for (int k = j + 1; k < number; k++) {
      if (array[j] > array[k]) {
        int temp = array[j];
        array[j] = array[k];
        array[k] = temp;
      }
    }
    printf("%i \n", array[j]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x41(%rbp)
call   1030 <printf@plt>
mov    -0x41(%rbp),%al
lea    0xec8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x41(%rbp),%al
lea    0xecb(%rip),%rdi
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ec <main+0xcc>
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7a(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a3 <main+0x83>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    129a <main+0x17a>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1273 <main+0x153>
mov    -0x40(%rbp),%rcx
movslq -0x30(%rbp),%rax
mov    (%rcx,%rax,4),%eax
movslq -0x34(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1260 <main+0x140>
mov    -0x40(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    %ecx,-0x38(%rbp)
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%edx
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1265 <main+0x145>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1216 <main+0xf6>
mov    -0x40(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1201 <main+0xe1>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rsp,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11d8 <main+0xa8>
lea    0xe8b(%rip),%r14
lea    0xe81(%rip),%r15
mov    %r12,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
movslq -0x2c(%rbp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11b0 <main+0x80>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    -0x2c(%rbp),%ecx
test   %ecx,%ecx
jle    125f <main+0x12f>
mov    $0x1,%ebx
lea    0xe45(%rip),%r14
xor    %eax,%eax
jmp    121e <main+0xee>
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rax,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq -0x2c(%rbp),%rcx
add    $0x1,%rbx
mov    %r15,%rax
cmp    %rcx,%r15
jge    125f <main+0x12f>
lea    0x1(%rax),%r15
movslq %ecx,%rdx
cmp    %rdx,%r15
jge    1200 <main+0xd0>
mov    %ecx,%ecx
mov    %rbx,%rdx
jmp    1249 <main+0x119>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rdx
cmp    %rdx,%rcx
je     1200 <main+0xd0>
mov    (%r12,%rax,4),%esi
mov    (%r12,%rdx,4),%edi
cmp    %edi,%esi
jle    1240 <main+0x110>
mov    %edi,(%r12,%rax,4)
mov    %esi,(%r12,%rdx,4)
jmp    1240 <main+0x110>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.2 = [40 x i8] c"Enter the number of the integer array: \00"
@.str.3 = [3 x i8] c"%i\00"
@.str.4 = [17 x i8] c"Enter number%i: \00"
@.str.6 = [5 x i8] c"%i \0A\00"
@str = [24 x i8] c"===== Exercise 12 =====\00"
@str.7 = [17 x i8] c"Ascending Order!\00"
@str.8 = [21 x i8] c"--> Ascending Order:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %19, %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 0
br i1 %18, label %30, label %29
19: ; preds = %2, %19
%20 = phi i64 [ %21, %19 ], [ 0, %2 ]
%21 = add nuw nsw i64 %20, 1
%22 = trunc i64 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds i32, i32* %12, i64 %20
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %24)
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %21, %27
br i1 %28, label %19, label %15
29: ; preds = %40, %15
ret i32 0
30: ; preds = %15, %40
%31 = phi i64 [ %34, %40 ], [ 0, %15 ]
%32 = phi i64 [ %47, %40 ], [ 1, %15 ]
%33 = phi i32 [ %44, %40 ], [ %17, %15 ]
%34 = add nuw nsw i64 %31, 1
%35 = sext i32 %33 to i64
%36 = icmp slt i64 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = getelementptr inbounds i32, i32* %12, i64 %31
%39 = zext i32 %33 to i64
br label %48
40: ; preds = %55, %30
%41 = getelementptr inbounds i32, i32* %12, i64 %31
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %34, %45
%47 = add nuw nsw i64 %32, 1
br i1 %46, label %30, label %29
48: ; preds = %37, %55
%49 = phi i64 [ %32, %37 ], [ %56, %55 ]
%50 = load i32, i32* %38
%51 = getelementptr inbounds i32, i32* %12, i64 %49
%52 = load i32, i32* %51
%53 = icmp sgt i32 %50, %52
br i1 %53, label %54, label %55
54: ; preds = %48
store i32 %52, i32* %38
store i32 %50, i32* %51
br label %55
55: ; preds = %48, %54
%56 = add nuw nsw i64 %49, 1
%57 = icmp eq i64 %56, %39
br i1 %57, label %40, label %48
}