#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*/ choose_pivot(int *, int, int);
int /*<<< orphan*/ exchange_member(int *, int, int);
int partition(int *arr, int lo, int hi) {
  choose_pivot(arr, lo, hi);
  int pivot = arr[lo];
  int i = lo + 1;
  for (int j = lo + 1; j <= hi; j++) {
    if (arr[j] < pivot) {
      exchange_member(arr, j, i);
      i++;
    }
  }
  exchange_member(arr, lo, i - 1);
  return i;
}


x86 assembly (clang, -O0):
<partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <choose_pivot@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11ac <partition+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jge    1199 <partition+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <exchange_member@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119e <partition+0x7e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1161 <partition+0x41>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1030 <exchange_member@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%r15
call   1040 <choose_pivot@plt>
lea    0x1(%rbp),%ebx
cmp    %r12d,%ebp
mov    %rbp,(%rsp)
jge    118f <partition+0x6f>
movslq %ebp,%rax
mov    (%r15,%rax,4),%ebp
lea    (%r15,%rax,4),%r14
add    $0x4,%r14
neg    %r12d
mov    %ebx,%r13d
jmp    1177 <partition+0x57>
nopl   0x0(%rax,%rax,1)
add    $0x4,%r14
lea    (%r12,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     1192 <partition+0x72>
cmp    %ebp,(%r14)
jge    1160 <partition+0x40>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
call   1030 <exchange_member@plt>
add    $0x1,%r13d
jmp    1160 <partition+0x40>
mov    %ebx,%r13d
lea    -0x1(%r13),%edx
mov    %r15,%rdi
mov    (%rsp),%rsi
call   1030 <exchange_member@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @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** %4
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = call i32 @choose_pivot(i32* %10, i32 %11, i32 %12)
%14 = load i32*, i32** %4
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %7
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %9
br label %23
23: ; preds = %43, %3
%24 = load i32, i32* %9
%25 = load i32, i32* %6
%26 = icmp sle i32 %24, %25
br i1 %26, label %27, label %46
27: ; preds = %23
%28 = load i32*, i32** %4
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %42
35: ; preds = %27
%36 = load i32*, i32** %4
%37 = load i32, i32* %9
%38 = load i32, i32* %8
%39 = call i32 @exchange_member(i32* %36, i32 %37, i32 %38)
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %42
42: ; preds = %35, %27
br label %43
43: ; preds = %42
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %23
46: ; preds = %23
%47 = load i32*, i32** %4
%48 = load i32, i32* %5
%49 = load i32, i32* %8
%50 = sub nsw i32 %49, 1
%51 = call i32 @exchange_member(i32* %47, i32 %48, i32 %50)
%52 = load i32, i32* %8
ret i32 %52
}

LLVM IR (-O2):
define i32 @partition(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 @choose_pivot(i32* %0, i32 %1, i32 %2)
%5 = sext i32 %1 to i64
%6 = getelementptr inbounds i32, i32* %0, i64 %5
%7 = load i32, i32* %6
%8 = add nsw i32 %1, 1
%9 = icmp slt i32 %1, %2
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = add nsw i64 %5, 1
%12 = add i32 %2, 1
br label %17
13: ; preds = %27, %3
%14 = phi i32 [ %8, %3 ], [ %28, %27 ]
%15 = add nsw i32 %14, -1
%16 = tail call i32 @exchange_member(i32* %0, i32 %1, i32 %15)
ret i32 %14
17: ; preds = %10, %27
%18 = phi i64 [ %11, %10 ], [ %29, %27 ]
%19 = phi i32 [ %8, %10 ], [ %28, %27 ]
%20 = getelementptr inbounds i32, i32* %0, i64 %18
%21 = load i32, i32* %20
%22 = icmp slt i32 %21, %7
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = trunc i64 %18 to i32
%25 = tail call i32 @exchange_member(i32* %0, i32 %24, i32 %19)
%26 = add nsw i32 %19, 1
br label %27
27: ; preds = %17, %23
%28 = phi i32 [ %26, %23 ], [ %19, %17 ]
%29 = add nsw i64 %18, 1
%30 = trunc i64 %29 to i32
%31 = icmp eq i32 %12, %30
br i1 %31, label %13, label %17
}