#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 RAND_MAX;
int /*<<< orphan*/ printArray(double *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quick_sort(double *, int /*<<< orphan*/, int, int);
double rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  double srcdata[10];
  int idx, jdx;
  srand(time(NULL));
  for (idx = 0; idx < 10; idx++) {
    srcdata[idx] = rand() * 1.0 / RAND_MAX;
  }
  printArray(srcdata);
  printf("\nQuick sort algorithm with original partition pivot\n");
  quick_sort(srcdata, 0, 10 - 1, 0);
  printArray(srcdata);
  printf("\nQuick sort algorithm with randomized partition pivot\n");
  for (idx = 0; idx < 10; idx++) {
    srcdata[idx] = rand() * 1.0 / RAND_MAX;
  }
  printArray(srcdata);
  quick_sort(srcdata, 0, 10 - 1, 1);
  printArray(srcdata);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    11c6 <main+0x66>
mov    $0x0,%al
call   1080 <rand@plt>
movsd  0xe61(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e3e(%rip),%rax
divsd  (%rax),%xmm0
movslq -0x64(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1186 <main+0x26>
lea    -0x60(%rbp),%rdi
call   1070 <printArray@plt>
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
xor    %ecx,%ecx
mov    $0x9,%edx
mov    %ecx,%esi
call   1060 <quick_sort@plt>
lea    -0x60(%rbp),%rdi
call   1070 <printArray@plt>
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    1249 <main+0xe9>
mov    $0x0,%al
call   1080 <rand@plt>
movsd  0xdde(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2dbb(%rip),%rax
divsd  (%rax),%xmm0
movslq -0x64(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1209 <main+0xa9>
lea    -0x60(%rbp),%rdi
call   1070 <printArray@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x1,%ecx
call   1060 <quick_sort@plt>
lea    -0x60(%rbp),%rdi
call   1070 <printArray@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1080 <rand@plt>
movaps %xmm0,0x10(%rsp)
mov    0x2e60(%rip),%rbx
movsd  (%rbx),%xmm0
movapd %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd 0x10(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd (%rsp),%xmm0
movhpd (%rbx),%xmm0
divpd  %xmm0,%xmm1
movapd %xmm1,0x20(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd %xmm0,(%rsp)
movsd  (%rbx),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd (%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
movhpd (%rbx),%xmm0
divpd  %xmm0,%xmm1
movapd %xmm1,0x30(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd %xmm0,(%rsp)
movsd  (%rbx),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd (%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
movhpd (%rbx),%xmm0
divpd  %xmm0,%xmm1
movapd %xmm1,0x40(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd %xmm0,(%rsp)
movsd  (%rbx),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd (%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
movhpd (%rbx),%xmm0
divpd  %xmm0,%xmm1
movapd %xmm1,0x50(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd %xmm0,(%rsp)
movsd  (%rbx),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
movapd (%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
movhpd (%rbx),%xmm0
divpd  %xmm0,%xmm1
movapd %xmm1,0x60(%rsp)
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1070 <printArray@plt>
lea    0xd4f(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x9,%edx
xor    %ecx,%ecx
call   1060 <quick_sort@plt>
mov    %r14,%rdi
call   1070 <printArray@plt>
lea    0xd5e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x28(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x30(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x38(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x40(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x48(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x50(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x58(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x60(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
divsd  (%rbx),%xmm0
movsd  %xmm0,0x68(%rsp)
mov    %r14,%rdi
call   1070 <printArray@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x9,%edx
mov    $0x1,%ecx
call   1060 <quick_sort@plt>
mov    %r14,%rdi
call   1070 <printArray@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
@.str = [53 x i8] c"\0AQuick sort algorithm with original partition pivot\0A\00"
@.str.1 = [55 x i8] c"\0AQuick sort algorithm with randomized partition pivot\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x double]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
store i32 0, i32* %3
br label %7
7: ; preds = %18, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = call double (...) @rand()
%12 = fmul double %11, 1.000000e+00
%13 = load double, double* @RAND_MAX
%14 = fdiv double %12, %13
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 %16
store double %14, double* %17
br label %18
18: ; preds = %10
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %7
21: ; preds = %7
%22 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%23 = call i32 @printArray(double* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%25 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%26 = call i32 @quick_sort(double* %25, i32 0, i32 9, i32 0)
%27 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%28 = call i32 @printArray(double* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %30
30: ; preds = %41, %21
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 10
br i1 %32, label %33, label %44
33: ; preds = %30
%34 = call double (...) @rand()
%35 = fmul double %34, 1.000000e+00
%36 = load double, double* @RAND_MAX
%37 = fdiv double %35, %36
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 %39
store double %37, double* %40
br label %41
41: ; preds = %33
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %30
44: ; preds = %30
%45 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%46 = call i32 @printArray(double* %45)
%47 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%48 = call i32 @quick_sort(double* %47, i32 0, i32 9, i32 1)
%49 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%50 = call i32 @printArray(double* %49)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@str = [52 x i8] c"\0AQuick sort algorithm with original partition pivot\00"
@str.2 = [54 x i8] c"\0AQuick sort algorithm with randomized partition pivot\00"
define i32 @main() {
%1 = alloca [10 x double]
%2 = bitcast [10 x double]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call double (...) @rand()
%6 = load double, double* @RAND_MAX
%7 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 0
%8 = tail call double (...) @rand()
%9 = load double, double* @RAND_MAX
%10 = insertelement <2 x double> poison, double %5, i64 0
%11 = insertelement <2 x double> %10, double %8, i64 1
%12 = insertelement <2 x double> poison, double %6, i64 0
%13 = insertelement <2 x double> %12, double %9, i64 1
%14 = fdiv <2 x double> %11, %13
%15 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 1
%16 = bitcast [10 x double]* %1 to <2 x double>*
store <2 x double> %14, <2 x double>* %16
%17 = tail call double (...) @rand()
%18 = load double, double* @RAND_MAX
%19 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 2
%20 = tail call double (...) @rand()
%21 = load double, double* @RAND_MAX
%22 = insertelement <2 x double> poison, double %17, i64 0
%23 = insertelement <2 x double> %22, double %20, i64 1
%24 = insertelement <2 x double> poison, double %18, i64 0
%25 = insertelement <2 x double> %24, double %21, i64 1
%26 = fdiv <2 x double> %23, %25
%27 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 3
%28 = bitcast double* %19 to <2 x double>*
store <2 x double> %26, <2 x double>* %28
%29 = tail call double (...) @rand()
%30 = load double, double* @RAND_MAX
%31 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 4
%32 = tail call double (...) @rand()
%33 = load double, double* @RAND_MAX
%34 = insertelement <2 x double> poison, double %29, i64 0
%35 = insertelement <2 x double> %34, double %32, i64 1
%36 = insertelement <2 x double> poison, double %30, i64 0
%37 = insertelement <2 x double> %36, double %33, i64 1
%38 = fdiv <2 x double> %35, %37
%39 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 5
%40 = bitcast double* %31 to <2 x double>*
store <2 x double> %38, <2 x double>* %40
%41 = tail call double (...) @rand()
%42 = load double, double* @RAND_MAX
%43 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 6
%44 = tail call double (...) @rand()
%45 = load double, double* @RAND_MAX
%46 = insertelement <2 x double> poison, double %41, i64 0
%47 = insertelement <2 x double> %46, double %44, i64 1
%48 = insertelement <2 x double> poison, double %42, i64 0
%49 = insertelement <2 x double> %48, double %45, i64 1
%50 = fdiv <2 x double> %47, %49
%51 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 7
%52 = bitcast double* %43 to <2 x double>*
store <2 x double> %50, <2 x double>* %52
%53 = tail call double (...) @rand()
%54 = load double, double* @RAND_MAX
%55 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 8
%56 = tail call double (...) @rand()
%57 = load double, double* @RAND_MAX
%58 = insertelement <2 x double> poison, double %53, i64 0
%59 = insertelement <2 x double> %58, double %56, i64 1
%60 = insertelement <2 x double> poison, double %54, i64 0
%61 = insertelement <2 x double> %60, double %57, i64 1
%62 = fdiv <2 x double> %59, %61
%63 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 9
%64 = bitcast double* %55 to <2 x double>*
store <2 x double> %62, <2 x double>* %64
%65 = call i32 @printArray(double* %7)
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%67 = call i32 @quick_sort(double* %7, i32 0, i32 9, i32 0)
%68 = call i32 @printArray(double* %7)
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.2, i64 0, i64 0))
%70 = call double (...) @rand()
%71 = load double, double* @RAND_MAX
%72 = fdiv double %70, %71
store double %72, double* %7
%73 = call double (...) @rand()
%74 = load double, double* @RAND_MAX
%75 = fdiv double %73, %74
store double %75, double* %15
%76 = call double (...) @rand()
%77 = load double, double* @RAND_MAX
%78 = fdiv double %76, %77
store double %78, double* %19
%79 = call double (...) @rand()
%80 = load double, double* @RAND_MAX
%81 = fdiv double %79, %80
store double %81, double* %27
%82 = call double (...) @rand()
%83 = load double, double* @RAND_MAX
%84 = fdiv double %82, %83
store double %84, double* %31
%85 = call double (...) @rand()
%86 = load double, double* @RAND_MAX
%87 = fdiv double %85, %86
store double %87, double* %39
%88 = call double (...) @rand()
%89 = load double, double* @RAND_MAX
%90 = fdiv double %88, %89
store double %90, double* %43
%91 = call double (...) @rand()
%92 = load double, double* @RAND_MAX
%93 = fdiv double %91, %92
store double %93, double* %51
%94 = call double (...) @rand()
%95 = load double, double* @RAND_MAX
%96 = fdiv double %94, %95
store double %96, double* %55
%97 = call double (...) @rand()
%98 = load double, double* @RAND_MAX
%99 = fdiv double %97, %98
store double %99, double* %63
%100 = call i32 @printArray(double* %7)
%101 = call i32 @quick_sort(double* %7, i32 0, i32 9, i32 1)
%102 = call i32 @printArray(double* %7)
ret i32 0
}