#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*/ assert(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quicksort(int **, int /*<<< orphan*/, int, char *);
int main() {
  printf("quicksort\n");
  int expected[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  int arr[9] = {6, 5, 1, 3, 8, 4, 7, 9, 2};
  quicksort(&arr, 0, 9, "initial");
  for (int i = 0; i < 9; i++) {
    printf("offset: %d value: %d expected: %d\n", i, arr[i], expected[i]);
    assert(arr[i] == expected[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    0xed8(%rip),%rsi
mov    $0x24,%edx
call   1060 <memcpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xef3(%rip),%rsi
mov    $0x24,%edx
call   1060 <memcpy@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
lea    0xe72(%rip),%rcx
call   1030 <quicksort@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x9,-0x64(%rbp)
jge    11fb <main+0xbb>
mov    -0x64(%rbp),%esi
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
movslq -0x64(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
movslq -0x64(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11a5 <main+0x65>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xf03(%rip),%rdi
call   1030 <puts@plt>
mov    0xec9(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xeae(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe92(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeab(%rip),%rcx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1040 <quicksort@plt>
mov    (%rsp),%edx
lea    0xe9a(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x1,(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x2,0x4(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x3,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x3,0x8(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x4,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x4,0xc(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x5,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x5,0x10(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x6,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x6,0x14(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0x18(%rsp),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x7,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x7,0x18(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0x1c(%rsp),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
mov    $0x8,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x8,0x1c(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0x20(%rsp),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x9,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
cmpl   $0x9,0x20(%rsp)
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"quicksort\0A\00"
@__const.main.expected = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@__const.main.arr = [9 x i32] [i32 6, i32 5, i32 1, i32 3, i32 8, i32 4, i32 7, i32 9, i32 2]
@.str.1 = [8 x i8] c"initial\00"
@.str.2 = [35 x i8] c"offset: %d value: %d expected: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i32]
%3 = alloca [9 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = bitcast [9 x i32]* %2 to i8*
%7 = bitcast [9 x i32]* %3 to i8*
%8 = bitcast [9 x i32]* %3 to i32**
%9 = call i32 @quicksort(i32** %8, i32 0, i32 9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %10
10: ; preds = %35, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 9
br i1 %12, label %13, label %38
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %18, i32 %22)
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %27, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
br label %35
35: ; preds = %13
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %10
38: ; preds = %10
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@__const.main.arr = [9 x i32] [i32 6, i32 5, i32 1, i32 3, i32 8, i32 4, i32 7, i32 9, i32 2]
@.str.1 = [8 x i8] c"initial\00"
@.str.2 = [35 x i8] c"offset: %d value: %d expected: %d\0A\00"
@str = [10 x i8] c"quicksort\00"
define i32 @main() {
%1 = alloca [9 x i32]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%3 = bitcast [9 x i32]* %1 to i8*
%4 = bitcast [9 x i32]* %1 to i32**
%5 = call i32 @quicksort(i32** %4, i32 0, i32 9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 0
%7 = load i32, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 %7, i32 1)
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 1
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %14, i32 2)
%16 = load i32, i32* %13
%17 = icmp eq i32 %16, 2
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 2
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 %21, i32 3)
%23 = load i32, i32* %20
%24 = icmp eq i32 %23, 3
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 3
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %28, i32 4)
%30 = load i32, i32* %27
%31 = icmp eq i32 %30, 4
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 4
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 4, i32 %35, i32 5)
%37 = load i32, i32* %34
%38 = icmp eq i32 %37, 5
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 5
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 %42, i32 6)
%44 = load i32, i32* %41
%45 = icmp eq i32 %44, 6
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 6
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 6, i32 %49, i32 7)
%51 = load i32, i32* %48
%52 = icmp eq i32 %51, 7
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 7
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 7, i32 %56, i32 8)
%58 = load i32, i32* %55
%59 = icmp eq i32 %58, 8
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 8
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 8, i32 %63, i32 9)
%65 = load i32, i32* %62
%66 = icmp eq i32 %65, 9
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
ret i32 0
}