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


x86 assembly (clang, -O0):
<rec_quick_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
ja     1140 <rec_quick_sort+0x20>
jmp    1262 <rec_quick_sort+0x142>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
ja     1235 <rec_quick_sort+0x115>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11c3 <rec_quick_sort+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x28(%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    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1230 <rec_quick_sort+0x110>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    121f <rec_quick_sort+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%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)
jmp    122b <rec_quick_sort+0x10b>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1230 <rec_quick_sort+0x110>
jmp    1169 <rec_quick_sort+0x49>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
sub    $0x1,%rsi
call   1030 <rec_quick_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
sub    -0x28(%rbp),%rsi
call   1030 <rec_quick_sort@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rec_quick_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%rsi
jae    1141 <rec_quick_sort+0x21>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rsi,%r14
mov    %rdi,%r15
jmp    1169 <rec_quick_sort+0x49>
nopl   0x0(%rax)
lea    -0x1(%rbx),%rsi
mov    %r15,%rdi
call   1030 <rec_quick_sort@plt>
lea    (%r15,%rbx,8),%r15
sub    %rbx,%r14
cmp    $0x1,%r14
jbe    1133 <rec_quick_sort+0x13>
movsd  (%r15),%xmm1
lea    -0x1(%r14),%r12
mov    $0x1,%ebx
xor    %r13d,%r13d
movsd  %xmm1,0x8(%rsp)
jmp    1199 <rec_quick_sort+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %r12,%rbx
ja     1150 <rec_quick_sort+0x30>
lea    (%r15,%rbx,8),%rax
movsd  (%r15,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d0 <rec_quick_sort+0xb0>
lea    (%r15,%r12,8),%rsi
mov    %rax,%rdi
call   1040 <swap@plt>
movsd  0x8(%rsp),%xmm1
add    $0xffffffffffffffff,%r12
cmp    %r12,%rbx
jbe    1199 <rec_quick_sort+0x79>
jmp    1150 <rec_quick_sort+0x30>
cs nopw 0x0(%rax,%rax,1)
ucomisd %xmm0,%xmm1
jbe    1190 <rec_quick_sort+0x70>
lea    (%r15,%r13,8),%rdi
mov    %rax,%rsi
call   1040 <swap@plt>
movsd  0x8(%rsp),%xmm1
add    $0x1,%r13
jmp    1190 <rec_quick_sort+0x70>

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

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