#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 *);
int partition(double arr[], int low, int high) {
  double pivot = arr[high];
  int i = (low - 1);
  int j;
  for (j = low; j <= high - 1; j++) {
    if (arr[j] <= pivot) {
      i++;
      swap(&arr[i], &arr[j]);
    }
  }
  swap(&arr[i + 1], &arr[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
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11af <partition+0x9f>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     119c <partition+0x8c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swap@plt>
jmp    11a1 <partition+0x91>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1143 <partition+0x33>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
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    %rdi,%r15
movslq %edx,%rbp
lea    (%rdi,%rbp,8),%r14
lea    -0x1(%rsi),%r12d
cmp    %ebp,%esi
jge    117e <partition+0x6e>
movsd  (%r15,%rbp,8),%xmm0
movslq %esi,%rax
lea    (%r15,%rax,8),%rbx
sub    %esi,%ebp
movsd  %xmm0,0x8(%rsp)
jmp    1159 <partition+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x8,%rbx
add    $0xffffffff,%ebp
je     117e <partition+0x6e>
ucomisd (%rbx),%xmm0
jb     1150 <partition+0x40>
movslq %r12d,%rax
add    $0x1,%r12d
lea    (%r15,%rax,8),%rdi
add    $0x8,%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
movsd  0x8(%rsp),%xmm0
jmp    1150 <partition+0x40>
movslq %r12d,%rax
add    $0x1,%r12d
lea    (%r15,%rax,8),%rdi
add    $0x8,%rdi
mov    %r14,%rsi
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 = %44, %3
%19 = load i32, i32* %9
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 1
%22 = icmp sle i32 %19, %21
br i1 %22, label %23, label %47
23: ; preds = %18
%24 = load double*, double** %4
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = load double, double* %7
%30 = fcmp ole double %28, %29
br i1 %30, label %31, label %43
31: ; preds = %23
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
%34 = load double*, double** %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double*, double** %4
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = call i32 @swap(double* %37, double* %41)
br label %43
43: ; preds = %31, %23
br label %44
44: ; preds = %43
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %18
47: ; preds = %18
%48 = load double*, double** %4
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %48, i64 %51
%53 = load double*, double** %4
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = call i32 @swap(double* %52, double* %56)
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
ret i32 %59
}

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 %27
9: ; preds = %3
%10 = sext i32 %1 to i64
br label %11
11: ; preds = %9, %22
%12 = phi i64 [ %10, %9 ], [ %24, %22 ]
%13 = phi i32 [ %7, %9 ], [ %23, %22 ]
%14 = getelementptr inbounds double, double* %0, i64 %12
%15 = load double, double* %14
%16 = fcmp ugt double %15, %6
br i1 %16, label %22, label %17
17: ; preds = %11
%18 = add nsw i32 %13, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = tail call i32 @swap(double* %20, double* %14)
br label %22
22: ; preds = %11, %17
%23 = phi i32 [ %18, %17 ], [ %13, %11 ]
%24 = add nsw i64 %12, 1
%25 = trunc i64 %24 to i32
%26 = icmp eq i32 %25, %2
br i1 %26, label %27, label %11
27: ; preds = %22, %3
%28 = phi i32 [ %7, %3 ], [ %23, %22 ]
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %0, i64 %30
%32 = tail call i32 @swap(double* %31, double* %5)
ret i32 %29
}