#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 partitionAscending(int *, int, int);
int partitionDescending(int *, int, int);
void quickSort(int *array, int low, int high, int asc) {
  int pivot;
  if (low < high) {
    if (asc >= 1) {
      pivot = partitionAscending(array, low, high);
    } else {
      pivot = partitionDescending(array, low, high);
    }
    quickSort(array, low, pivot - 1, asc);
    quickSort(array, pivot + 1, high, asc);
  }
}


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    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ae <quickSort+0x7e>
cmpl   $0x1,-0x14(%rbp)
jl     1172 <quickSort+0x42>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partitionAscending@plt>
mov    %eax,-0x18(%rbp)
jmp    1184 <quickSort+0x54>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <partitionDescending@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%ecx
call   1050 <quickSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1050 <quickSort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quickSort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    %edx,%esi
jge    1185 <quickSort+0x55>
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r15
jmp    1171 <quickSort+0x41>
nopl   0x0(%rax)
call   1040 <partitionDescending@plt>
mov    %eax,%ebp
lea    -0x1(%rbp),%edx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%ecx
call   1050 <quickSort@plt>
add    $0x1,%ebp
mov    %ebp,%ebx
cmp    %r12d,%ebp
jge    1185 <quickSort+0x55>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
test   %r14d,%r14d
jle    1150 <quickSort+0x20>
call   1030 <partitionAscending@plt>
jmp    1155 <quickSort+0x25>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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