#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 *);
int /*<<< orphan*/ init_arr(int *, size_t);
int *malloc(size_t);
int /*<<< orphan*/ print_arr(int *, size_t);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ quicksort(int *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
scalar_t__ strncmp(char const *, char *, int);
int strtol(char const *, int /*<<< orphan*/ *, int);
size_t strtoul(char const *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(const int argc, const char *argv[]) {
  size_t arg, length = 0;
  int i, quiet = 0;
  int *numbers;
  for (i = 1; i < argc; i++) {
    if (strncmp(argv[i], "-q", 2) == 0) {
      quiet = 1;
    } else {
      arg = strtoul(argv[i], NULL, 10);
      if (strtol(argv[i], NULL, 10) < 2 || arg > 100000000) {
        puts("ERROR: Invalid argument");
        printf("%s\n", argv[i]);
        return 1;
      }
      if (length == 0)
        length = arg;
    }
  }
  if (length == 0)
    length = 64;
  numbers = malloc(length * sizeof(int));
  srandom(time(NULL));
  init_arr(numbers, length);
  if (!quiet) {
    puts("Array:");
    print_arr(numbers, length);
  }
  quicksort(numbers, 0, length - 1);
  if (!quiet) {
    puts("Quicksort:");
    print_arr(numbers, length);
  }
  free(numbers);
  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)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d5 <main+0x115>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdf5(%rip),%rsi
mov    $0x2,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
jne    122b <main+0x6b>
movl   $0x1,-0x28(%rbp)
jmp    12c2 <main+0x102>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10b0 <strtol@plt>
cmp    $0x2,%eax
jl     127a <main+0xba>
cmpq   $0x5f5e100,-0x18(%rbp)
05
jbe    12aa <main+0xea>
lea    0xd82(%rip),%rdi
call   1070 <puts@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd82(%rip),%rdi
call   10a0 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x1bf>
cmpq   $0x0,-0x20(%rbp)
jne    12bd <main+0xfd>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    12c2 <main+0x102>
jmp    12c7 <main+0x107>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ec <main+0x2c>
cmpq   $0x0,-0x20(%rbp)
jne    12e8 <main+0x128>
movq   $0x40,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
shl    $0x2,%rdi
call   10d0 <malloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1050 <srandom@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <init_arr@plt>
cmpl   $0x0,-0x28(%rbp)
jne    1339 <main+0x179>
lea    0xcf8(%rip),%rdi
call   1070 <puts@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <print_arr@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
xor    %esi,%esi
call   1090 <quicksort@plt>
cmpl   $0x0,-0x28(%rbp)
jne    136f <main+0x1af>
lea    0xcc9(%rip),%rdi
call   1070 <puts@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <print_arr@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
cmp    $0x2,%edi
jl     1273 <main+0xb3>
mov    %rsi,%r12
mov    %edi,%r13d
xor    %eax,%eax
mov    %rax,(%rsp)
mov    $0x1,%ebp
lea    0xe12(%rip),%r15
xor    %r14d,%r14d
jmp    1212 <main+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%eax
mov    %rax,(%rsp)
add    $0x1,%rbp
cmp    %rbp,%r13
je     126a <main+0xaa>
mov    (%r12,%rbp,8),%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
je     1200 <main+0x40>
mov    (%r12,%rbp,8),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %rax,%rbx
mov    (%r12,%rbp,8),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10b0 <strtol@plt>
cmp    $0x2,%eax
jl     1301 <main+0x141>
cmp    $0x5f5e101,%rbx
jae    1301 <main+0x141>
test   %r14,%r14
cmove  %rbx,%r14
jmp    1209 <main+0x49>
test   %r14,%r14
mov    (%rsp),%rbp
jne    1279 <main+0xb9>
mov    $0x40,%r14d
lea    0x0(,%r14,4),%rdi
call   10d0 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1050 <srandom@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <init_arr@plt>
test   %ebp,%ebp
je     12b9 <main+0xf9>
add    $0xffffffffffffffff,%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1090 <quicksort@plt>
jmp    12f5 <main+0x135>
lea    0xd5f(%rip),%rdi
call   1070 <puts@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <print_arr@plt>
lea    -0x1(%r14),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <quicksort@plt>
lea    0xd41(%rip),%rdi
call   1070 <puts@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <print_arr@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    1322 <main+0x162>
lea    0xcfb(%rip),%rdi
call   1070 <puts@plt>
mov    (%r12,%rbp,8),%rsi
lea    0xd03(%rip),%rdi
call   10a0 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-q\00"
@.str.1 = [24 x i8] c"ERROR: Invalid argument\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [7 x i8] c"Array:\00"
@.str.4 = [11 x i8] c"Quicksort:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
store i32 0, i32* %9
store i32 1, i32* %8
br label %11
11: ; preds = %56, %2
%12 = load i32, i32* %8
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %59
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %15
store i32 1, i32* %9
br label %55
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strtoul(i8* %29, i32* null, i32 10)
store i64 %30, i64* %6
%31 = load i8**, i8*** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @strtol(i8* %35, i32* null, i32 10)
%37 = icmp slt i32 %36, 2
br i1 %37, label %41, label %38
38: ; preds = %24
%39 = load i64, i64* %6
%40 = icmp ugt i64 %39, 100000000
br i1 %40, label %41, label %49
41: ; preds = %38, %24
%42 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%43 = load i8**, i8*** %5
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %47)
store i32 1, i32* %3
br label %94
49: ; preds = %38
%50 = load i64, i64* %7
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = load i64, i64* %6
store i64 %53, i64* %7
br label %54
54: ; preds = %52, %49
br label %55
55: ; preds = %54, %23
br label %56
56: ; preds = %55
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %11
59: ; preds = %11
%60 = load i64, i64* %7
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
store i64 64, i64* %7
br label %63
63: ; preds = %62, %59
%64 = load i64, i64* %7
%65 = mul i64 %64, 4
%66 = call i32* @malloc(i64 %65)
store i32* %66, i32** %10
%67 = call i32 @time(i32* null)
%68 = call i32 @srandom(i32 %67)
%69 = load i32*, i32** %10
%70 = load i64, i64* %7
%71 = call i32 @init_arr(i32* %69, i64 %70)
%72 = load i32, i32* %9
%73 = icmp ne i32 %72, 0
br i1 %73, label %79, label %74
74: ; preds = %63
%75 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%76 = load i32*, i32** %10
%77 = load i64, i64* %7
%78 = call i32 @print_arr(i32* %76, i64 %77)
br label %79
79: ; preds = %74, %63
%80 = load i32*, i32** %10
%81 = load i64, i64* %7
%82 = sub i64 %81, 1
%83 = call i32 @quicksort(i32* %80, i32 0, i64 %82)
%84 = load i32, i32* %9
%85 = icmp ne i32 %84, 0
br i1 %85, label %91, label %86
86: ; preds = %79
%87 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%88 = load i32*, i32** %10
%89 = load i64, i64* %7
%90 = call i32 @print_arr(i32* %88, i64 %89)
br label %91
91: ; preds = %86, %79
%92 = load i32*, i32** %10
%93 = call i32 @free(i32* %92)
store i32 0, i32* %3
br label %94
94: ; preds = %91, %41
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [3 x i8] c"-q\00"
@.str.1 = [24 x i8] c"ERROR: Invalid argument\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [7 x i8] c"Array:\00"
@.str.4 = [11 x i8] c"Quicksort:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %36
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %29
%7 = phi i64 [ 1, %4 ], [ %32, %29 ]
%8 = phi i32 [ 0, %4 ], [ %31, %29 ]
%9 = phi i64 [ 0, %4 ], [ %30, %29 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %7
%11 = load i8*, i8** %10
%12 = tail call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %6
%15 = load i8*, i8** %10
%16 = tail call i64 @strtoul(i8* nocapture %15, i32* null, i32 10)
%17 = load i8*, i8** %10
%18 = tail call i32 @strtol(i8* nocapture %17, i32* null, i32 10)
%19 = icmp slt i32 %18, 2
%20 = icmp ugt i64 %16, 100000000
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%24 = load i8*, i8** %10
%25 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %59
26: ; preds = %14
%27 = icmp eq i64 %9, 0
%28 = select i1 %27, i64 %16, i64 %9
br label %29
29: ; preds = %26, %6
%30 = phi i64 [ %9, %6 ], [ %28, %26 ]
%31 = phi i32 [ 1, %6 ], [ %8, %26 ]
%32 = add nuw nsw i64 %7, 1
%33 = icmp eq i64 %32, %5
br i1 %33, label %34, label %6
34: ; preds = %29
%35 = icmp eq i64 %30, 0
br i1 %35, label %36, label %38
36: ; preds = %2, %34
%37 = phi i32 [ %31, %34 ], [ 0, %2 ]
br label %38
38: ; preds = %34, %36
%39 = phi i32 [ %37, %36 ], [ %31, %34 ]
%40 = phi i64 [ 64, %36 ], [ %30, %34 ]
%41 = shl i64 %40, 2
%42 = tail call i32* @malloc(i64 %41)
%43 = tail call i32 @time(i32* null)
%44 = tail call i32 @srandom(i32 %43)
%45 = tail call i32 @init_arr(i32* %42, i64 %40)
%46 = icmp eq i32 %39, 0
br i1 %46, label %47, label %54
47: ; preds = %38
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%49 = tail call i32 @print_arr(i32* %42, i64 %40)
%50 = add i64 %40, -1
%51 = tail call i32 @quicksort(i32* %42, i32 0, i64 %50)
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%53 = tail call i32 @print_arr(i32* %42, i64 %40)
br label %57
54: ; preds = %38
%55 = add i64 %40, -1
%56 = tail call i32 @quicksort(i32* %42, i32 0, i64 %55)
br label %57
57: ; preds = %54, %47
%58 = tail call i32 @free(i32* %42)
br label %59
59: ; preds = %57, %22
%60 = phi i32 [ 1, %22 ], [ 0, %57 ]
ret i32 %60
}