#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 isSane(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ mergesort(int *, int /*<<< orphan*/, 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;
  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();
  mergesort(a, 0, n - 1);
  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    $0x30,%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   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
cmpl   $0x2,-0x8(%rbp)
jle    129e <main+0xde>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    123e <main+0x7e>
mov    -0x14(%rbp),%edi
call   1060 <vector_fill_almost_sorted@plt>
mov    %rax,-0x20(%rbp)
jmp    1299 <main+0xd9>
cmpl   $0x2,-0x28(%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,-0x28(%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,-0x28(%rbp)
jne    128a <main+0xca>
mov    -0x14(%rbp),%edi
call   1090 <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   1090 <vector_fill_unique@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   10b0 <mergesort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2d06(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x14(%rbp),%esi
lea    0xd10(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <isSane@plt>
add    $0x30,%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   1080 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <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   1060 <vector_fill_almost_sorted@plt>
jmp    122e <main+0x6e>
mov    %r15d,%edi
call   1090 <vector_fill_unique@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    %r15d,%edx
add    $0xffffffff,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <mergesort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2d87(%rip),%rax
divsd  (%rax),%xmm0
lea    0xda4(%rip),%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 4, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %7
%21 = call i32 @time(i32* null)
%22 = call i32 @srand(i32 %21)
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 2
br i1 %24, label %25, label %57
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %6
%34 = call i32* @vector_fill_almost_sorted(i32 %33)
store i32* %34, i32** %7
br label %56
35: ; preds = %25
%36 = load i32, i32* %9
%37 = icmp eq i32 %36, 2
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* %6
%40 = call i32* @vector_fill_few_unique(i32 %39)
store i32* %40, i32** %7
br label %55
41: ; preds = %35
%42 = load i32, i32* %9
%43 = icmp eq i32 %42, 3
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* %6
%46 = call i32* @vector_fill_reverse(i32 %45)
store i32* %46, i32** %7
br label %54
47: ; preds = %41
%48 = load i32, i32* %9
%49 = icmp eq i32 %48, 4
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* %6
%52 = call i32* @vector_fill_unique(i32 %51)
store i32* %52, i32** %7
br label %53
53: ; preds = %50, %47
br label %54
54: ; preds = %53, %44
br label %55
55: ; preds = %54, %38
br label %56
56: ; preds = %55, %32
br label %60
57: ; preds = %2
%58 = load i32, i32* %6
%59 = call i32* @vector_fill_unique(i32 %58)
store i32* %59, i32** %7
br label %60
60: ; preds = %57, %56
%61 = call i64 (...) @clock()
store i64 %61, i64* %10
%62 = load i32*, i32** %7
%63 = load i32, i32* %6
%64 = sub nsw i32 %63, 1
%65 = call i32 @mergesort(i32* %62, i32 0, i32 %64)
%66 = call i64 (...) @clock()
%67 = load i64, i64* %10
%68 = sub nsw i64 %66, %67
store i64 %68, i64* %10
%69 = load i64, i64* %10
%70 = sitofp i64 %69 to double
%71 = load double, double* @CLOCKS_PER_SEC
%72 = fdiv double %70, %71
%73 = load i32, i32* %6
%74 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %72, i32 %73)
%75 = load i32*, i32** %7
%76 = load i32, i32* %6
%77 = call i32 @isSane(i32* %75, i32 %76)
ret i32 %77
}

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 = add nsw i32 %5, -1
%30 = tail call i32 @mergesort(i32* %27, i32 0, i32 %29)
%31 = tail call i64 (...) @clock()
%32 = sub nsw i64 %31, %28
%33 = sitofp i64 %32 to double
%34 = load double, double* @CLOCKS_PER_SEC
%35 = fdiv double %33, %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %35, i32 %5)
%37 = tail call i32 @isSane(i32* %27, i32 %5)
ret i32 %37
}