#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 partition(int *, int, int, int);
void sort_partition(int *array, int left, int right) {
  if (left >= right)
    return;
  int middle = (left + right) / 2;
  int pivot = array[middle];
  int boundary = partition(array, left, right, pivot);
  sort_partition(array, left, boundary - 1);
  sort_partition(array, boundary, right);
}


x86 assembly (clang, -O0):
<sort_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1143 <sort_partition+0x23>
jmp    1198 <sort_partition+0x78>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <partition@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1040 <sort_partition@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <sort_partition@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_partition>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    %edx,%esi
jge    117a <sort_partition+0x5a>
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r12,%r14,1),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
mov    (%r15,%rax,4),%ecx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r15,%rdi
mov    %r12d,%esi
call   1040 <sort_partition@plt>
mov    %ebx,%r12d
cmp    %r14d,%ebx
jl     1140 <sort_partition+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @sort_partition(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %15
5: ; preds = %3, %5
%6 = phi i32 [ %12, %5 ], [ %1, %3 ]
%7 = add nsw i32 %6, %2
%8 = sdiv i32 %7, 2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @partition(i32* %0, i32 %6, i32 %2, i32 %11)
%13 = add nsw i32 %12, -1
tail call void @sort_partition(i32* %0, i32 %6, i32 %13)
%14 = icmp slt i32 %12, %2
br i1 %14, label %5, label %15
15: ; preds = %5, %3
ret void
}