// File: /workspace/github_cpp_makefile_star2_O1/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 0x5703(%rip), %rsi      # 0x7cd8
leaq 0x48(%rsp), %r14
movl $0xd0, %edx
movq %r14, %rdi
callq 0x2100
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %r15
movl $0xd, %edx
movq %r14, %rsi
movq %r15, %rcx
callq 0x28f2
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
cmpl $0x2, %ebp
jl 0x26af
movq 0x8(%rbx), %rsi
leaq 0x48(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x293a
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
cmpq %r12, %rbx
je 0x2682
leaq 0x48(%rsp), %r14
leaq 0x10(%rsp), %r15
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x2060
testl %eax, %eax
jne 0x2679
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x266e
movups (%rbx), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x2679
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2c66
addq $0x10, %rbx
cmpq %r12, %rbx
jne 0x2645
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x2879
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x26be
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2120
jmp 0x26be
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2978
movabsq $0x1234567890abcdef, %rax # imm = 0x1234567890ABCDEF
movq %rax, 0x5a59(%rip)      # 0x8128
movl $0x4c4b400, %edi        # imm = 0x4C4B400
callq 0x2030
movq %rax, %rbx
movq 0x5a45(%rip), %rcx      # 0x8128
xorl %esi, %esi
movabsq $0x60bee2bee120fc15, %rdi # imm = 0x60BEE2BEE120FC15
movabsq $-0x5c4e6acab5c648f3, %r8 # imm = 0xA3B195354A39B70D
movabsq $0x1b03738712fad5c9, %r9 # imm = 0x1B03738712FAD5C9
movabsq $0x9502f9000, %r10      # imm = 0x9502F9000
addq %rdi, %rcx
movq %rcx, %rax
mulq %r8
xorq %rdx, %rax
mulq %r9
xorq %rdx, %rax
mulq %r10
movq %rdx, (%rbx,%rsi,8)
incq %rsi
cmpq $0x989680, %rsi         # imm = 0x989680
jne 0x270d
movq %rcx, 0x59ef(%rip)      # 0x8128
movl $0x4c4b400, %edi        # imm = 0x4C4B400
callq 0x2030
movq %rax, %r14
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x48(%rsp), %rdi
movl $0x8, %esi
xorl %edx, %edx
callq 0x2130
movq 0x48(%rsp), %rdi
movl 0x50(%rsp), %esi
movl $0x989680, %edx         # imm = 0x989680
callq 0x2a4d
movl 0x50(%rsp), %ebp
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x278e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2120
leaq 0x29a1(%rip), %rdi      # 0x5136
leaq 0x299e(%rip), %rdx      # 0x513a
movl %ebp, %esi
xorl %eax, %eax
callq 0x2040
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
cmpq %r13, %r12
je 0x27d2
leaq 0x2984(%rip), %r15      # 0x513f
movq (%r12), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x2040
addq $0x10, %r12
cmpq %r13, %r12
jne 0x27bb
movl $0x3e8, %r12d           # imm = 0x3E8
leaq 0x2964(%rip), %rdi      # 0x5143
movl %ebp, %esi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2040
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %r15
cmpq %r15, %r13
je 0x2811
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x246c
addq $0x10, %r13
jmp 0x27f5
leaq (%r12,%r12), %rax
leaq (%rax,%rax,4), %rax
cmpq $0xf4241, %r12          # imm = 0xF4241
movq %rax, %r12
jb 0x27d8
movl $0xa, %edi
callq 0x2180
movq %r14, %rdi
callq 0x2160
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x284e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2865
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48(%rsp), %rdi
callq 0x2220
jmp 0x288b
jmp 0x288b
jmp 0x28b0
jmp 0x288b
movq %rax, %rbx
jmp 0x28bb
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28bb
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2120
jmp 0x28bb
movq %rax, %rbx
movq %r14, %rdi
callq 0x2160
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x28d2
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x28e9
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21d0
nop