#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 *);
void rec_three_way_qsort(double *array, size_t size) {
  if (size <= 1) {
    return;
  }
  double p = array[0];
  size_t i = 0, j = 0, k = 1, l = size - 1;
  while (k <= l) {
    if (array[k] > p) {
      swap(array + k, array + l);
      --l;
    } else if (array[k] < p) {
      swap(array + i, array + k);
      ++i;
      ++j;
      ++k;
    } else {
      ++k;
    }
  }
  rec_three_way_qsort(array, j);
  rec_three_way_qsort(array + k, size - k);
}


x86 assembly (clang, -O0):
<rec_three_way_qsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
ja     1140 <rec_three_way_qsort+0x20>
jmp    1272 <rec_three_way_qsort+0x152>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
ja     1249 <rec_three_way_qsort+0x129>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11cb <rec_three_way_qsort+0xab>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x38(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    1244 <rec_three_way_qsort+0x124>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1233 <rec_three_way_qsort+0x113>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    123f <rec_three_way_qsort+0x11f>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1244 <rec_three_way_qsort+0x124>
jmp    1171 <rec_three_way_qsort+0x51>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <rec_three_way_qsort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
sub    -0x30(%rbp),%rsi
call   1030 <rec_three_way_qsort@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rec_three_way_qsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%rsi
jae    1140 <rec_three_way_qsort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%r14
mov    %rdi,%r12
jmp    1168 <rec_three_way_qsort+0x48>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <rec_three_way_qsort@plt>
lea    (%r12,%rbx,8),%r12
sub    %rbx,%r14
cmp    $0x1,%r14
jbe    1131 <rec_three_way_qsort+0x11>
movsd  (%r12),%xmm1
lea    -0x1(%r14),%r13
mov    $0x1,%ebx
xor    %r15d,%r15d
xor    %ebp,%ebp
movsd  %xmm1,(%rsp)
jmp    1199 <rec_three_way_qsort+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %r13,%rbx
ja     1150 <rec_three_way_qsort+0x30>
lea    (%r12,%rbx,8),%rax
movsd  (%r12,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d0 <rec_three_way_qsort+0xb0>
lea    (%r12,%r13,8),%rsi
mov    %rax,%rdi
call   1040 <swap@plt>
movsd  (%rsp),%xmm1
add    $0xffffffffffffffff,%r13
cmp    %r13,%rbx
jbe    1199 <rec_three_way_qsort+0x79>
jmp    1150 <rec_three_way_qsort+0x30>
cs nopw 0x0(%rax,%rax,1)
nop
ucomisd %xmm0,%xmm1
jbe    1190 <rec_three_way_qsort+0x70>
lea    (%r12,%rbp,8),%rdi
mov    %rax,%rsi
call   1040 <swap@plt>
movsd  (%rsp),%xmm1
add    $0x1,%rbp
add    $0x1,%r15
jmp    1190 <rec_three_way_qsort+0x70>

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

LLVM IR (-O2):
define void @rec_three_way_qsort(double* %0, i64 %1) {
%3 = icmp ult i64 %1, 2
br i1 %3, label %41, label %4
4: ; preds = %2, %37
%5 = phi i64 [ %39, %37 ], [ %1, %2 ]
%6 = phi double* [ %38, %37 ], [ %0, %2 ]
%7 = load double, double* %6
%8 = add i64 %5, -1
br label %9
9: ; preds = %4, %31
%10 = phi i64 [ %35, %31 ], [ %8, %4 ]
%11 = phi i64 [ %34, %31 ], [ 1, %4 ]
%12 = phi i64 [ %33, %31 ], [ 0, %4 ]
%13 = phi i64 [ %32, %31 ], [ 0, %4 ]
%14 = getelementptr inbounds double, double* %6, i64 %11
%15 = load double, double* %14
%16 = fcmp ogt double %15, %7
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = getelementptr inbounds double, double* %6, i64 %10
%19 = tail call i32 @swap(double* %14, double* %18)
%20 = add i64 %10, -1
br label %31
21: ; preds = %9
%22 = fcmp olt double %15, %7
br i1 %22, label %23, label %29
23: ; preds = %21
%24 = getelementptr inbounds double, double* %6, i64 %13
%25 = tail call i32 @swap(double* %24, double* %14)
%26 = add i64 %13, 1
%27 = add i64 %12, 1
%28 = add i64 %11, 1
br label %31
29: ; preds = %21
%30 = add i64 %11, 1
br label %31
31: ; preds = %23, %29, %17
%32 = phi i64 [ %13, %17 ], [ %26, %23 ], [ %13, %29 ]
%33 = phi i64 [ %12, %17 ], [ %27, %23 ], [ %12, %29 ]
%34 = phi i64 [ %11, %17 ], [ %28, %23 ], [ %30, %29 ]
%35 = phi i64 [ %20, %17 ], [ %10, %23 ], [ %10, %29 ]
%36 = icmp ugt i64 %34, %35
br i1 %36, label %37, label %9
37: ; preds = %31
tail call void @rec_three_way_qsort(double* %6, i64 %33)
%38 = getelementptr inbounds double, double* %6, i64 %34
%39 = sub i64 %5, %34
%40 = icmp ult i64 %39, 2
br i1 %40, label %41, label %4
41: ; preds = %37, %2
ret void
}