#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*/ bubblesort(int *, int, int);
int partition(int *, int, int);
void quicksort(int *array, int low, int high) {
  if (high - low < 10) {
    bubblesort(array, low, high);
    return;
  }
  int middle = partition(array, low, high);
  if (low < middle) {
#pragma omp task firstprivate(array, low, middle)
    quicksort(array, low, middle - 1);
  }
  if (middle < high) {
#pragma omp task firstprivate(array, middle, high)
    quicksort(array, middle + 1, high);
  }
}


x86 assembly (clang, -O0):
<quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0xa,%eax
jge    1165 <quicksort+0x35>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <bubblesort@plt>
jmp    11b3 <quicksort+0x83>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1195 <quicksort+0x65>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <quicksort@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b3 <quicksort+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <quicksort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
mov    %edx,%eax
sub    %esi,%eax
cmp    $0xa,%eax
jge    1150 <quicksort+0x20>
mov    %ebp,%ebx
jmp    1184 <quicksort+0x54>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
cmp    %ebp,%eax
jle    1170 <quicksort+0x40>
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <quicksort@plt>
cmp    %r15d,%ebx
jge    119b <quicksort+0x6b>
add    $0x1,%ebx
mov    %r15d,%eax
sub    %ebx,%eax
mov    %ebx,%ebp
cmp    $0x9,%eax
jg     1150 <quicksort+0x20>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <bubblesort@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @quicksort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = load i32, i32* %5
%10 = sub nsw i32 %8, %9
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32*, i32** %4
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = call i32 @bubblesort(i32* %13, i32 %14, i32 %15)
br label %39
17: ; preds = %3
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @partition(i32* %18, i32 %19, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %5
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 1
br label %30
30: ; preds = %25, %17
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32*, i32** %4
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %6
br label %39
39: ; preds = %12, %34, %30
ret void
}

LLVM IR (-O2):
define void @quicksort(i32* %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %2, %1
%5 = icmp slt i32 %4, 10
br i1 %5, label %9, label %12
6: ; preds = %18
%7 = sub nsw i32 %2, %20
%8 = icmp slt i32 %7, 10
br i1 %8, label %9, label %12
9: ; preds = %6, %3
%10 = phi i32 [ %1, %3 ], [ %20, %6 ]
%11 = tail call i32 @bubblesort(i32* %0, i32 %10, i32 %2)
br label %21
12: ; preds = %3, %6
%13 = phi i32 [ %20, %6 ], [ %1, %3 ]
%14 = tail call i32 @partition(i32* %0, i32 %13, i32 %2)
%15 = icmp sgt i32 %14, %13
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = add nsw i32 %14, -1
tail call void @quicksort(i32* %0, i32 %13, i32 %17)
br label %18
18: ; preds = %16, %12
%19 = icmp slt i32 %14, %2
%20 = add nsw i32 %14, 1
br i1 %19, label %6, label %21
21: ; preds = %18, %9
ret void
}