#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 */
typedef int /*<<< orphan*/ array;

/* Variables and functions */
int /*<<< orphan*/ PrintArray(int *, int);
int /*<<< orphan*/ QuickSortMiddleBase(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  int array[] = {3, 9, 4, 2, 5, 8, 7, 6, 1};
  int length = sizeof(array) / sizeof(int);
  printf("output array\n");
  PrintArray(array, length);
  printf("begin quick sort\n");
  QuickSortMiddleBase(array, 0, length - 1);
  printf("quick sorted\n");
  PrintArray(array, length);
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
movl   $0x9,-0x44(%rbp)
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <PrintArray@plt>
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1070 <QuickSortMiddleBase@plt>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <PrintArray@plt>
lea    0xe7c(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0xed5(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1050 <PrintArray@plt>
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <QuickSortMiddleBase@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1050 <PrintArray@plt>
lea    0xe67(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.array = [9 x i32] [i32 3, i32 9, i32 4, i32 2, i32 5, i32 8, i32 7, i32 6, i32 1]
@.str = [14 x i8] c"output array\0A\00"
@.str.1 = [18 x i8] c"begin quick sort\0A\00"
@.str.2 = [14 x i8] c"quick sorted\0A\00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [9 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [9 x i32]* %6 to i8*
store i32 9, i32* %7
%9 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 0
%11 = load i32, i32* %7
%12 = call i32 @PrintArray(i32* %10, i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 0
%15 = load i32, i32* %7
%16 = sub nsw i32 %15, 1
%17 = call i32 @QuickSortMiddleBase(i32* %14, i32 0, i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 0
%20 = load i32, i32* %7
%21 = call i32 @PrintArray(i32* %19, i32 %20)
%22 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [9 x i32] [i32 3, i32 9, i32 4, i32 2, i32 5, i32 8, i32 7, i32 6, i32 1]
@.str.3 = [6 x i8] c"pause\00"
@str = [13 x i8] c"output array\00"
@str.4 = [17 x i8] c"begin quick sort\00"
@str.5 = [13 x i8] c"quick sorted\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [9 x i32]
%4 = bitcast [9 x i32]* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 0
%7 = call i32 @PrintArray(i32* %6, i32 9)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%9 = call i32 @QuickSortMiddleBase(i32* %6, i32 0, i32 8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
%11 = call i32 @PrintArray(i32* %6, i32 9)
%12 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}