#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*/ swap(double *, double *);
double partition(double array[], int left, int right) {
  int i, j;
  i = left;
  for (j = left + 1; j <= right; ++j) {
    if (array[j] < array[left]) {
      ++i;
      swap(&array[i], &array[j]);
    }
  }
  swap(&array[left], &array[i]);
  return i;
}


x86 assembly (clang, -O0):
<partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11a0 <partition+0x90>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    118d <partition+0x7d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swap@plt>
jmp    1192 <partition+0x82>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <partition+0x21>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swap@plt>
cvtsi2sdl -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
movslq %esi,%r15
cmp    %edx,%esi
jge    1170 <partition+0x60>
movslq %edx,%rbx
sub    %r15,%rbx
lea    (%r12,%r15,8),%rbp
add    $0x8,%rbp
jmp    114a <partition+0x3a>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x8,%rbp
add    $0xffffffffffffffff,%rbx
je     1175 <partition+0x65>
movsd  (%r12,%r15,8),%xmm0
ucomisd 0x0(%rbp),%xmm0
jbe    1140 <partition+0x30>
movslq %r14d,%rax
add    $0x1,%r14d
lea    (%r12,%rax,8),%rdi
add    $0x8,%rdi
mov    %rbp,%rsi
call   1030 <swap@plt>
jmp    1140 <partition+0x30>
mov    %r15,%rax
jmp    1178 <partition+0x68>
movslq %r14d,%rax
lea    (%r12,%r15,8),%rdi
lea    (%r12,%rax,8),%rsi
call   1030 <swap@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @partition(double* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
%5 = sext i32 %1 to i64
br i1 %4, label %6, label %27
6: ; preds = %3
%7 = getelementptr inbounds double, double* %0, i64 %5
%8 = sext i32 %2 to i64
br label %9
9: ; preds = %6, %22
%10 = phi i64 [ %5, %6 ], [ %12, %22 ]
%11 = phi i32 [ %1, %6 ], [ %23, %22 ]
%12 = add nsw i64 %10, 1
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
%15 = load double, double* %7
%16 = fcmp olt double %14, %15
br i1 %16, label %17, label %22
17: ; preds = %9
%18 = add nsw i32 %11, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = tail call i32 @swap(double* %20, double* %13)
br label %22
22: ; preds = %9, %17
%23 = phi i32 [ %18, %17 ], [ %11, %9 ]
%24 = icmp eq i64 %12, %8
br i1 %24, label %25, label %9
25: ; preds = %22
%26 = sext i32 %23 to i64
br label %27
27: ; preds = %3, %25
%28 = phi i64 [ %26, %25 ], [ %5, %3 ]
%29 = phi i32 [ %23, %25 ], [ %1, %3 ]
%30 = getelementptr inbounds double, double* %0, i64 %5
%31 = getelementptr inbounds double, double* %0, i64 %28
%32 = tail call i32 @swap(double* %30, double* %31)
%33 = sitofp i32 %29 to double
ret double %33
}