#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*/ bentley_mcilroy_3way_partition(int *, int, int, int *);
void quicksort_rec(int *items, int lo, int hi) {
  int indices[4];
  if (lo >= hi) {
    return;
  }
  int pivot = items[lo];
  bentley_mcilroy_3way_partition(items + lo, hi - lo + 1, pivot, indices);
  int midlo = indices[1] - 1;
  int midhi = indices[2];
  if (midlo - lo < hi - midhi) {
    quicksort_rec(items, lo, midlo);
    quicksort_rec(items, midhi, hi);
  } else {
    quicksort_rec(items, midhi, hi);
    quicksort_rec(items, lo, midlo);
  }
}


x86 assembly (clang, -O0):
<quicksort_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1143 <quicksort_rec+0x23>
jmp    11d9 <quicksort_rec+0xb9>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x24(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1030 <bentley_mcilroy_3way_partition@plt>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    -0x2c(%rbp),%ecx
cmp    %ecx,%eax
jge    11bb <quicksort_rec+0x9b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1040 <quicksort_rec@plt>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <quicksort_rec@plt>
jmp    11d9 <quicksort_rec+0xb9>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <quicksort_rec@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1040 <quicksort_rec@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort_rec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edx,%esi
sub    %ebx,%esi
jle    1198 <quicksort_rec+0x78>
mov    %edx,%r15d
mov    %rdi,%r14
movslq %ebx,%rax
lea    (%rdi,%rax,4),%rdi
mov    (%r14,%rax,4),%edx
add    $0x1,%esi
mov    %rsp,%rcx
call   1030 <bentley_mcilroy_3way_partition@plt>
mov    0x4(%rsp),%ebp
mov    0x8(%rsp),%r12d
add    $0xffffffff,%ebp
mov    %ebp,%eax
sub    %ebx,%eax
mov    %r15d,%ecx
sub    %r12d,%ecx
mov    %r14,%rdi
cmp    %ecx,%eax
jge    1181 <quicksort_rec+0x61>
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <quicksort_rec@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
jmp    1193 <quicksort_rec+0x73>
mov    %r12d,%esi
mov    %r15d,%edx
call   1040 <quicksort_rec@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <quicksort_rec@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @quicksort_rec(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [4 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp sge i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %3
br label %58
15: ; preds = %3
%16 = load i32*, i32** %4
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
store i32 %20, i32* %8
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %6
%26 = load i32, i32* %5
%27 = sub nsw i32 %25, %26
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %8
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
%31 = call i32 @bentley_mcilroy_3way_partition(i32* %24, i32 %28, i32 %29, i32* %30)
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 1
%33 = load i32, i32* %32
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %9
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 2
%36 = load i32, i32* %35
store i32 %36, i32* %10
%37 = load i32, i32* %9
%38 = load i32, i32* %5
%39 = sub nsw i32 %37, %38
%40 = load i32, i32* %6
%41 = load i32, i32* %10
%42 = sub nsw i32 %40, %41
%43 = icmp slt i32 %39, %42
br i1 %43, label %44, label %51
44: ; preds = %15
%45 = load i32*, i32** %4
%46 = load i32, i32* %5
%47 = load i32, i32* %9
%48 = load i32*, i32** %4
%49 = load i32, i32* %10
%50 = load i32, i32* %6
br label %58
51: ; preds = %15
%52 = load i32*, i32** %4
%53 = load i32, i32* %10
%54 = load i32, i32* %6
%55 = load i32*, i32** %4
%56 = load i32, i32* %5
%57 = load i32, i32* %9
br label %58
58: ; preds = %14, %51, %44
ret void
}

LLVM IR (-O2):
define void @quicksort_rec(i32* %0, i32 %1, i32 %2) {
%4 = alloca [4 x i32]
%5 = bitcast [4 x i32]* %4 to i8*
%6 = icmp sgt i32 %2, %1
br i1 %6, label %7, label %25
7: ; preds = %3
%8 = sext i32 %1 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = sub i32 1, %1
%12 = add i32 %11, %2
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%14 = call i32 @bentley_mcilroy_3way_partition(i32* %9, i32 %12, i32 %10, i32* %13)
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%16 = load i32, i32* %15
%17 = add nsw i32 %16, -1
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%19 = load i32, i32* %18
%20 = sub nsw i32 %17, %1
%21 = sub nsw i32 %2, %19
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %7
br label %25
24: ; preds = %7
br label %25
25: ; preds = %23, %24, %3
ret void
}