#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 */
int /*<<< orphan*/ swapDoubles(double *, double *);
size_t partitionDoublesAscending(double *array, size_t low, size_t up) {
  size_t pivot = low + (up - low) / 2;
  double val = array[pivot];
  swapDoubles(&array[pivot], &array[up]);
  size_t i = low;
  size_t j;
  for (j = low; j < up; ++j) {
    if (array[j] <= val) {
      swapDoubles(&array[i++], &array[j]);
    }
  }
  swapDoubles(&array[i], &array[up]);
  return i;
}


x86 assembly (clang, -O0):
<partitionDoublesAscending>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    -0x10(%rbp),%rcx
shr    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swapDoubles@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ee <partitionDoublesAscending+0xde>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11d8 <partitionDoublesAscending+0xc8>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x38(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swapDoubles@plt>
jmp    11dd <partitionDoublesAscending+0xcd>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1180 <partitionDoublesAscending+0x70>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swapDoubles@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partitionDoublesAscending>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rax
sub    %rsi,%rax
shr    %rax
add    %rsi,%rax
lea    (%rdi,%rax,8),%rdi
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    (%r14,%rdx,8),%r12
mov    %r12,%rsi
call   1030 <swapDoubles@plt>
sub    %r15,%r13
jbe    1188 <partitionDoublesAscending+0x78>
lea    (%r14,%r15,8),%rbx
jmp    116a <partitionDoublesAscending+0x5a>
nopl   0x0(%rax)
add    $0x8,%rbx
add    $0xffffffffffffffff,%r13
je     1188 <partitionDoublesAscending+0x78>
movsd  0x8(%rsp),%xmm0
ucomisd (%rbx),%xmm0
jb     1160 <partitionDoublesAscending+0x50>
lea    (%r14,%r15,8),%rdi
add    $0x1,%r15
mov    %rbx,%rsi
call   1030 <swapDoubles@plt>
jmp    1160 <partitionDoublesAscending+0x50>
lea    (%r14,%r15,8),%rdi
mov    %r12,%rsi
call   1030 <swapDoubles@plt>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @partitionDoublesAscending(double* %0, i64 %1, i64 %2) {
%4 = alloca double*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
%9 = alloca i64
%10 = alloca i64
store double* %0, double** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%11 = load i64, i64* %5
%12 = load i64, i64* %6
%13 = load i64, i64* %5
%14 = sub i64 %12, %13
%15 = udiv i64 %14, 2
%16 = add i64 %11, %15
store i64 %16, i64* %7
%17 = load double*, double** %4
%18 = load i64, i64* %7
%19 = getelementptr inbounds double, double* %17, i64 %18
%20 = load double, double* %19
store double %20, double* %8
%21 = load double*, double** %4
%22 = load i64, i64* %7
%23 = getelementptr inbounds double, double* %21, i64 %22
%24 = load double*, double** %4
%25 = load i64, i64* %6
%26 = getelementptr inbounds double, double* %24, i64 %25
%27 = call i32 @swapDoubles(double* %23, double* %26)
%28 = load i64, i64* %5
store i64 %28, i64* %9
%29 = load i64, i64* %5
store i64 %29, i64* %10
br label %30
30: ; preds = %51, %3
%31 = load i64, i64* %10
%32 = load i64, i64* %6
%33 = icmp ult i64 %31, %32
br i1 %33, label %34, label %54
34: ; preds = %30
%35 = load double*, double** %4
%36 = load i64, i64* %10
%37 = getelementptr inbounds double, double* %35, i64 %36
%38 = load double, double* %37
%39 = load double, double* %8
%40 = fcmp ole double %38, %39
br i1 %40, label %41, label %50
41: ; preds = %34
%42 = load double*, double** %4
%43 = load i64, i64* %9
%44 = add i64 %43, 1
store i64 %44, i64* %9
%45 = getelementptr inbounds double, double* %42, i64 %43
%46 = load double*, double** %4
%47 = load i64, i64* %10
%48 = getelementptr inbounds double, double* %46, i64 %47
%49 = call i32 @swapDoubles(double* %45, double* %48)
br label %50
50: ; preds = %41, %34
br label %51
51: ; preds = %50
%52 = load i64, i64* %10
%53 = add i64 %52, 1
store i64 %53, i64* %10
br label %30
54: ; preds = %30
%55 = load double*, double** %4
%56 = load i64, i64* %9
%57 = getelementptr inbounds double, double* %55, i64 %56
%58 = load double*, double** %4
%59 = load i64, i64* %6
%60 = getelementptr inbounds double, double* %58, i64 %59
%61 = call i32 @swapDoubles(double* %57, double* %60)
%62 = load i64, i64* %9
ret i64 %62
}

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