#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 double time_t;
struct timeval {
  unsigned int tv_sec;
  double tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ quick_sort(int *, int /*<<< orphan*/, int, unsigned int *);
int /*<<< orphan*/ randomSequence(unsigned int *, int *, int);
int /*<<< orphan*/ stderr;
double time(int /*<<< orphan*/ *);
int main() {
  int i;
  int *arr = (int *)malloc(sizeof(int) * 10000000);
  unsigned int seed = 5;
  struct timeval start, end;
  time_t t1 = time(NULL);
  randomSequence(&seed, arr, 10000000);
  double t2 = time(NULL);
  fprintf(stderr, "Time taken for generation of input = %e\n", t2 - t1);
  t1 = time(NULL);
  gettimeofday(&start, NULL);
  quick_sort(arr, 0, 10000000 - 1, &seed);
  gettimeofday(&end, NULL);
  t2 = time(NULL);
  double delta =
      ((end.tv_sec - start.tv_sec) * 1000000u + end.tv_usec - start.tv_usec) /
      1.e6;
  fprintf(stderr, "Time taken for output = %e .\n", delta);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2625a00,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,-0x64(%rbp)
mov    %eax,%edi
mov    %rdi,-0x58(%rbp)
call   1050 <time@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdi
mov    %rdi,-0x60(%rbp)
mov    $0x989680,%edx
call   1080 <randomSequence@plt>
mov    -0x58(%rbp),%rdi
call   1050 <time@plt>
movsd  %xmm0,-0x48(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
subsd  %xmm1,%xmm0
lea    0xe2d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x58(%rbp),%rdi
call   1050 <time@plt>
mov    -0x58(%rbp),%rsi
movsd  %xmm0,-0x40(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <gettimeofday@plt>
mov    -0x64(%rbp),%esi
mov    -0x60(%rbp),%rcx
mov    -0x10(%rbp),%rdi
mov    $0x98967f,%edx
call   1070 <quick_sort@plt>
mov    -0x58(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1030 <gettimeofday@plt>
mov    -0x58(%rbp),%rdi
call   1050 <time@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    %ecx,%eax
imul   $0xf4240,%eax,%eax
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xdb0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
movsd  -0x50(%rbp),%xmm0
lea    0xdc3(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    $0x2625a00,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movl   $0x5,0x4(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x989680,%edx
call   1080 <randomSequence@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    0x2e32(%rip),%r15
mov    (%r15),%edi
subsd  0x8(%rsp),%xmm0
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <time@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x98967f,%edx
mov    %r14,%rcx
call   1070 <quick_sort@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    0x10(%rsp),%eax
sub    0x20(%rsp),%eax
imul   $0xf4240,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x18(%rsp),%xmm0
subsd  0x28(%rsp),%xmm0
divsd  0xddb(%rip),%xmm0
mov    (%r15),%edi
lea    0xe02(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, double }
@stderr = global i32 0
@.str = [41 x i8] c"Time taken for generation of input = %e\0A\00"
@.str.1 = [30 x i8] c"Time taken for output = %e .\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 0, i32* %1
%10 = call i64 @malloc(i32 40000000)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %3
store i32 5, i32* %4
%12 = call double @time(i32* null)
store double %12, double* %7
%13 = load i32*, i32** %3
%14 = call i32 @randomSequence(i32* %4, i32* %13, i32 10000000)
%15 = call double @time(i32* null)
store double %15, double* %8
%16 = load i32, i32* @stderr
%17 = load double, double* %8
%18 = load double, double* %7
%19 = fsub double %17, %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), double %19)
%21 = call double @time(i32* null)
store double %21, double* %7
%22 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%23 = load i32*, i32** %3
%24 = call i32 @quick_sort(i32* %23, i32 0, i32 9999999, i32* %4)
%25 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%26 = call double @time(i32* null)
store double %26, double* %8
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%30 = load i32, i32* %29
%31 = sub i32 %28, %30
%32 = mul i32 %31, 1000000
%33 = uitofp i32 %32 to double
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%35 = load double, double* %34
%36 = fadd double %33, %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%38 = load double, double* %37
%39 = fsub double %36, %38
%40 = fdiv double %39, 1.000000e+06
store double %40, double* %9
%41 = load i32, i32* @stderr
%42 = load double, double* %9
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), double %42)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, double }
@stderr = global i32 0
@.str = [41 x i8] c"Time taken for generation of input = %e\0A\00"
@.str.1 = [30 x i8] c"Time taken for output = %e .\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = tail call i64 @malloc(i32 40000000)
%5 = inttoptr i64 %4 to i32*
%6 = bitcast i32* %1 to i8*
store i32 5, i32* %1
%7 = bitcast %struct.timeval* %2 to i8*
%8 = bitcast %struct.timeval* %3 to i8*
%9 = tail call double @time(i32* null)
%10 = call i32 @randomSequence(i32* %1, i32* %5, i32 10000000)
%11 = call double @time(i32* null)
%12 = load i32, i32* @stderr
%13 = fsub double %11, %9
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), double %13)
%15 = call double @time(i32* null)
%16 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%17 = call i32 @quick_sort(i32* %5, i32 0, i32 9999999, i32* %1)
%18 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%19 = call double @time(i32* null)
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%23 = load i32, i32* %22
%24 = sub i32 %21, %23
%25 = mul i32 %24, 1000000
%26 = uitofp i32 %25 to double
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%28 = load double, double* %27
%29 = fadd double %28, %26
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%31 = load double, double* %30
%32 = fsub double %29, %31
%33 = fdiv double %32, 1.000000e+06
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), double %33)
ret i32 0
}