#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 */
typedef scalar_t__ time_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int atoi(char *);
scalar_t__ clock();
int /*<<< orphan*/ heapSort(int *, int);
int isSane(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, double, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int *vector_fill_almost_sorted(int);
int *vector_fill_few_unique(int);
int *vector_fill_reverse(int);
int *vector_fill_unique(int);
int main(int argc, char *argv[]) {
  int n = atoi(argv[1]);
  int *a = (int *)malloc(sizeof(int) * n);
  int i, j, m, flag;
  srand(time(NULL));
  if (argc > 2) {
    int k = atoi(argv[2]);
    if (k == 1) {
      a = vector_fill_almost_sorted(n);
    } else if (k == 2) {
      a = vector_fill_few_unique(n);
    } else if (k == 3) {
      a = vector_fill_reverse(n);
    } else if (k == 4) {
      a = vector_fill_unique(n);
    }
  } else {
    a = vector_fill_unique(n);
  }
  time_t t = clock();
  heapSort(a, n);
  t = clock() - t;
  printf("%f %d\n", (double)t / CLOCKS_PER_SEC, n);
  return isSane(a, n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmpl   $0x2,-0x8(%rbp)
jle    129e <main+0xde>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jne    123e <main+0x7e>
mov    -0x14(%rbp),%edi
call   1070 <vector_fill_almost_sorted@plt>
mov    %rax,-0x20(%rbp)
jmp    1299 <main+0xd9>
cmpl   $0x2,-0x34(%rbp)
jne    1259 <main+0x99>
mov    -0x14(%rbp),%edi
call   10e0 <vector_fill_few_unique@plt>
mov    %rax,-0x20(%rbp)
jmp    1294 <main+0xd4>
cmpl   $0x3,-0x34(%rbp)
jne    1274 <main+0xb4>
mov    -0x14(%rbp),%edi
call   10d0 <vector_fill_reverse@plt>
mov    %rax,-0x20(%rbp)
jmp    128f <main+0xcf>
cmpl   $0x4,-0x34(%rbp)
jne    128a <main+0xca>
mov    -0x14(%rbp),%edi
call   10a0 <vector_fill_unique@plt>
mov    %rax,-0x20(%rbp)
jmp    128f <main+0xcf>
jmp    1294 <main+0xd4>
jmp    1299 <main+0xd9>
jmp    12aa <main+0xea>
mov    -0x14(%rbp),%edi
call   10a0 <vector_fill_unique@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <heapSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
cvtsi2sdq -0x40(%rbp),%xmm0
mov    0x2d0b(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x14(%rbp),%esi
lea    0xd15(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10b0 <isSane@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
lea    0x0(,%r15,4),%edi
call   1090 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmp    $0x3,%ebp
jl     1226 <main+0x66>
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1231 <main+0x71>
lea    0xded(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %r15d,%edi
call   1070 <vector_fill_almost_sorted@plt>
jmp    122e <main+0x6e>
mov    %r15d,%edi
call   10a0 <vector_fill_unique@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <heapSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2d8c(%rip),%rax
divsd  (%rax),%xmm0
lea    0xda9(%rip),%rdi
mov    %r15d,%esi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <isSane@plt>
mov    %r15d,%edi
call   10e0 <vector_fill_few_unique@plt>
jmp    122e <main+0x6e>
mov    %r15d,%edi
call   10d0 <vector_fill_reverse@plt>
jmp    122e <main+0x6e>

LLVM IR (-O0):
@.str = [7 x i8] c"%f %d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
%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)
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 2
br i1 %27, label %28, label %60
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i32, i32* %6
%37 = call i32* @vector_fill_almost_sorted(i32 %36)
store i32* %37, i32** %7
br label %59
38: ; preds = %28
%39 = load i32, i32* %12
%40 = icmp eq i32 %39, 2
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %6
%43 = call i32* @vector_fill_few_unique(i32 %42)
store i32* %43, i32** %7
br label %58
44: ; preds = %38
%45 = load i32, i32* %12
%46 = icmp eq i32 %45, 3
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %6
%49 = call i32* @vector_fill_reverse(i32 %48)
store i32* %49, i32** %7
br label %57
50: ; preds = %44
%51 = load i32, i32* %12
%52 = icmp eq i32 %51, 4
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* %6
%55 = call i32* @vector_fill_unique(i32 %54)
store i32* %55, i32** %7
br label %56
56: ; preds = %53, %50
br label %57
57: ; preds = %56, %47
br label %58
58: ; preds = %57, %41
br label %59
59: ; preds = %58, %35
br label %63
60: ; preds = %2
%61 = load i32, i32* %6
%62 = call i32* @vector_fill_unique(i32 %61)
store i32* %62, i32** %7
br label %63
63: ; preds = %60, %59
%64 = call i64 (...) @clock()
store i64 %64, i64* %13
%65 = load i32*, i32** %7
%66 = load i32, i32* %6
%67 = call i32 @heapSort(i32* %65, i32 %66)
%68 = call i64 (...) @clock()
%69 = load i64, i64* %13
%70 = sub nsw i64 %68, %69
store i64 %70, i64* %13
%71 = load i64, i64* %13
%72 = sitofp i64 %71 to double
%73 = load double, double* @CLOCKS_PER_SEC
%74 = fdiv double %72, %73
%75 = load i32, i32* %6
%76 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %74, i32 %75)
%77 = load i32*, i32** %7
%78 = load i32, i32* %6
%79 = call i32 @isSane(i32* %77, i32 %78)
ret i32 %79
}

LLVM IR (-O2):
@.str = [7 x i8] c"%f %d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = shl i32 %5, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = tail call i32 @time(i32* null)
%9 = tail call i32 @srand(i32 %8)
%10 = icmp sgt i32 %0, 2
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = inttoptr i64 %7 to i32*
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
switch i32 %15, label %26 [
i32 1, label %16
i32 2, label %18
i32 3, label %20
i32 4, label %22
]
16: ; preds = %11
%17 = tail call i32* @vector_fill_almost_sorted(i32 %5)
br label %26
18: ; preds = %11
%19 = tail call i32* @vector_fill_few_unique(i32 %5)
br label %26
20: ; preds = %11
%21 = tail call i32* @vector_fill_reverse(i32 %5)
br label %26
22: ; preds = %11
%23 = tail call i32* @vector_fill_unique(i32 %5)
br label %26
24: ; preds = %2
%25 = tail call i32* @vector_fill_unique(i32 %5)
br label %26
26: ; preds = %16, %20, %22, %18, %11, %24
%27 = phi i32* [ %25, %24 ], [ %17, %16 ], [ %19, %18 ], [ %21, %20 ], [ %23, %22 ], [ %12, %11 ]
%28 = tail call i64 (...) @clock()
%29 = tail call i32 @heapSort(i32* %27, i32 %5)
%30 = tail call i64 (...) @clock()
%31 = sub nsw i64 %30, %28
%32 = sitofp i64 %31 to double
%33 = load double, double* @CLOCKS_PER_SEC
%34 = fdiv double %32, %33
%35 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %34, i32 %5)
%36 = tail call i32 @isSane(i32* %27, i32 %5)
ret i32 %36
}