#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*/ swap(int *, int *);
int *partition(int *first, int *last, int *pivot) {
  int *store, *ptr;
  int value = *pivot;
  swap(pivot, last);
  store = first;
  for (ptr = first; ptr < last; ptr++) {
    if (*ptr < value) {
      swap(ptr, store);
      store++;
    }
  }
  swap(store, last);
  return store;
}


x86 assembly (clang, -O0):
<partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <swap@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1196 <partition+0x86>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
jge    1180 <partition+0x70>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <swap@plt>
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    1185 <partition+0x75>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    114a <partition+0x3a>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <swap@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdx),%ebp
mov    %rdx,%rdi
call   1030 <swap@plt>
cmp    %r14,%r15
jae    115e <partition+0x4e>
mov    %r15,%rbx
jmp    1149 <partition+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x4,%rbx
cmp    %r14,%rbx
jae    115e <partition+0x4e>
cmp    %ebp,(%rbx)
jge    1140 <partition+0x30>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <swap@plt>
add    $0x4,%r15
jmp    1140 <partition+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <swap@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
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** %6
%11 = load i32, i32* %10
store i32 %11, i32* %9
%12 = load i32*, i32** %6
%13 = load i32*, i32** %5
%14 = call i32 @swap(i32* %12, i32* %13)
%15 = load i32*, i32** %4
store i32* %15, i32** %7
%16 = load i32*, i32** %4
store i32* %16, i32** %8
br label %17
17: ; preds = %33, %3
%18 = load i32*, i32** %8
%19 = load i32*, i32** %5
%20 = icmp ult i32* %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i32*, i32** %8
%23 = load i32, i32* %22
%24 = load i32, i32* %9
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32*, i32** %8
%28 = load i32*, i32** %7
%29 = call i32 @swap(i32* %27, i32* %28)
%30 = load i32*, i32** %7
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %7
br label %32
32: ; preds = %26, %21
br label %33
33: ; preds = %32
%34 = load i32*, i32** %8
%35 = getelementptr inbounds i32, i32* %34, i32 1
store i32* %35, i32** %8
br label %17
36: ; preds = %17
%37 = load i32*, i32** %7
%38 = load i32*, i32** %5
%39 = call i32 @swap(i32* %37, i32* %38)
%40 = load i32*, i32** %7
ret i32* %40
}

LLVM IR (-O2):
define i32* @partition(i32* %0, i32* %1, i32* %2) {
%4 = load i32, i32* %2
%5 = tail call i32 @swap(i32* %2, i32* %1)
%6 = icmp ult i32* %0, %1
br i1 %6, label %7, label %19
7: ; preds = %3, %15
%8 = phi i32* [ %16, %15 ], [ %0, %3 ]
%9 = phi i32* [ %17, %15 ], [ %0, %3 ]
%10 = load i32, i32* %9
%11 = icmp slt i32 %10, %4
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i32 @swap(i32* %9, i32* %8)
%14 = getelementptr inbounds i32, i32* %8, i64 1
br label %15
15: ; preds = %7, %12
%16 = phi i32* [ %14, %12 ], [ %8, %7 ]
%17 = getelementptr inbounds i32, i32* %9, i64 1
%18 = icmp ult i32* %17, %1
br i1 %18, label %7, label %19
19: ; preds = %15, %3
%20 = phi i32* [ %0, %3 ], [ %16, %15 ]
%21 = tail call i32 @swap(i32* %20, i32* %1)
ret i32* %20
}