#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 do_quicksort(int *, size_t);
int median_of_three_ints(int *, size_t);
int /*<<< orphan*/ swap(int *, int *);
void quicksort_ints(int *array, size_t nmemb) {
  while (nmemb > 1) {
    int pivotIndex = median_of_three_ints(array, nmemb);
    swap(&array[pivotIndex], &array[0]);
    pivotIndex = do_quicksort(array, nmemb);
    quicksort_ints(&array[pivotIndex + 1], nmemb - 1 - pivotIndex);
    nmemb = pivotIndex;
  }
}


x86 assembly (clang, -O0):
<quicksort_ints>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jbe    11c7 <quicksort_ints+0x87>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <median_of_three_ints@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1060 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <do_quicksort@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
sub    $0x1,%rsi
movslq -0x14(%rbp),%rax
sub    %rax,%rsi
call   1040 <quicksort_ints@plt>
movslq -0x14(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1150 <quicksort_ints+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort_ints>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%rsi
jb     11a9 <quicksort_ints+0x69>
mov    %rsi,%rbp
mov    %rdi,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <median_of_three_ints@plt>
cltq
lea    (%r14,%rax,4),%rdi
mov    %r14,%rsi
call   1060 <swap@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <do_quicksort@plt>
mov    %eax,%r15d
movslq %eax,%rbx
lea    (%r14,%rbx,4),%rdi
add    $0x4,%rdi
mov    %rbx,%rsi
not    %rsi
add    %rbp,%rsi
call   1040 <quicksort_ints@plt>
mov    %rbx,%rbp
cmp    $0x1,%r15d
ja     1160 <quicksort_ints+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @quicksort_ints(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
br label %6
6: ; preds = %9, %2
%7 = load i64, i64* %4
%8 = icmp ugt i64 %7, 1
br i1 %8, label %9, label %35
9: ; preds = %6
%10 = load i32*, i32** %3
%11 = load i64, i64* %4
%12 = call i32 @median_of_three_ints(i32* %10, i64 %11)
store i32 %12, i32* %5
%13 = load i32*, i32** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = call i32 @swap(i32* %16, i32* %18)
%20 = load i32*, i32** %3
%21 = load i64, i64* %4
%22 = call i32 @do_quicksort(i32* %20, i64 %21)
store i32 %22, i32* %5
%23 = load i32*, i32** %3
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %23, i64 %26
%28 = load i64, i64* %4
%29 = sub i64 %28, 1
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = sub i64 %29, %31
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
store i64 %34, i64* %4
br label %6
35: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @quicksort_ints(i32* %0, i64 %1) {
%3 = icmp ugt i64 %1, 1
br i1 %3, label %4, label %18
4: ; preds = %2, %4
%5 = phi i64 [ %14, %4 ], [ %1, %2 ]
%6 = tail call i32 @median_of_three_ints(i32* %0, i64 %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = tail call i32 @swap(i32* %8, i32* %0)
%10 = tail call i32 @do_quicksort(i32* %0, i64 %5)
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = sext i32 %10 to i64
%15 = xor i64 %14, -1
%16 = add i64 %5, %15
tail call void @quicksort_ints(i32* %13, i64 %16)
%17 = icmp ugt i32 %10, 1
br i1 %17, label %4, label %18
18: ; preds = %4, %2
ret void
}