#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ quickSort(int *, int);
int /*<<< orphan*/ reverse(int *, int);
int main() {
  int n = 1000;
  int *a = (int *)malloc(sizeof(int) * n);
  for (int i = 0; i < n; ++i)
    a[i] = i * 2;
  for (int i = 0; i < 1000; ++i) {
    quickSort(a, n);
    reverse(a, n);
  }
  printf("a[0] = %d\n", a[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119b <main+0x5b>
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <main+0x30>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jge    11d5 <main+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <quickSort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <reverse@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0xfa0,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movdqa 0xea8(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xeab(%rip),%xmm1
movdqa 0xeb3(%rip),%xmm2
nopl   (%rax)
movdqa %xmm0,%xmm3
paddd  %xmm0,%xmm3
movdqu %xmm3,-0x30(%rbx,%rax,4)
paddd  %xmm1,%xmm3
movdqu %xmm3,-0x20(%rbx,%rax,4)
cmp    $0x3ec,%rax
je     11b5 <main+0x75>
movdqa %xmm0,%xmm3
paddd  %xmm1,%xmm3
paddd  %xmm3,%xmm3
movdqu %xmm3,-0x10(%rbx,%rax,4)
paddd  %xmm1,%xmm3
movdqu %xmm3,(%rbx,%rax,4)
paddd  %xmm2,%xmm0
add    $0x10,%rax
jmp    1170 <main+0x30>
mov    $0x3e8,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1060 <quickSort@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1030 <reverse@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x80>
mov    (%rbx),%esi
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"a[0] = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1000, i32* %2
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 4, %7
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %3
store i32 0, i32* %4
br label %12
12: ; preds = %23, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i32, i32* %4
%18 = mul nsw i32 %17, 2
%19 = load i32*, i32** %3
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
store i32 %18, i32* %22
br label %23
23: ; preds = %16
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %12
26: ; preds = %12
store i32 0, i32* %5
br label %27
27: ; preds = %37, %26
%28 = load i32, i32* %5
%29 = icmp slt i32 %28, 1000
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i32*, i32** %3
%32 = load i32, i32* %2
%33 = call i32 @quickSort(i32* %31, i32 %32)
%34 = load i32*, i32** %3
%35 = load i32, i32* %2
%36 = call i32 @reverse(i32* %34, i32 %35)
br label %37
37: ; preds = %30
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %27
40: ; preds = %27
%41 = load i32*, i32** %3
%42 = getelementptr inbounds i32, i32* %41, i64 0
%43 = load i32, i32* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"a[0] = %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4000)
%2 = inttoptr i64 %1 to i32*
br label %3
3: ; preds = %16, %0
%4 = phi i64 [ 0, %0 ], [ %24, %16 ]
%5 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %25, %16 ]
%6 = getelementptr inbounds i32, i32* %2, i64 %4
%7 = shl <4 x i32> %5, <i32 1, i32 1, i32 1, i32 1>
%8 = shl <4 x i32> %5, <i32 1, i32 1, i32 1, i32 1>
%9 = add <4 x i32> %8, <i32 8, i32 8, i32 8, i32 8>
%10 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %6, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %9, <4 x i32>* %12
%13 = or i64 %4, 8
%14 = add <4 x i32> %5, <i32 8, i32 8, i32 8, i32 8>
%15 = icmp eq i64 %13, 1000
br i1 %15, label %29, label %16
16: ; preds = %3
%17 = getelementptr inbounds i32, i32* %2, i64 %13
%18 = shl <4 x i32> %14, <i32 1, i32 1, i32 1, i32 1>
%19 = shl <4 x i32> %14, <i32 1, i32 1, i32 1, i32 1>
%20 = add <4 x i32> %19, <i32 8, i32 8, i32 8, i32 8>
%21 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %17, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %23
%24 = add nuw nsw i64 %4, 16
%25 = add <4 x i32> %5, <i32 16, i32 16, i32 16, i32 16>
br label %3
26: ; preds = %29
%27 = load i32, i32* %2
%28 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
29: ; preds = %3, %29
%30 = phi i32 [ %33, %29 ], [ 0, %3 ]
%31 = tail call i32 @quickSort(i32* %2, i32 1000)
%32 = tail call i32 @reverse(i32* %2, i32 1000)
%33 = add nuw nsw i32 %30, 1
%34 = icmp eq i32 %33, 1000
br i1 %34, label %26, label %29
}