// File: /workspace/github_cpp_makefile_star2_O2/travisdowns[P]sort-bench/bench.cpp
// Function: main
int main(int argc, char** argv) {

  std::vector<sort_algo> all_algos = {
    {"qsort", qsort_sort},
    {"qsort-inlined", qsort_inlined},
    {"std::sort", std_sort},
    {"std::stable_sort", std_stable_sort},
    {"std::partial_sort", std_partial_sort},
    {"radix1", radix_sort1},
    {"radix2", radix_sort2},
    {"radix3", radix_sort3},
    {"radix4", radix_sort4},
    {"radix5", radix_sort5},
    {"radix6", radix_sort6},
    {"radix7", radix_sort7},
    {"qsort-recompiled", qsort_recompiled},
  }, selected_algos;

  if (argc > 1) {
    // test name provided, look for that test
    const std::string test_name = argv[1];
    for (auto& algo : all_algos) {
      if (test_name == algo.name) {
        selected_algos.push_back(algo);
      }
    }
    if (selected_algos.empty()) {
      fprintf(stderr, "No test named %s\n", test_name.c_str());
      exit(1);
    }
  } else {
    selected_algos = all_algos;
  }

  wyhash64_seed(0x1234567890ABCDEFull);

  uint64_t* temp = new uint64_t[max_size];
  fill_N(0, range_max, max_size, temp);
  const uint64_t* input = temp;

  // allocate a temporary buffer of the same size as the input array (max_size),
  // which the benchmark function uses as the input to each algorithm (since we)
  // won't want to destroy the original
  auto temp_buffer = std::unique_ptr<uint64_t[]>(new uint64_t[max_size]);
  // auto temp_buffer = make_huge_array<uint64_t>(max_size, true);

  int size_width = std::to_string(max_size).size();
  printf("%*s", size_width, "size");
  for (auto& algo : selected_algos) {
    printf(",%s", algo.name);
  }

  for (size_t size = min_size; size <= max_size; size *= 10) {
    printf("\n%*zu", size_width, size);
    for (auto& algo : selected_algos) {
      bench_one(algo, input, temp_buffer.get(), size);
    }
  }
  printf("\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x5804(%rip), %rsi      # 0x7cd8
leaq 0x48(%rsp), %r14
movl $0xd0, %edx
movq %r14, %rdi
callq 0x2130
leaq 0x30(%rsp), %rdi
pushq $0xd
popq %rdx
leaq 0x10(%rsp), %r15
movq %r14, %rsi
movq %r15, %rcx
callq 0x279e
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
cmpl $0x2, %ebp
jl 0x255b
movq 0x8(%rbx), %rsi
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x27d8
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
leaq 0x48(%rsp), %r14
leaq 0x10(%rsp), %r15
cmpq %r12, %rbx
je 0x256c
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x2813
testb %al, %al
je 0x2555
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2820
addq $0x10, %rbx
jmp 0x2536
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x283e
jmp 0x2586
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x26b5
leaq 0x48(%rsp), %rdi
callq 0x20b0
movabsq $0x1234567890abcdef, %rax # imm = 0x1234567890ABCDEF
movq %rax, 0x5ba9(%rip)      # 0x8140
movl $0x4c4b400, %edi        # imm = 0x4C4B400
callq 0x2030
movq %rax, %rbx
movabsq $0x9502f9000, %rsi      # imm = 0x9502F9000
movl $0x989680, %edx         # imm = 0x989680
xorl %edi, %edi
movq %rax, %rcx
callq 0x235d
movl $0x4c4b400, %edi        # imm = 0x4C4B400
callq 0x2030
movq %rax, 0x8(%rsp)
leaq 0x48(%rsp), %rdi
movl $0x989680, %esi         # imm = 0x989680
callq 0x2908
leaq 0x48(%rsp), %rdi
movl 0x8(%rdi), %ebp
callq 0x20b0
leaq 0x2b47(%rip), %rdi      # 0x5136
leaq 0x2b44(%rip), %rdx      # 0x513a
movl %ebp, %esi
xorl %eax, %eax
callq 0x2040
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
leaq 0x2b2f(%rip), %r14      # 0x513f
cmpq %r12, %r15
je 0x2628
movq (%r15), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x2040
addq $0x10, %r15
jmp 0x2610
movl $0x3e8, %r14d           # imm = 0x3E8
leaq 0x2b0e(%rip), %r15      # 0x5143
cmpq $0x989681, %r14         # imm = 0x989681
jae 0x267b
movq %r15, %rdi
movl %ebp, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2040
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
cmpq %r13, %r12
je 0x2675
movq 0x8(%rsp), %rdx
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rcx
callq 0x23cb
addq $0x10, %r12
jmp 0x2657
imulq $0xa, %r14, %r14
jmp 0x2635
pushq $0xa
popq %rdi
callq 0x21b0
leaq 0x8(%rsp), %rdi
callq 0x294a
leaq 0x10(%rsp), %rdi
callq 0x2af4
leaq 0x30(%rsp), %rdi
callq 0x2af4
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x591c(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
movq 0x48(%rsp), %rdx
leaq 0x2a59(%rip), %rsi      # 0x5124
xorl %eax, %eax
callq 0x21c0
pushq $0x1
popq %rdi
callq 0x2180
jmp 0x26e2
jmp 0x26e2
jmp 0x26f6
jmp 0x26e2
movq %rax, %rbx
jmp 0x2703
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20b0
jmp 0x2703
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x294a
leaq 0x10(%rsp), %rdi
callq 0x2af4
leaq 0x30(%rsp), %rdi
callq 0x2af4
movq %rbx, %rdi
callq 0x2200