#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 */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ assert(int);
double clock();
int *create_random_array(unsigned int);
int isSorted(int *, unsigned int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ quick_sort(int *, int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int main(int argc, char *argv[]) {
  assert(argc == 2);
  unsigned length;
  sscanf(argv[1], "%u", &length);
  int *ptr = create_random_array(length + 1);
  double start = clock();
  quick_sort(ptr, 0, length);
  double stop = clock();
  double seconds = (stop - start) / CLOCKS_PER_SEC;
  printf("Time elapsed: %f seconds.\n", seconds);
  assert(isSorted(ptr, length + 1));
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1040 <create_random_array@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1080 <quick_sort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
mov    0x2df3(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xdf9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1090 <isSorted@plt>
mov    %eax,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1060 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe6e(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1070 <sscanf@plt>
mov    0x4(%rsp),%edi
add    $0x1,%edi
call   1040 <create_random_array@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <quick_sort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
subsd  0x8(%rsp),%xmm0
mov    0x2e0e(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
add    $0x1,%esi
mov    %rbx,%rdi
call   1090 <isSorted@plt>
mov    %eax,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [27 x i8] c"Time elapsed: %f seconds.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%19 = load i32, i32* %6
%20 = add i32 %19, 1
%21 = call i32* @create_random_array(i32 %20)
store i32* %21, i32** %7
%22 = call double (...) @clock()
store double %22, double* %8
%23 = load i32*, i32** %7
%24 = load i32, i32* %6
%25 = call i32 @quick_sort(i32* %23, i32 0, i32 %24)
%26 = call double (...) @clock()
store double %26, double* %9
%27 = load double, double* %9
%28 = load double, double* %8
%29 = fsub double %27, %28
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %29, %30
store double %31, double* %10
%32 = load double, double* %10
%33 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %32)
%34 = load i32*, i32** %7
%35 = load i32, i32* %6
%36 = add i32 %35, 1
%37 = call i32 @isSorted(i32* %34, i32 %36)
%38 = call i32 @assert(i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [27 x i8] c"Time elapsed: %f seconds.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = add i32 %11, 1
%13 = call i32* @create_random_array(i32 %12)
%14 = call double (...) @clock()
%15 = load i32, i32* %3
%16 = call i32 @quick_sort(i32* %13, i32 0, i32 %15)
%17 = call double (...) @clock()
%18 = fsub double %17, %14
%19 = load double, double* @CLOCKS_PER_SEC
%20 = fdiv double %18, %19
%21 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %20)
%22 = load i32, i32* %3
%23 = add i32 %22, 1
%24 = call i32 @isSorted(i32* %13, i32 %23)
%25 = call i32 @assert(i32 %24)
ret i32 0
}