#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*/ qsort(int *, int, int, int (*)());
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int num_of_rand;
  int a, b;
  int compare();
  double mean();
  double median();
  int mode();
  printf("Please enter an integer: ");
  scanf("%d", &num_of_rand);
  srand(time(NULL));
  int rand_array[num_of_rand];
  printf("The unsorted array is: ");
  for (a = 0; a < num_of_rand; a++) {
    rand_array[a] = rand() % 100;
    printf("%d ", rand_array[a]);
  }
  printf("\n");
  printf("The sorted array is: ");
  qsort(rand_array, num_of_rand, sizeof(int), compare);
  for (b = 0; b < num_of_rand; b++) {
    printf("%d ", rand_array[b]);
  }
  printf("\n");
  printf("The mean of the dataset is: %.1lf\n", mean(rand_array, num_of_rand));
  printf("The median of the dataset is: %.1lf\n",
         median(rand_array, num_of_rand));
  printf("The mode of the dataset is: %d\n", mode(rand_array));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
call   1050 <printf@plt>
lea    0xe63(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@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,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1256 <main+0xc6>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    120d <main+0x7d>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x4,%edx
mov    0x2d63(%rip),%rcx
call   1040 <qsort@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12c4 <main+0x134>
mov    -0x28(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1291 <main+0x101>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x0,%al
call   10a0 <mean@plt>
lea    0xd68(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x0,%al
call   1030 <median@plt>
lea    0xd6f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1080 <mode@plt>
mov    %eax,%esi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%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   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe56(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   10a0 <scanf@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    %rsp,%r15
mov    -0x24(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,-0x24(%rbp)
jle    125e <main+0xbe>
lea    0xe24(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10c0 <rand@plt>
movslq %eax,%rsi
imul   $0x51eb851f,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%esi
mov    %esi,(%r12,%rbx,4)
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq -0x24(%rbp),%rax
cmp    %rax,%rbx
jl     1220 <main+0x80>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdca(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x24(%rbp),%esi
mov    0x2d68(%rip),%rcx
mov    %r12,%rdi
mov    $0x4,%edx
call   1050 <qsort@plt>
cmpl   $0x0,-0x24(%rbp)
jle    12bb <main+0x11b>
lea    0xd9b(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq -0x24(%rbp),%rax
cmp    %rax,%rbx
jl     12a0 <main+0x100>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x24(%rbp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   10b0 <mean@plt>
lea    0xd76(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <median@plt>
lea    0xd7e(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <mode@plt>
lea    0xd8b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Please enter an integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"The unsorted array is: \00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [22 x i8] c"The sorted array is: \00"
@.str.6 = [35 x i8] c"The mean of the dataset is: %.1lf\0A\00"
@.str.7 = [37 x i8] c"The median of the dataset is: %.1lf\0A\00"
@.str.8 = [32 x i8] c"The mode of the dataset is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 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 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %5
%14 = alloca i32, i64 %12
store i64 %12, i64* %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %16
16: ; preds = %31, %0
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 100
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %14, i64 %24
store i32 %22, i32* %25
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %14, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %20
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %16
34: ; preds = %16
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%37 = load i32, i32* %2
%38 = call i32 @qsort(i32* %14, i32 %37, i32 4, i32 (...)* @compare)
store i32 0, i32* %4
br label %39
39: ; preds = %49, %34
%40 = load i32, i32* %4
%41 = load i32, i32* %2
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %14, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %43
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %39
52: ; preds = %39
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* %2
%55 = call double (i32*, i32, ...) bitcast (double (...)* @mean to double (i32*, i32, ...)*)(i32* %14, i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), double %55)
%57 = load i32, i32* %2
%58 = call double (i32*, i32, ...) bitcast (double (...)* @median to double (i32*, i32, ...)*)(i32* %14, i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), double %58)
%60 = call i32 (i32*, ...) bitcast (i32 (...)* @mode to i32 (i32*, ...)*)(i32* %14)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i32 %60)
store i32 0, i32* %1
%62 = load i8*, i8** %5
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@.str = [26 x i8] c"Please enter an integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"The unsorted array is: \00"
@.str.3 = [4 x i8] c"%d \00"
@.str.5 = [22 x i8] c"The sorted array is: \00"
@.str.6 = [35 x i8] c"The mean of the dataset is: %.1lf\0A\00"
@.str.7 = [37 x i8] c"The median of the dataset is: %.1lf\0A\00"
@.str.8 = [32 x i8] c"The mode of the dataset is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 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 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = load i32, i32* %1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %0, %14
%15 = phi i64 [ %20, %14 ], [ 0, %0 ]
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 100
%18 = getelementptr inbounds i32, i32* %10, i64 %15
store i32 %17, i32* %18
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%20 = add nuw nsw i64 %15, 1
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %14, label %24
24: ; preds = %14, %0
%25 = call i32 @putchar(i32 10)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%27 = load i32, i32* %1
%28 = call i32 @qsort(i32* %10, i32 %27, i32 4, i32 (...)* @compare)
%29 = load i32, i32* %1
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %24, %31
%32 = phi i64 [ %36, %31 ], [ 0, %24 ]
%33 = getelementptr inbounds i32, i32* %10, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = add nuw nsw i64 %32, 1
%37 = load i32, i32* %1
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %31, label %40
40: ; preds = %31, %24
%41 = call i32 @putchar(i32 10)
%42 = load i32, i32* %1
%43 = call double (i32*, i32, ...) bitcast (double (...)* @mean to double (i32*, i32, ...)*)(i32* %10, i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), double %43)
%45 = load i32, i32* %1
%46 = call double (i32*, i32, ...) bitcast (double (...)* @median to double (i32*, i32, ...)*)(i32* %10, i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), double %46)
%48 = call i32 (i32*, ...) bitcast (i32 (...)* @mode to i32 (i32*, ...)*)(i32* %10)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i32 %48)
ret i32 0
}