#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int atoi(char *);
scalar_t__ clock();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quicksort(int *, int /*<<< orphan*/, int);
int rand();
int main(int argc, char *argv[]) {
  int N;
  int *A;
  if (argc > 1) {
    N = atoi(argv[1]);
  } else {
    N = 4000000;
  }
  printf("** Filling array with %d random values...\n", N);
  A = (int *)malloc(N * sizeof(int));
  for (int i = 0; i < N; ++i)
    A[i] = rand() % (2 * N);
  printf("** Unsorted values:\n");
  printf("   %d,%d,%d,...,%d,%d,%d\n\n", A[0], A[1], A[2], A[N - 3], A[N - 2],
         A[N - 1]);
  clock_t startTime = clock();
  quicksort(A, 0, N - 1);
  clock_t stopTime = clock();
  double time = (((double)stopTime) - ((double)startTime)) / CLOCKS_PER_SEC;
  printf("** Sort time: %f secs\n\n", time);
  printf("** Sorted values:\n");
  printf("   %d,%d,%d,...,%d,%d,%d\n\n", A[0], A[1], A[2], A[N - 3], A[N - 2],
         A[N - 1]);
  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)
cmpl   $0x1,-0x8(%rbp)
jle    1195 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    119c <main+0x3c>
movl   $0x3d0900,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fc <main+0x9c>
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c7 <main+0x67>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
sub    $0x3,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%r8d
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
sub    $0x2,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%r9d
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%eax
lea    0xde9(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <quicksort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x38(%rbp)
cvtsi2sdq -0x38(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    0x2d49(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xda7(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
sub    $0x3,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%r8d
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
sub    $0x2,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%r9d
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,4),%eax
lea    0xd2a(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x3d0900,%r14d
cmp    $0x2,%edi
jl     1192 <main+0x22>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    0xe67(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x0(,%r14,4),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    11e8 <main+0x78>
lea    (%r14,%r14,1),%r12d
mov    %r14d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idiv   %r12d
mov    %edx,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11d0 <main+0x60>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%esi
mov    0x4(%r15),%edx
mov    0x8(%r15),%ecx
movslq %r14d,%r13
mov    -0xc(%r15,%r13,4),%r8d
mov    -0x8(%r15,%r13,4),%r9d
add    $0xffffffff,%r14d
mov    -0x4(%r15,%r13,4),%eax
mov    %eax,(%rsp)
lea    0xe0c(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r12
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <quicksort@plt>
xor    %eax,%eax
call   1040 <clock@plt>
cvtsi2sd %rax,%xmm0
cvtsi2sd %r12,%xmm1
subsd  %xmm1,%xmm0
mov    0x2d8c(%rip),%rax
divsd  (%rax),%xmm0
lea    0xddf(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xdfd(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%esi
mov    0x4(%r15),%edx
mov    0x8(%r15),%ecx
mov    -0xc(%r15,%r13,4),%r8d
mov    -0x8(%r15,%r13,4),%r9d
mov    -0x4(%r15,%r13,4),%eax
mov    %eax,(%rsp)
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"** Filling array with %d random values...\0A\00"
@.str.1 = [21 x i8] c"** Unsorted values:\0A\00"
@.str.2 = [27 x i8] c" %d,%d,%d,...,%d,%d,%d\0A\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [24 x i8] c"** Sort time: %f secs\0A\0A\00"
@.str.4 = [19 x i8] c"** Sorted values:\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 i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
br label %20
19: ; preds = %2
store i32 4000000, i32* %6
br label %20
20: ; preds = %19, %14
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 4
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i32*
store i32* %28, i32** %7
store i32 0, i32* %8
br label %29
29: ; preds = %42, %20
%30 = load i32, i32* %8
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = call i32 (...) @rand()
%35 = load i32, i32* %6
%36 = mul nsw i32 2, %35
%37 = srem i32 %34, %36
%38 = load i32*, i32** %7
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
br label %42
42: ; preds = %33
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %29
45: ; preds = %29
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%47 = load i32*, i32** %7
%48 = getelementptr inbounds i32, i32* %47, i64 0
%49 = load i32, i32* %48
%50 = load i32*, i32** %7
%51 = getelementptr inbounds i32, i32* %50, i64 1
%52 = load i32, i32* %51
%53 = load i32*, i32** %7
%54 = getelementptr inbounds i32, i32* %53, i64 2
%55 = load i32, i32* %54
%56 = load i32*, i32** %7
%57 = load i32, i32* %6
%58 = sub nsw i32 %57, 3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %56, i64 %59
%61 = load i32, i32* %60
%62 = load i32*, i32** %7
%63 = load i32, i32* %6
%64 = sub nsw i32 %63, 2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %62, i64 %65
%67 = load i32, i32* %66
%68 = load i32*, i32** %7
%69 = load i32, i32* %6
%70 = sub nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %68, i64 %71
%73 = load i32, i32* %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 %52, i32 %55, i32 %61, i32 %67, i32 %73)
%75 = call i64 (...) @clock()
store i64 %75, i64* %9
%76 = load i32*, i32** %7
%77 = load i32, i32* %6
%78 = sub nsw i32 %77, 1
%79 = call i32 @quicksort(i32* %76, i32 0, i32 %78)
%80 = call i64 (...) @clock()
store i64 %80, i64* %10
%81 = load i64, i64* %10
%82 = sitofp i64 %81 to double
%83 = load i64, i64* %9
%84 = sitofp i64 %83 to double
%85 = fsub double %82, %84
%86 = load double, double* @CLOCKS_PER_SEC
%87 = fdiv double %85, %86
store double %87, double* %11
%88 = load double, double* %11
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), double %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%91 = load i32*, i32** %7
%92 = getelementptr inbounds i32, i32* %91, i64 0
%93 = load i32, i32* %92
%94 = load i32*, i32** %7
%95 = getelementptr inbounds i32, i32* %94, i64 1
%96 = load i32, i32* %95
%97 = load i32*, i32** %7
%98 = getelementptr inbounds i32, i32* %97, i64 2
%99 = load i32, i32* %98
%100 = load i32*, i32** %7
%101 = load i32, i32* %6
%102 = sub nsw i32 %101, 3
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i32, i32* %100, i64 %103
%105 = load i32, i32* %104
%106 = load i32*, i32** %7
%107 = load i32, i32* %6
%108 = sub nsw i32 %107, 2
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i32, i32* %106, i64 %109
%111 = load i32, i32* %110
%112 = load i32*, i32** %7
%113 = load i32, i32* %6
%114 = sub nsw i32 %113, 1
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i32, i32* %112, i64 %115
%117 = load i32, i32* %116
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %93, i32 %96, i32 %99, i32 %105, i32 %111, i32 %117)
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"** Filling array with %d random values...\0A\00"
@.str.2 = [27 x i8] c" %d,%d,%d,...,%d,%d,%d\0A\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [24 x i8] c"** Sort time: %f secs\0A\0A\00"
@str = [20 x i8] c"** Unsorted values:\00"
@str.5 = [18 x i8] c"** Sorted values:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 4000000, %2 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = shl i32 %9, 2
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
%14 = icmp sgt i32 %9, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = shl nuw nsw i32 %9, 1
%17 = zext i32 %9 to i64
br label %55
18: ; preds = %55, %8
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* %13
%21 = getelementptr inbounds i32, i32* %13, i64 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds i32, i32* %13, i64 2
%24 = load i32, i32* %23
%25 = add nsw i32 %9, -3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %13, i64 %26
%28 = load i32, i32* %27
%29 = add nsw i32 %9, -2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %13, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %9, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %13, i64 %34
%36 = load i32, i32* %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %22, i32 %24, i32 %28, i32 %32, i32 %36)
%38 = tail call i64 (...) @clock()
%39 = tail call i32 @quicksort(i32* %13, i32 0, i32 %33)
%40 = tail call i64 (...) @clock()
%41 = sitofp i64 %40 to double
%42 = sitofp i64 %38 to double
%43 = fsub double %41, %42
%44 = load double, double* @CLOCKS_PER_SEC
%45 = fdiv double %43, %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), double %45)
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%48 = load i32, i32* %13
%49 = load i32, i32* %21
%50 = load i32, i32* %23
%51 = load i32, i32* %27
%52 = load i32, i32* %31
%53 = load i32, i32* %35
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %49, i32 %50, i32 %51, i32 %52, i32 %53)
ret i32 0
55: ; preds = %15, %55
%56 = phi i64 [ 0, %15 ], [ %60, %55 ]
%57 = tail call i32 (...) @rand()
%58 = srem i32 %57, %16
%59 = getelementptr inbounds i32, i32* %13, i64 %56
store i32 %58, i32* %59
%60 = add nuw nsw i64 %56, 1
%61 = icmp eq i64 %60, %17
br i1 %61, label %18, label %55
}