#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 /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ tail_recursive_quicksort(int *, int /*<<< orphan*/, int);
int main(void) {
  int i;
  int num[] = {2, 3, 5, 1, 7, 8, 6, 4, 2, 3, 6, 9, 10, 4};
  printf("q = %d\n", partition(num, 0, 13));
  tail_recursive_quicksort(num, 0, 13);
  for (i = 0; i < 14; i++)
    printf("%d\n", num[i]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x38,%edx
call   1060 <memcpy@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1030 <partition@plt>
mov    %eax,%esi
lea    0xebb(%rip),%rdi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1040 <tail_recursive_quicksort@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xe,-0x8(%rbp)
jge    11c5 <main+0x85>
movslq -0x8(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1199 <main+0x59>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    0xef4(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea0(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1030 <partition@plt>
lea    0xebb(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1040 <tail_recursive_quicksort@plt>
mov    (%rsp),%esi
lea    0xe9f(%rip),%rbx
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x30(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x34(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.num = [14 x i32] [i32 2, i32 3, i32 5, i32 1, i32 7, i32 8, i32 6, i32 4, i32 2, i32 3, i32 6, i32 9, i32 10, i32 4]
@.str = [8 x i8] c"q = %d\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [14 x i32]
store i32 0, i32* %1
%4 = bitcast [14 x i32]* %3 to i8*
%5 = getelementptr inbounds [14 x i32], [14 x i32]* %3, i64 0, i64 0
%6 = call i32 @partition(i32* %5, i32 0, i32 13)
%7 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [14 x i32], [14 x i32]* %3, i64 0, i64 0
%9 = call i32 @tail_recursive_quicksort(i32* %8, i32 0, i32 13)
store i32 0, i32* %2
br label %10
10: ; preds = %19, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 14
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [14 x i32], [14 x i32]* %3, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %13
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %10
22: ; preds = %10
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@__const.main.num = [14 x i32] [i32 2, i32 3, i32 5, i32 1, i32 7, i32 8, i32 6, i32 4, i32 2, i32 3, i32 6, i32 9, i32 10, i32 4]
@.str = [8 x i8] c"q = %d\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [14 x i32]
%2 = bitcast [14 x i32]* %1 to i8*
%3 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 0
%4 = call i32 @partition(i32* %3, i32 0, i32 13)
%5 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @tail_recursive_quicksort(i32* %3, i32 0, i32 13)
%7 = load i32, i32* %3
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 1
%10 = load i32, i32* %9
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 2
%13 = load i32, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 3
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 4
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 5
%22 = load i32, i32* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 6
%25 = load i32, i32* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 7
%28 = load i32, i32* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 8
%31 = load i32, i32* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 9
%34 = load i32, i32* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 10
%37 = load i32, i32* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 11
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 12
%43 = load i32, i32* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds [14 x i32], [14 x i32]* %1, i64 0, i64 13
%46 = load i32, i32* %45
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
ret i32 0
}