#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*/ ReverseSort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  int i;
  printf("Please write here the array size \n");
  scanf("%d", &n);
  printf("The dimension of the array is %d\n", n);
  int a[n];
  if (n == 0)
    printf(
        "An empty array has not elements. We can not reverse an empty array\n");
  else {
    printf("Please type the %d elements one by one and push ENTER\n", n);
    for (i = 0; i < n; i++)
      scanf("%d", &a[i]);
    if (n == 1)
      printf("The reversed array is %d\n", a[0]);
    else {
      printf("Loading... \n");
      ReverseSort(a, n);
      printf("Loading... \n");
      for (i = 0; i < n; i++)
        printf("%d ", a[i]);
      printf("\n");
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x31(%rbp)
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x31(%rbp),%al
mov    -0x8(%rbp),%esi
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11b6 <main+0x86>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ae <main+0x17e>
mov    -0x8(%rbp),%esi
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1203 <main+0xd3>
mov    -0x30(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe33(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ce <main+0x9e>
cmpl   $0x1,-0x8(%rbp)
jne    1226 <main+0xf6>
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a9 <main+0x179>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <ReverseSort@plt>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1288 <main+0x158>
mov    -0x30(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1255 <main+0x125>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    12b5 <main+0x185>
jmp    12ae <main+0x17e>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%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
push   %rax
lea    0xf15(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8f(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
je     1277 <main+0x127>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1214 <main+0xc4>
xor    %r13d,%r13d
lea    0xe31(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11e0 <main+0x90>
cmp    $0x1,%eax
jne    1214 <main+0xc4>
mov    (%r14),%esi
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1283 <main+0x133>
lea    0xe81(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    -0x2c(%rbp),%esi
mov    %r14,%rdi
call   1070 <ReverseSort@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    126b <main+0x11b>
lea    0xe33(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1250 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1283 <main+0x133>
lea    0xe2a(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%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 = [35 x i8] c"Please write here the array size \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"The dimension of the array is %d\0A\00"
@.str.3 = [68 x i8] c"An empty array has not elements. We can not reverse an empty array\0A\00"
@.str.4 = [55 x i8] c"Please type the %d elements one by one and push ENTER\0A\00"
@.str.5 = [26 x i8] c"The reversed array is %d\0A\00"
@.str.6 = [13 x i8] c"Loading... \0A\00"
@.str.7 = [4 x i8] c"%d \00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i32, i64 %12
store i64 %12, i64* %5
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
br label %62
19: ; preds = %0
%20 = load i32, i32* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 %20)
store i32 0, i32* %3
br label %22
22: ; preds = %31, %19
%23 = load i32, i32* %3
%24 = load i32, i32* %2
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %14, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
br label %31
31: ; preds = %26
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %22
34: ; preds = %22
%35 = load i32, i32* %2
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = getelementptr inbounds i32, i32* %14, i64 0
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %39)
br label %61
41: ; preds = %34
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%43 = load i32, i32* %2
%44 = call i32 @ReverseSort(i32* %14, i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %46
46: ; preds = %56, %41
%47 = load i32, i32* %3
%48 = load i32, i32* %2
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %59
50: ; preds = %46
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %14, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %50
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %46
59: ; preds = %46
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %1
store i32 1, i32* %6
br label %63
61: ; preds = %37
br label %62
62: ; preds = %61, %17
store i32 0, i32* %6
br label %63
63: ; preds = %62, %59
%64 = load i8*, i8** %4
%65 = load i32, i32* %6
switch i32 %65, label %68 [
i32 0, label %66
i32 1, label %66
]
66: ; preds = %63, %63
%67 = load i32, i32* %1
ret i32 %67
68: ; preds = %63
unreachable
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"The dimension of the array is %d\0A\00"
@.str.4 = [55 x i8] c"Please type the %d elements one by one and push ENTER\0A\00"
@.str.5 = [26 x i8] c"The reversed array is %d\0A\00"
@.str.7 = [4 x i8] c"%d \00"
@str = [34 x i8] c"Please write here the array size \00"
@str.10 = [12 x i8] c"Loading... \00"
@str.11 = [67 x i8] c"An empty array has not elements. We can not reverse an empty array\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.11, i64 0, i64 0))
br label %50
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %15, %19
%20 = phi i64 [ %23, %19 ], [ 0, %15 ]
%21 = getelementptr inbounds i32, i32* %10, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = add nuw nsw i64 %20, 1
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %19, label %27
27: ; preds = %19
%28 = icmp eq i32 %24, 1
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i32, i32* %10
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %30)
br label %50
32: ; preds = %15, %27
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
%34 = load i32, i32* %1
%35 = call i32 @ReverseSort(i32* %10, i32 %34)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
%37 = load i32, i32* %1
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %32, %39
%40 = phi i64 [ %44, %39 ], [ 0, %32 ]
%41 = getelementptr inbounds i32, i32* %10, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i64 %40, 1
%45 = load i32, i32* %1
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %39, label %48
48: ; preds = %39, %32
%49 = call i32 @putchar(i32 10)
br label %50
50: ; preds = %13, %29, %48
ret i32 0
}