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


x86 assembly (clang, -O0):
<partitioning>:
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     118c <partitioning+0x7c>
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    1179 <partitioning+0x69>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <swap@plt>
jmp    117e <partitioning+0x6e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <partitioning+0x21>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partitioning>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %esi,%r15d
mov    %rsi,(%rsp)
cmp    %edx,%esi
jge    116f <partitioning+0x5f>
mov    (%rsp),%rax
movslq %eax,%r14
movslq %edx,%r13
lea    0x1(%rax),%ebp
mov    %r14,%r12
mov    %eax,%r15d
jmp    1148 <partitioning+0x38>
xchg   %ax,%ax
add    $0x1,%ebp
cmp    %r12,%r13
je     116f <partitioning+0x5f>
movsd  (%rbx,%r14,8),%xmm0
ucomisd 0x8(%rbx,%r12,8),%xmm0
lea    0x1(%r12),%r12
jbe    1140 <partitioning+0x30>
add    $0x1,%r15d
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <swap@plt>
jmp    1140 <partitioning+0x30>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    (%rsp),%rdx
call   1030 <swap@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @partitioning(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 = %36, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %39
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 %35
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 = load i32, i32* %8
%34 = call i32 @swap(double* %31, i32 %32, i32 %33)
br label %35
35: ; preds = %28, %16
br label %36
36: ; preds = %35
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %12
39: ; preds = %12
%40 = load double*, double** %4
%41 = load i32, i32* %7
%42 = load i32, i32* %5
%43 = call i32 @swap(double* %40, i32 %41, i32 %42)
%44 = load i32, i32* %7
ret i32 %44
}

LLVM IR (-O2):
define i32 @partitioning(double* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %24
5: ; preds = %3
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds double, double* %0, i64 %6
%8 = sext i32 %2 to i64
br label %9
9: ; preds = %5, %21
%10 = phi i64 [ %6, %5 ], [ %12, %21 ]
%11 = phi i32 [ %1, %5 ], [ %22, %21 ]
%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 %21
17: ; preds = %9
%18 = add nsw i32 %11, 1
%19 = trunc i64 %12 to i32
%20 = tail call i32 @swap(double* %0, i32 %18, i32 %19)
br label %21
21: ; preds = %9, %17
%22 = phi i32 [ %18, %17 ], [ %11, %9 ]
%23 = icmp eq i64 %12, %8
br i1 %23, label %24, label %9
24: ; preds = %21, %3
%25 = phi i32 [ %1, %3 ], [ %22, %21 ]
%26 = tail call i32 @swap(double* %0, i32 %25, i32 %1)
ret i32 %25
}