#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(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printArray(int *, int, char *);
int /*<<< orphan*/ quicksort(int *, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ validateArgs(int, char **);
int /*<<< orphan*/ validateInput(int);
int /*<<< orphan*/ verifyResult(int *, int);
int main(int argc, char **argv) {
  validateArgs(argc, argv);
  int n;
  sscanf(argv[1], "%d", &n);
  validateInput(n);
  int *array = (int *)malloc(sizeof(int) * n);
  srand(time(NULL));
  int i;
  for (i = 0; i < n; ++i) {
    array[i] = rand() % 1024;
  }
  printArray(array, n, "a: ");
  quicksort(array, n);
  printArray(array, n, "b: ");
  verifyResult(array, n);
  free(array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <validateArgs@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   10b0 <sscanf@plt>
mov    -0x14(%rbp),%edi
call   1080 <validateInput@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1250 <main+0xa0>
mov    $0x0,%al
call   10d0 <rand@plt>
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    121c <main+0x6c>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xda5(%rip),%rdx
call   10c0 <printArray@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <quicksort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xd8a(%rip),%rdx
call   10c0 <printArray@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <verifyResult@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1050 <validateArgs@plt>
mov    0x8(%rbx),%rdi
lea    0xe39(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10b0 <sscanf@plt>
mov    0x4(%rsp),%edi
call   1080 <validateInput@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    123c <main+0x8c>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10d0 <rand@plt>
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffc00,%ecx
sub    %ecx,%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
movslq 0x4(%rsp),%rsi
cmp    %rsi,%rbx
jl     1210 <main+0x60>
lea    0xdc0(%rip),%rdx
mov    %r14,%rdi
call   10c0 <printArray@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1040 <quicksort@plt>
mov    0x4(%rsp),%esi
lea    0xda5(%rip),%rdx
mov    %r14,%rdi
call   10c0 <printArray@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1070 <verifyResult@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"a: \00"
@.str.2 = [4 x i8] c"b: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @validateArgs(i32 %9, i8** %10)
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%16 = load i32, i32* %6
%17 = call i32 @validateInput(i32 %16)
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = mul i64 4, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i32*
store i32* %23, i32** %7
%24 = call i32 @time(i32* null)
%25 = call i32 @srand(i32 %24)
store i32 0, i32* %8
br label %26
26: ; preds = %37, %2
%27 = load i32, i32* %8
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = call i32 (...) @rand()
%32 = srem i32 %31, 1024
%33 = load i32*, i32** %7
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
br label %37
37: ; preds = %30
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %26
40: ; preds = %26
%41 = load i32*, i32** %7
%42 = load i32, i32* %6
%43 = call i32 @printArray(i32* %41, i32 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32*, i32** %7
%45 = load i32, i32* %6
%46 = call i32 @quicksort(i32* %44, i32 %45)
%47 = load i32*, i32** %7
%48 = load i32, i32* %6
%49 = call i32 @printArray(i32* %47, i32 %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32*, i32** %7
%51 = load i32, i32* %6
%52 = call i32 @verifyResult(i32* %50, i32 %51)
%53 = load i32*, i32** %7
%54 = call i32 @free(i32* %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"a: \00"
@.str.2 = [4 x i8] c"b: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = tail call i32 @validateArgs(i32 %0, i8** %1)
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = call i32 @validateInput(i32 %9)
%11 = load i32, i32* %3
%12 = shl i32 %11, 2
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
%15 = call i32 @time(i32* null)
%16 = call i32 @srand(i32 %15)
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %2, %19
%20 = phi i64 [ %24, %19 ], [ 0, %2 ]
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 1024
%23 = getelementptr inbounds i32, i32* %14, i64 %20
store i32 %22, i32* %23
%24 = add nuw nsw i64 %20, 1
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %19, label %28
28: ; preds = %19, %2
%29 = phi i32 [ %17, %2 ], [ %25, %19 ]
%30 = call i32 @printArray(i32* %14, i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* %3
%32 = call i32 @quicksort(i32* %14, i32 %31)
%33 = load i32, i32* %3
%34 = call i32 @printArray(i32* %14, i32 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* %3
%36 = call i32 @verifyResult(i32* %14, i32 %35)
%37 = call i32 @free(i32* %14)
ret i32 0
}