#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*/ print_list(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quicksort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ quicksort_non_recursive(int *, int /*<<< orphan*/, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int l[50];
  int size = 50;
  int c;
  srand(time(NULL));
  for (c = 0; c < size; c++)
    l[c] = rand() % 100;
  printf("out of order:\n");
  print_list(l, size - 1);
  printf("in order (recursive quicksort):\n");
  quicksort(l, 0, size - 1);
  print_list(l, size - 1);
  printf("\n\n");
  for (c = 0; c < size; c++)
    l[c] = rand() % 100;
  printf("new out of order:\n");
  print_list(l, size - 1);
  printf("in order (non-recursive quicksort):\n");
  quicksort_non_recursive(l, 0, size - 1);
  print_list(l, size - 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x32,-0xd4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0xd8(%rbp)
mov    -0xd8(%rbp),%eax
cmp    -0xd4(%rbp),%eax
jge    11e9 <main+0x79>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0xd8(%rbp),%rax
mov    %edx,-0xd0(%rbp,%rax,4)
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    11a6 <main+0x36>
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
sub    $0x1,%esi
call   1030 <print_list@plt>
lea    0xdef(%rip),%rdi
call   1050 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <quicksort@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
sub    $0x1,%esi
call   1030 <print_list@plt>
lea    0xdd8(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0xd8(%rbp)
mov    -0xd8(%rbp),%eax
cmp    -0xd4(%rbp),%eax
jge    129b <main+0x12b>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0xd8(%rbp),%rax
mov    %edx,-0xd0(%rbp,%rax,4)
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    1258 <main+0xe8>
lea    0xd82(%rip),%rdi
call   1050 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
sub    $0x1,%esi
call   1030 <print_list@plt>
lea    0xd74(%rip),%rdi
call   1050 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1080 <quicksort_non_recursive@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
sub    $0x1,%esi
call   1030 <print_list@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xd0,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1190 <main+0x20>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x31,%esi
call   1040 <print_list@plt>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x31,%edx
call   1050 <quicksort@plt>
mov    %rbx,%rdi
mov    $0x31,%esi
call   1040 <print_list@plt>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1220 <main+0xb0>
lea    0xdcc(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x31,%esi
call   1040 <print_list@plt>
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x31,%edx
call   1080 <quicksort_non_recursive@plt>
mov    %rbx,%rdi
mov    $0x31,%esi
call   1040 <print_list@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"out of order:\0A\00"
@.str.1 = [33 x i8] c"in order (recursive quicksort):\0A\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [19 x i8] c"new out of order:\0A\00"
@.str.4 = [37 x i8] c"in order (non-recursive quicksort):\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 50, i32* %3
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
store i32 0, i32* %4
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 100
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %15
store i32 %13, i32* %16
br label %17
17: ; preds = %11
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %7
20: ; preds = %7
%21 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
%25 = call i32 @print_list(i32* %22, i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%27 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %3
%29 = sub nsw i32 %28, 1
%30 = call i32 @quicksort(i32* %27, i32 0, i32 %29)
%31 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %3
%33 = sub nsw i32 %32, 1
%34 = call i32 @print_list(i32* %31, i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %36
36: ; preds = %46, %20
%37 = load i32, i32* %4
%38 = load i32, i32* %3
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = call i32 (...) @rand()
%42 = srem i32 %41, 100
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %44
store i32 %42, i32* %45
br label %46
46: ; preds = %40
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %36
49: ; preds = %36
%50 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%51 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%52 = load i32, i32* %3
%53 = sub nsw i32 %52, 1
%54 = call i32 @print_list(i32* %51, i32 %53)
%55 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%56 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%57 = load i32, i32* %3
%58 = sub nsw i32 %57, 1
%59 = call i32 @quicksort_non_recursive(i32* %56, i32 0, i32 %58)
%60 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 0
%61 = load i32, i32* %3
%62 = sub nsw i32 %61, 1
%63 = call i32 @print_list(i32* %60, i32 %62)
ret i32 0
}

LLVM IR (-O2):
@str = [14 x i8] c"out of order:\00"
@str.5 = [32 x i8] c"in order (recursive quicksort):\00"
@str.6 = [2 x i8] c"\0A\00"
@str.7 = [18 x i8] c"new out of order:\00"
@str.8 = [36 x i8] c"in order (non-recursive quicksort):\00"
define i32 @main() {
%1 = alloca [50 x i32]
%2 = bitcast [50 x i32]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %10, %5 ]
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 100
%9 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %6
store i32 %8, i32* %9
%10 = add nuw nsw i64 %6, 1
%11 = icmp eq i64 %10, 50
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%14 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 0
%15 = call i32 @print_list(i32* %14, i32 49)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%17 = call i32 @quicksort(i32* %14, i32 0, i32 49)
%18 = call i32 @print_list(i32* %14, i32 49)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0))
br label %20
20: ; preds = %12, %20
%21 = phi i64 [ 0, %12 ], [ %25, %20 ]
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 100
%24 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %21
store i32 %23, i32* %24
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, 50
br i1 %26, label %27, label %20
27: ; preds = %20
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
%29 = call i32 @print_list(i32* %14, i32 49)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.8, i64 0, i64 0))
%31 = call i32 @quicksort_non_recursive(i32* %14, i32 0, i32 49)
%32 = call i32 @print_list(i32* %14, i32 49)
ret i32 0
}