#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*/ printf(char *, ...);
int /*<<< orphan*/ swap(int *, int, int);
int partition(int array[], int leftBound, int rightBound) {
  int pivot = array[leftBound];
  int leftPointer = leftBound + 1;
  int rightPointer = rightBound;
  printf("Pivot selected is %i:\n", pivot);
  printf("Evaluating on:\n");
  for (int logCount = leftBound; logCount <= rightBound; logCount++) {
    printf("%d ", array[logCount]);
  }
  printf("\n\n");
  while (1) {
    while (array[leftPointer] <= pivot && leftPointer <= rightBound) {
      leftPointer++;
      continue;
    }
    while (array[rightPointer] > pivot) {
      rightPointer--;
      continue;
    }
    if (leftPointer < rightPointer) {
      swap(array, leftPointer, rightPointer);
    } else {
      break;
    }
  }
  swap(array, leftBound, rightPointer);
  printf("Midpoint is index %i\n", rightPointer);
  printf("Pivot shifted to midpoint:\n");
  for (int logCount = 0; logCount < 9; logCount++) {
    printf("%d ", array[logCount]);
  }
  printf("\n\n\n");
  return rightPointer;
}


x86 assembly (clang, -O0):
<partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
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    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11a7 <partition+0x87>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1174 <partition+0x54>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ba <partition+0x9a>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x25(%rbp)
jg     11df <partition+0xbf>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
setle  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11ef <partition+0xcf>
jmp    11fd <partition+0xdd>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ba <partition+0x9a>
jmp    1202 <partition+0xe2>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jle    1224 <partition+0x104>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1202 <partition+0xe2>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1244 <partition+0x124>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <swap@plt>
jmp    1249 <partition+0x129>
jmp    124e <partition+0x12e>
jmp    11b5 <partition+0x95>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <swap@plt>
mov    -0x1c(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x9,-0x24(%rbp)
jge    12b4 <partition+0x194>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1283 <partition+0x163>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%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,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
movslq %esi,%r15
mov    (%rdi,%r15,4),%r12d
lea    0xeb0(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,(%rsp)
cmp    %ebx,%ebp
jg     119c <partition+0x6c>
lea    (%r14,%r15,4),%rbp
mov    %ebx,%r15d
sub    (%rsp),%r15d
add    $0x1,%r15d
xor    %r13d,%r13d
mov    0x0(%rbp,%r13,4),%esi
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
cmp    %r13d,%r15d
jne    1180 <partition+0x50>
mov    (%rsp),%r15
lea    0x1(%r15),%ebp
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
movslq %ebx,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %ebp,%rax
lea    -0x1(%rax),%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %r12d,(%r14,%rax,4)
jg     11e5 <partition+0xb5>
lea    0x1(%rax),%rcx
cmp    %r13,%rax
mov    %rcx,%rax
jle    11d0 <partition+0xa0>
movslq %ebx,%rax
lea    0x1(%rax),%ebx
lea    (%r14,%rax,4),%rax
nop
add    $0xffffffff,%ebx
lea    -0x4(%rax),%rcx
cmp    %r12d,(%rax)
mov    %rcx,%rax
jg     11f0 <partition+0xc0>
mov    %r14,%rdi
cmp    %ebx,%ebp
jge    1211 <partition+0xe1>
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <swap@plt>
jmp    11c0 <partition+0x90>
mov    %r15d,%esi
mov    %ebx,%edx
call   1050 <swap@plt>
lea    0xdf9(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%esi
lea    0xdd6(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd99(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Pivot selected is %i:\0A\00"
@.str.1 = [16 x i8] c"Evaluating on:\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [3 x i8] c"\0A\0A\00"
@.str.4 = [22 x i8] c"Midpoint is index %i\0A\00"
@.str.5 = [28 x i8] c"Pivot shifted to midpoint:\0A\00"
@.str.6 = [4 x i8] c"\0A\0A\0A\00"
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
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
store i32 %16, i32* %7
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %8
%19 = load i32, i32* %6
store i32 %19, i32* %9
%20 = load i32, i32* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %5
store i32 %23, i32* %10
br label %24
24: ; preds = %35, %3
%25 = load i32, i32* %10
%26 = load i32, i32* %6
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i32*, i32** %4
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %28
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %24
38: ; preds = %24
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %80
br label %41
41: ; preds = %55, %40
%42 = load i32*, i32** %4
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %7
%48 = icmp sle i32 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %41
%50 = load i32, i32* %8
%51 = load i32, i32* %6
%52 = icmp sle i32 %50, %51
br label %53
53: ; preds = %49, %41
%54 = phi i1 [ false, %41 ], [ %52, %49 ]
br i1 %54, label %55, label %58
55: ; preds = %53
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %41
58: ; preds = %53
br label %59
59: ; preds = %67, %58
%60 = load i32*, i32** %4
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = load i32, i32* %7
%66 = icmp sgt i32 %64, %65
br i1 %66, label %67, label %70
67: ; preds = %59
%68 = load i32, i32* %9
%69 = add nsw i32 %68, -1
store i32 %69, i32* %9
br label %59
70: ; preds = %59
%71 = load i32, i32* %8
%72 = load i32, i32* %9
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %79
74: ; preds = %70
%75 = load i32*, i32** %4
%76 = load i32, i32* %8
%77 = load i32, i32* %9
%78 = call i32 @swap(i32* %75, i32 %76, i32 %77)
br label %80
79: ; preds = %70
br label %81
80: ; preds = %74
br label %40
81: ; preds = %79
%82 = load i32*, i32** %4
%83 = load i32, i32* %5
%84 = load i32, i32* %9
%85 = call i32 @swap(i32* %82, i32 %83, i32 %84)
%86 = load i32, i32* %9
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %11
br label %89
89: ; preds = %99, %81
%90 = load i32, i32* %11
%91 = icmp slt i32 %90, 9
br i1 %91, label %92, label %102
92: ; preds = %89
%93 = load i32*, i32** %4
%94 = load i32, i32* %11
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i32, i32* %93, i64 %95
%97 = load i32, i32* %96
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %97)
br label %99
99: ; preds = %92
%100 = load i32, i32* %11
%101 = add nsw i32 %100, 1
store i32 %101, i32* %11
br label %89
102: ; preds = %89
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%104 = load i32, i32* %9
ret i32 %104
}

LLVM IR (-O2):
@.str = [23 x i8] c"Pivot selected is %i:\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.4 = [22 x i8] c"Midpoint is index %i\0A\00"
@str = [15 x i8] c"Evaluating on:\00"
@str.7 = [2 x i8] c"\0A\00"
@str.8 = [27 x i8] c"Pivot shifted to midpoint:\00"
@str.9 = [3 x i8] c"\0A\0A\00"
define i32 @partition(i32* %0, i32 %1, i32 %2) {
%4 = sext i32 %1 to i64
%5 = getelementptr inbounds i32, i32* %0, i64 %4
%6 = load i32, i32* %5
%7 = add nsw i32 %1, 1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%10 = icmp sgt i32 %1, %2
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = add i32 %2, 1
br label %16
13: ; preds = %16, %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
%15 = sext i32 %2 to i64
br label %24
16: ; preds = %11, %16
%17 = phi i64 [ %4, %11 ], [ %21, %16 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = add nsw i64 %17, 1
%22 = trunc i64 %21 to i32
%23 = icmp eq i32 %12, %22
br i1 %23, label %13, label %16
24: ; preds = %48, %13
%25 = phi i32 [ %7, %13 ], [ %45, %48 ]
%26 = phi i32 [ %2, %13 ], [ %46, %48 ]
%27 = sext i32 %25 to i64
br label %28
28: ; preds = %28, %24
%29 = phi i64 [ %35, %28 ], [ %27, %24 ]
%30 = getelementptr inbounds i32, i32* %0, i64 %29
%31 = load i32, i32* %30
%32 = icmp sle i32 %31, %6
%33 = icmp sle i64 %29, %15
%34 = select i1 %32, i1 %33, i1 false
%35 = add i64 %29, 1
br i1 %34, label %28, label %36
36: ; preds = %28
%37 = sext i32 %26 to i64
br label %38
38: ; preds = %38, %36
%39 = phi i64 [ %43, %38 ], [ %37, %36 ]
%40 = getelementptr inbounds i32, i32* %0, i64 %39
%41 = load i32, i32* %40
%42 = icmp sgt i32 %41, %6
%43 = add i64 %39, -1
br i1 %42, label %38, label %44
44: ; preds = %38
%45 = trunc i64 %29 to i32
%46 = trunc i64 %39 to i32
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = tail call i32 @swap(i32* %0, i32 %45, i32 %46)
br label %24
50: ; preds = %44
%51 = trunc i64 %39 to i32
%52 = tail call i32 @swap(i32* %0, i32 %1, i32 %51)
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.8, i64 0, i64 0))
%55 = load i32, i32* %0
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds i32, i32* %0, i64 1
%58 = load i32, i32* %57
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds i32, i32* %0, i64 2
%61 = load i32, i32* %60
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds i32, i32* %0, i64 3
%64 = load i32, i32* %63
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds i32, i32* %0, i64 4
%67 = load i32, i32* %66
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds i32, i32* %0, i64 5
%70 = load i32, i32* %69
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %70)
%72 = getelementptr inbounds i32, i32* %0, i64 6
%73 = load i32, i32* %72
%74 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %73)
%75 = getelementptr inbounds i32, i32* %0, i64 7
%76 = load i32, i32* %75
%77 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %76)
%78 = getelementptr inbounds i32, i32* %0, i64 8
%79 = load i32, i32* %78
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %79)
%81 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.9, i64 0, i64 0))
ret i32 %51
}