#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 */
size_t qs_partition(double *list, size_t left, size_t right,
                    size_t pivotIndex) {
  double pivotValue, tmp;
  size_t i, storeIndex;
  pivotValue = list[pivotIndex];
  tmp = list[pivotIndex];
  list[pivotIndex] = list[right];
  list[right] = tmp;
  storeIndex = left;
  for (i = left; i <= right - 1; i++) {
    if (list[i] < pivotValue) {
      tmp = list[storeIndex];
      list[storeIndex] = list[i];
      list[i] = tmp;
      storeIndex++;
    }
  }
  tmp = list[right];
  list[right] = list[storeIndex];
  list[storeIndex] = tmp;
  return storeIndex;
}


x86 assembly (clang, -O0):
<qs_partition>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
ja     1205 <qs_partition+0x105>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ef <qs_partition+0xef>
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11f4 <qs_partition+0xf4>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1174 <qs_partition+0x74>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<qs_partition>:
mov    %rsi,%rax
movsd  (%rdi,%rcx,8),%xmm0
movsd  (%rdi,%rdx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
movsd  %xmm0,(%rdi,%rdx,8)
lea    -0x1(%rdx),%rcx
cmp    %rsi,%rcx
jb     115e <qs_partition+0x5e>
mov    %rax,%rsi
jmp    1139 <qs_partition+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rsi
cmp    %rcx,%rsi
ja     1159 <qs_partition+0x59>
movsd  (%rdi,%rsi,8),%xmm1
ucomisd %xmm1,%xmm0
jbe    1130 <qs_partition+0x30>
movsd  (%rdi,%rax,8),%xmm2
movsd  %xmm1,(%rdi,%rax,8)
movsd  %xmm2,(%rdi,%rsi,8)
add    $0x1,%rax
jmp    1130 <qs_partition+0x30>
movsd  (%rdi,%rdx,8),%xmm0
movsd  (%rdi,%rax,8),%xmm1
movsd  %xmm1,(%rdi,%rdx,8)
movsd  %xmm0,(%rdi,%rax,8)
ret

LLVM IR (-O0):
define i64 @qs_partition(double* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca double*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
%10 = alloca double
%11 = alloca i64
%12 = alloca i64
store double* %0, double** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%13 = load double*, double** %5
%14 = load i64, i64* %8
%15 = getelementptr inbounds double, double* %13, i64 %14
%16 = load double, double* %15
store double %16, double* %9
%17 = load double*, double** %5
%18 = load i64, i64* %8
%19 = getelementptr inbounds double, double* %17, i64 %18
%20 = load double, double* %19
store double %20, double* %10
%21 = load double*, double** %5
%22 = load i64, i64* %7
%23 = getelementptr inbounds double, double* %21, i64 %22
%24 = load double, double* %23
%25 = load double*, double** %5
%26 = load i64, i64* %8
%27 = getelementptr inbounds double, double* %25, i64 %26
store double %24, double* %27
%28 = load double, double* %10
%29 = load double*, double** %5
%30 = load i64, i64* %7
%31 = getelementptr inbounds double, double* %29, i64 %30
store double %28, double* %31
%32 = load i64, i64* %6
store i64 %32, i64* %12
%33 = load i64, i64* %6
store i64 %33, i64* %11
br label %34
34: ; preds = %65, %4
%35 = load i64, i64* %11
%36 = load i64, i64* %7
%37 = sub i64 %36, 1
%38 = icmp ule i64 %35, %37
br i1 %38, label %39, label %68
39: ; preds = %34
%40 = load double*, double** %5
%41 = load i64, i64* %11
%42 = getelementptr inbounds double, double* %40, i64 %41
%43 = load double, double* %42
%44 = load double, double* %9
%45 = fcmp olt double %43, %44
br i1 %45, label %46, label %64
46: ; preds = %39
%47 = load double*, double** %5
%48 = load i64, i64* %12
%49 = getelementptr inbounds double, double* %47, i64 %48
%50 = load double, double* %49
store double %50, double* %10
%51 = load double*, double** %5
%52 = load i64, i64* %11
%53 = getelementptr inbounds double, double* %51, i64 %52
%54 = load double, double* %53
%55 = load double*, double** %5
%56 = load i64, i64* %12
%57 = getelementptr inbounds double, double* %55, i64 %56
store double %54, double* %57
%58 = load double, double* %10
%59 = load double*, double** %5
%60 = load i64, i64* %11
%61 = getelementptr inbounds double, double* %59, i64 %60
store double %58, double* %61
%62 = load i64, i64* %12
%63 = add i64 %62, 1
store i64 %63, i64* %12
br label %64
64: ; preds = %46, %39
br label %65
65: ; preds = %64
%66 = load i64, i64* %11
%67 = add i64 %66, 1
store i64 %67, i64* %11
br label %34
68: ; preds = %34
%69 = load double*, double** %5
%70 = load i64, i64* %7
%71 = getelementptr inbounds double, double* %69, i64 %70
%72 = load double, double* %71
store double %72, double* %10
%73 = load double*, double** %5
%74 = load i64, i64* %12
%75 = getelementptr inbounds double, double* %73, i64 %74
%76 = load double, double* %75
%77 = load double*, double** %5
%78 = load i64, i64* %7
%79 = getelementptr inbounds double, double* %77, i64 %78
store double %76, double* %79
%80 = load double, double* %10
%81 = load double*, double** %5
%82 = load i64, i64* %12
%83 = getelementptr inbounds double, double* %81, i64 %82
store double %80, double* %83
%84 = load i64, i64* %12
ret i64 %84
}

LLVM IR (-O2):
define i64 @qs_partition(double* nocapture %0, i64 %1, i64 %2, i64 %3) {
%5 = getelementptr inbounds double, double* %0, i64 %3
%6 = load double, double* %5
%7 = getelementptr inbounds double, double* %0, i64 %2
%8 = load double, double* %7
store double %8, double* %5
store double %6, double* %7
%9 = add i64 %2, -1
%10 = icmp ult i64 %9, %1
br i1 %10, label %27, label %11
11: ; preds = %4, %21
%12 = phi i64 [ %22, %21 ], [ %1, %4 ]
%13 = phi i64 [ %23, %21 ], [ %1, %4 ]
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = fcmp olt double %15, %6
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = getelementptr inbounds double, double* %0, i64 %12
%19 = load double, double* %18
store double %15, double* %18
store double %19, double* %14
%20 = add i64 %12, 1
br label %21
21: ; preds = %11, %17
%22 = phi i64 [ %20, %17 ], [ %12, %11 ]
%23 = add i64 %13, 1
%24 = icmp ugt i64 %23, %9
br i1 %24, label %25, label %11
25: ; preds = %21
%26 = load double, double* %7
br label %27
27: ; preds = %25, %4
%28 = phi double [ %6, %4 ], [ %26, %25 ]
%29 = phi i64 [ %1, %4 ], [ %22, %25 ]
%30 = getelementptr inbounds double, double* %0, i64 %29
%31 = load double, double* %30
store double %31, double* %7
store double %28, double* %30
ret i64 %29
}