#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 */
struct DSVector {
  int dummy;
};
typedef int int32_t;

/* Variables and functions */
int ds_vector_partition(struct DSVector *, int, int, int,
                        int (*)(void *, void *));
void ds_vector_quicksort(struct DSVector *vec, int32_t left, int32_t right,
                         int32_t(compare)(void *, void *)) {
  int32_t pivot;
  if (left >= right)
    return;
  pivot = (left + right) / 2;
  pivot = ds_vector_partition(vec, left, right, pivot, compare);
  ds_vector_quicksort(vec, left, pivot - 1, compare);
  ds_vector_quicksort(vec, pivot + 1, right, compare);
}


x86 assembly (clang, -O0):
<ds_vector_quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1147 <ds_vector_quicksort+0x27>
jmp    119d <ds_vector_quicksort+0x7d>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8
call   1030 <ds_vector_partition@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%rcx
call   1040 <ds_vector_quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <ds_vector_quicksort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds_vector_quicksort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    %edx,%esi
jge    117c <ds_vector_quicksort+0x5c>
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%r15
nopl   0x0(%rax)
lea    (%r12,%r13,1),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    %r14,%r8
call   1030 <ds_vector_partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r14,%rcx
call   1040 <ds_vector_quicksort@plt>
add    $0x1,%ebx
mov    %ebx,%r13d
cmp    %r12d,%ebx
jl     1140 <ds_vector_quicksort+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.DSVector = type { i32 }
define void @ds_vector_quicksort(%struct.DSVector* %0, i32 %1, i32 %2, i32 (i8*, i8*)* %3) {
%5 = icmp slt i32 %1, %2
br i1 %5, label %6, label %14
6: ; preds = %4, %6
%7 = phi i32 [ %12, %6 ], [ %1, %4 ]
%8 = add nsw i32 %7, %2
%9 = sdiv i32 %8, 2
%10 = tail call i32 @ds_vector_partition(%struct.DSVector* %0, i32 %7, i32 %2, i32 %9, i32 (i8*, i8*)* %3)
%11 = add nsw i32 %10, -1
tail call void @ds_vector_quicksort(%struct.DSVector* %0, i32 %7, i32 %11, i32 (i8*, i8*)* %3)
%12 = add nsw i32 %10, 1
%13 = icmp slt i32 %12, %2
br i1 %13, label %6, label %14
14: ; preds = %6, %4
ret void
}