#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*/ a;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ quick_sort(int *, int /*<<< orphan*/, int);
int rand();
int main() {
  int a[10000];
  int i;
  for (i = 0; i < 10000; i++)
    a[i] = rand() % 20000;
  quick_sort(a, 0, sizeof(a) / sizeof(int));
  for (i = 0; i < sizeof(a) / sizeof(int); i++)
    printf("%5d ", a[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x9c54(%rbp)
cmpl   $0x2710,-0x9c54(%rbp)
jge    118d <main+0x5d>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x4e20,%ecx
cltd
idiv   %ecx
movslq -0x9c54(%rbp),%rax
mov    %edx,-0x9c50(%rbp,%rax,4)
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    114c <main+0x1c>
lea    -0x9c50(%rbp),%rdi
xor    %esi,%esi
mov    $0x2710,%edx
call   1040 <quick_sort@plt>
movl   $0x0,-0x9c54(%rbp)
movslq -0x9c54(%rbp),%rax
cmp    $0x2710,%rax
jae    11eb <main+0xbb>
movslq -0x9c54(%rbp),%rax
mov    -0x9c50(%rbp,%rax,4),%esi
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    11aa <main+0x7a>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x9c48,%rsp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2d,%rcx
add    %edx,%ecx
imul   $0x4e20,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    1140 <main+0x10>
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x2710,%edx
call   1040 <quick_sort@plt>
lea    0xe73(%rip),%r14
nopl   (%rax)
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    1190 <main+0x60>
xor    %eax,%eax
add    $0x9c48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%5d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i32]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %13, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 10000
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 20000
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %11
store i32 %9, i32* %12
br label %13
13: ; preds = %7
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %4
16: ; preds = %4
%17 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 0
%18 = call i32 @quick_sort(i32* %17, i32 0, i32 10000)
store i32 0, i32* %3
br label %19
19: ; preds = %29, %16
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = icmp ult i64 %21, 10000
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %23
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %19
32: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%5d \00"
define i32 @main() {
%1 = alloca [10000 x i32]
%2 = bitcast [10000 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %8, %3 ]
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 20000
%7 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %4
store i32 %6, i32* %7
%8 = add nuw nsw i64 %4, 1
%9 = icmp eq i64 %8, 10000
br i1 %9, label %10, label %3
10: ; preds = %3
%11 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 0
%12 = call i32 @quick_sort(i32* %11, i32 0, i32 10000)
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %18, %13 ]
%15 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, 10000
br i1 %19, label %20, label %13
20: ; preds = %13
ret i32 0
}