#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*/ getchar();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ randomized_quicksort(int *, int);
int main(void) {
  int array[] = {155, -59, 18, 29, 544, 26, 31, 47, 59, 846, 25, 59};
  unsigned int i = 0;
  puts("Before sorting");
  for (i = 0; i < sizeof(array) / sizeof(int); i++) {
    printf("%d ", array[i]);
  }
  randomized_quicksort(array, sizeof(array) / sizeof(int));
  puts("\nAfter sorting");
  for (i = 0; i < sizeof(array) / sizeof(int); i++) {
    printf("%d ", array[i]);
  }
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x30,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x44(%rbp)
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    $0xc,%rax
jae    11bc <main+0x6c>
mov    -0x44(%rbp),%eax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    118e <main+0x3e>
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   1060 <randomized_quicksort@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    $0xc,%rax
jae    120b <main+0xbb>
mov    -0x44(%rbp),%eax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11dd <main+0x8d>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
lea    0xec4(%rip),%rbx
mov    %rbx,%rdi
mov    $0x9b,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0xffffffc5,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x12,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1d,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x220,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1a,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1f,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x34e,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x19,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0xc,%esi
call   1060 <randomized_quicksort@plt>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.array = [12 x i32] [i32 155, i32 -59, i32 18, i32 29, i32 544, i32 26, i32 31, i32 47, i32 59, i32 846, i32 25, i32 59]
@.str = [15 x i8] c"Before sorting\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [15 x i8] c"\0AAfter sorting\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [12 x i32]* %2 to i8*
store i32 0, i32* %3
%5 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %16, %0
%7 = load i32, i32* %3
%8 = zext i32 %7 to i64
%9 = icmp ult i64 %8, 12
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = load i32, i32* %3
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %10
%17 = load i32, i32* %3
%18 = add i32 %17, 1
store i32 %18, i32* %3
br label %6
19: ; preds = %6
%20 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%21 = call i32 @randomized_quicksort(i32* %20, i32 12)
%22 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %23
23: ; preds = %33, %19
%24 = load i32, i32* %3
%25 = zext i32 %24 to i64
%26 = icmp ult i64 %25, 12
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i32, i32* %3
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 %29
%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)
br label %33
33: ; preds = %27
%34 = load i32, i32* %3
%35 = add i32 %34, 1
store i32 %35, i32* %3
br label %23
36: ; preds = %23
%37 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [12 x i32] [i32 155, i32 -59, i32 18, i32 29, i32 544, i32 26, i32 31, i32 47, i32 59, i32 846, i32 25, i32 59]
@.str = [15 x i8] c"Before sorting\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [15 x i8] c"\0AAfter sorting\00"
define i32 @main() {
%1 = alloca [12 x i32]
%2 = bitcast [12 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 0
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 155)
%6 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 -59)
%8 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 18)
%10 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 3
%11 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 29)
%12 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 4
%13 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 544)
%14 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 5
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 26)
%16 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 6
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 31)
%18 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 7
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 47)
%20 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 8
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 59)
%22 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 9
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 846)
%24 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 10
%25 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 25)
%26 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 11
%27 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 59)
%28 = call i32 @randomized_quicksort(i32* %4, i32 12)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %4
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %6
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %8
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %10
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %12
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %14
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %16
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %18
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %20
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %22
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %24
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %26
%53 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = call i32 (...) @getchar()
ret i32 0
}