#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*/ free(void *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quicksort(int *, int /*<<< orphan*/, int);
int rand();
int /*<<< orphan*/ srand(int);
int main(int argc, char **argv) {
  srand(123456);
  int *arr = (int *)malloc(sizeof(int) * 1000);
  int i;
  for (i = 0; i < 1000; i++) {
    arr[i] = rand() % 200;
  }
  printf("Before Sort:  \n\n");
  for (i = 0; i < 1000; i++) {
    if (i == 0) {
      printf("[ ");
    }
    printf("%d ", arr[i]);
    if (i == 1000 - 1) {
      printf("]\n");
    }
  }
  printf("After Sort:  \n\n");
  quicksort(arr, 0, 1000 - 1);
  for (i = 0; i < 1000; i++) {
    if (i == 0) {
      printf("[ ");
    }
    printf("%d ", arr[i]);
    if (i == 1000 - 1) {
      printf("]\n");
    }
  }
  free((void *)arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1e240,%edi
call   1060 <srand@plt>
mov    $0xfa0,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    11ca <main+0x6a>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0xc8,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1195 <main+0x35>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    124b <main+0xeb>
cmpl   $0x0,-0x1c(%rbp)
jne    1204 <main+0xa4>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x3e7,-0x1c(%rbp)
jne    1238 <main+0xd8>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123d <main+0xdd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11df <main+0x7f>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e7,%edx
call   1040 <quicksort@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    12dc <main+0x17c>
cmpl   $0x0,-0x1c(%rbp)
jne    1295 <main+0x135>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x3e7,-0x1c(%rbp)
jne    12c9 <main+0x169>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ce <main+0x16e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1270 <main+0x110>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x1e240,%edi
call   1070 <srand@plt>
mov    $0xfa0,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0xc8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1190 <main+0x20>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%esi
lea    0xe19(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1200 <main+0x90>
lea    0xe04(%rip),%rdi
call   1040 <puts@plt>
lea    0xde9(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x3e7,%edx
call   1050 <quicksort@plt>
lea    0xdb7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%esi
lea    0xda9(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1270 <main+0x100>
lea    0xd94(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Before Sort: \0A\0A\00"
@.str.1 = [3 x i8] c"[ \00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [3 x i8] c"]\0A\00"
@.str.4 = [16 x i8] c"After Sort: \0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @srand(i32 123456)
%9 = call i64 @malloc(i32 4000)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %6
store i32 0, i32* %7
br label %11
11: ; preds = %21, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 1000
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 200
%17 = load i32*, i32** %6
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 %16, i32* %20
br label %21
21: ; preds = %14
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %11
24: ; preds = %11
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %26
26: ; preds = %46, %24
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 1000
br i1 %28, label %29, label %49
29: ; preds = %26
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = load i32*, i32** %6
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 999
br i1 %42, label %43, label %45
43: ; preds = %34
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %34
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %26
49: ; preds = %26
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32*, i32** %6
%52 = call i32 @quicksort(i32* %51, i32 0, i32 999)
store i32 0, i32* %7
br label %53
53: ; preds = %73, %49
%54 = load i32, i32* %7
%55 = icmp slt i32 %54, 1000
br i1 %55, label %56, label %76
56: ; preds = %53
%57 = load i32, i32* %7
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
%62 = load i32*, i32** %6
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
%66 = load i32, i32* %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %7
%69 = icmp eq i32 %68, 999
br i1 %69, label %70, label %72
70: ; preds = %61
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %72
72: ; preds = %70, %61
br label %73
73: ; preds = %72
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %53
76: ; preds = %53
%77 = load i32*, i32** %6
%78 = bitcast i32* %77 to i8*
%79 = call i32 @free(i8* %78)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"[ \00"
@.str.2 = [4 x i8] c"%d \00"
@str = [16 x i8] c"Before Sort: \0A\00"
@str.5 = [15 x i8] c"After Sort: \0A\00"
@str.7 = [2 x i8] c"]\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @srand(i32 123456)
%4 = tail call i64 @malloc(i32 4000)
%5 = inttoptr i64 %4 to i32*
br label %6
6: ; preds = %2, %6
%7 = phi i64 [ 0, %2 ], [ %11, %6 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 200
%10 = getelementptr inbounds i32, i32* %5, i64 %7
store i32 %9, i32* %10
%11 = add nuw nsw i64 %7, 1
%12 = icmp eq i64 %11, 1000
br i1 %12, label %13, label %6
13: ; preds = %6
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %5
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %18, %13
%19 = phi i64 [ 1, %13 ], [ %24, %18 ]
%20 = getelementptr inbounds i32, i32* %5, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %19, 999
%24 = add nuw nsw i64 %19, 1
br i1 %23, label %25, label %18
25: ; preds = %18
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
%28 = tail call i32 @quicksort(i32* %5, i32 0, i32 999)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* %5
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %32, %25
%33 = phi i64 [ 1, %25 ], [ %38, %32 ]
%34 = getelementptr inbounds i32, i32* %5, i64 %33
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = icmp eq i64 %33, 999
%38 = add nuw nsw i64 %33, 1
br i1 %37, label %39, label %32
39: ; preds = %32
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
%41 = inttoptr i64 %4 to i8*
%42 = tail call i32 @free(i8* %41)
ret i32 0
}