#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 int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ critbit_sort(uintptr_t *const, size_t const);
int /*<<< orphan*/ free(uintptr_t *const);
double get_time();
int /*<<< orphan*/ init_array(uintptr_t *const, size_t const);
uintptr_t *malloc(int);
int /*<<< orphan*/ print_performance(double, size_t const);
int /*<<< orphan*/ printf(char *, size_t const, size_t const);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
void test_sort(const size_t n, const size_t m) {
  printf("test_sort(n=%zu, m=%zu)", n, m);
  uintptr_t *const a = malloc(sizeof(a[0]) * n);
  double total_time = 0;
  srand(0);
  for (size_t i = 0; i < m / n; ++i) {
    init_array(a, n);
    double start = get_time();
    critbit_sort(a, n);
    double end = get_time();
    total_time += end - start;
  }
  print_performance(total_time, m);
  free(a);
}


x86 assembly (clang, -O0):
<test_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe61(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xor    %edi,%edi
call   1070 <srand@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x8(%rbp)
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jae    1249 <test_sort+0xc9>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <init_array@plt>
mov    $0x0,%al
call   1080 <get_time@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <critbit_sort@plt>
mov    $0x0,%al
call   1080 <get_time@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11ce <test_sort+0x4e>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rdi
call   1040 <print_performance@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xe66(%rip),%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
lea    0x0(,%r13,8),%edi
call   1090 <malloc@plt>
mov    %rax,%r15
xor    %edi,%edi
call   1070 <srand@plt>
xorpd  %xmm0,%xmm0
cmp    %r14,%r13
ja     1251 <test_sort+0xd1>
mov    %r14,%rax
or     %r13,%rax
shr    $0x20,%rax
je     11df <test_sort+0x5f>
mov    %r14,%rax
xor    %edx,%edx
div    %r13
jmp    11e7 <test_sort+0x67>
mov    %r14d,%eax
xor    %edx,%edx
div    %r13d
cmp    $0x2,%rax
mov    $0x1,%r12d
cmovae %rax,%r12
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <init_array@plt>
xor    %eax,%eax
call   1080 <get_time@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
call   10a0 <critbit_sort@plt>
xor    %eax,%eax
call   1080 <get_time@plt>
subsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %r12,%rbx
jne    1200 <test_sort+0x80>
mov    %r14,%rdi
call   1040 <print_performance@plt>
mov    %r15,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"test_sort(n=%zu, m=%zu)\00"
define void @test_sort(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64*
%6 = alloca double
%7 = alloca i64
%8 = alloca double
%9 = alloca double
store i64 %0, i64* %3
store i64 %1, i64* %4
%10 = load i64, i64* %3
%11 = load i64, i64* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %10, i64 %11)
%13 = load i64, i64* %3
%14 = mul i64 8, %13
%15 = trunc i64 %14 to i32
%16 = call i64* @malloc(i32 %15)
store i64* %16, i64** %5
store double 0.000000e+00, double* %6
%17 = call i32 @srand(i32 0)
store i64 0, i64* %7
br label %18
18: ; preds = %38, %2
%19 = load i64, i64* %7
%20 = load i64, i64* %4
%21 = load i64, i64* %3
%22 = udiv i64 %20, %21
%23 = icmp ult i64 %19, %22
br i1 %23, label %24, label %41
24: ; preds = %18
%25 = load i64*, i64** %5
%26 = load i64, i64* %3
%27 = call i32 @init_array(i64* %25, i64 %26)
%28 = call double (...) @get_time()
store double %28, double* %8
%29 = load i64*, i64** %5
%30 = load i64, i64* %3
%31 = call i32 @critbit_sort(i64* %29, i64 %30)
%32 = call double (...) @get_time()
store double %32, double* %9
%33 = load double, double* %9
%34 = load double, double* %8
%35 = fsub double %33, %34
%36 = load double, double* %6
%37 = fadd double %36, %35
store double %37, double* %6
br label %38
38: ; preds = %24
%39 = load i64, i64* %7
%40 = add i64 %39, 1
store i64 %40, i64* %7
br label %18
41: ; preds = %18
%42 = load double, double* %6
%43 = load i64, i64* %4
%44 = call i32 @print_performance(double %42, i64 %43)
%45 = load i64*, i64** %5
%46 = call i32 @free(i64* %45)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"test_sort(n=%zu, m=%zu)\00"
define void @test_sort(i64 %0, i64 %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %1)
%4 = trunc i64 %0 to i32
%5 = shl i32 %4, 3
%6 = tail call i64* @malloc(i32 %5)
%7 = tail call i32 @srand(i32 0)
%8 = icmp ugt i64 %0, %1
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = udiv i64 %1, %0
%11 = call i64 @llvm.umax.i64(i64 %10, i64 1)
br label %16
12: ; preds = %16, %2
%13 = phi double [ 0.000000e+00, %2 ], [ %24, %16 ]
%14 = tail call i32 @print_performance(double %13, i64 %1)
%15 = tail call i32 @free(i64* %6)
ret void
16: ; preds = %9, %16
%17 = phi double [ %24, %16 ], [ 0.000000e+00, %9 ]
%18 = phi i64 [ %25, %16 ], [ 0, %9 ]
%19 = tail call i32 @init_array(i64* %6, i64 %0)
%20 = tail call double (...) @get_time()
%21 = tail call i32 @critbit_sort(i64* %6, i64 %0)
%22 = tail call double (...) @get_time()
%23 = fsub double %22, %20
%24 = fadd double %17, %23
%25 = add nuw i64 %18, 1
%26 = icmp eq i64 %25, %11
br i1 %26, label %12, label %16
}