#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 partition(double *v, int low, int high) {
  double pivot = v[high];
  int i = low - 1;
  for (int j = low; j < high; j++) {
    if (v[j] <= pivot) {
      i++;
      swap(v, i, j);
    }
  }
  swap(v, i + 1, high);
  return i + 1;
}


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    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1196 <partition+0x86>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1183 <partition+0x73>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1030 <swap@plt>
jmp    1188 <partition+0x78>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1143 <partition+0x33>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <swap@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r14
lea    -0x1(%rbx),%r12d
cmp    %edx,%esi
jge    117c <partition+0x6c>
movslq %r15d,%rax
movsd  (%r14,%rax,8),%xmm0
movslq %ebx,%rax
lea    (%r14,%rax,8),%rbp
movsd  %xmm0,0x8(%rsp)
jmp    115c <partition+0x4c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
add    $0x8,%rbp
cmp    %ebx,%r15d
je     117c <partition+0x6c>
ucomisd 0x0(%rbp),%xmm0
jb     1150 <partition+0x40>
add    $0x1,%r12d
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
call   1030 <swap@plt>
movsd  0x8(%rsp),%xmm0
jmp    1150 <partition+0x40>
add    $0x1,%r12d
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1030 <swap@plt>
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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