// File: /workspace/github_cpp_makefile_star2_O3/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 0x5708(%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 0x295c
pxor %xmm0, %xmm0
movdqa %xmm0, (%r15)
movq $0x0, 0x10(%r15)
cmpl $0x2, %ebp
jl 0x26ae
movq 0x8(%rbx), %rsi
leaq 0x48(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x29a4
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r12
cmpq %r12, %rbx
je 0x2681
leaq 0x48(%rsp), %r14
leaq 0x10(%rsp), %r15
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x2060
testl %eax, %eax
jne 0x2678
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x266d
movdqu (%rbx), %xmm0
movdqu %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x2678
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2cdc
addq $0x10, %rbx
cmpq %r12, %rbx
jne 0x2642
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x28e3
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x26bd
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2120
jmp 0x26bd
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x29e2
movabsq $0x1234567890abcdef, %rax # imm = 0x1234567890ABCDEF
movq %rax, 0x5a5a(%rip)      # 0x8128
movl $0x4c4b400, %edi        # imm = 0x4C4B400
callq 0x2030
movq %rax, %rbx
movdqa 0x294d(%rip), %xmm0     # 0x5030
xorl %r8d, %r8d
movdqa 0x2952(%rip), %xmm1     # 0x5040
movabsq $-0x5c4e6acab5c648f3, %r9 # imm = 0xA3B195354A39B70D
movabsq $0x1b03738712fad5c9, %r10 # imm = 0x1B03738712FAD5C9
movabsq $0x9502f9000, %r11      # imm = 0x9502F9000
movdqa 0x293c(%rip), %xmm2     # 0x5050
movdqa %xmm0, %xmm3
paddq %xmm1, %xmm3
movq %xmm3, %rcx
pshufd $0xee, %xmm3, %xmm3     # xmm3 = xmm3[2,3,2,3]
movq %xmm3, %rax
mulq %r9
movq %rdx, %rsi
movq %rax, %rdi
movq %rcx, %rax
mulq %r9
movq %rax, %rcx
xorq %rdx, %rcx
xorq %rdi, %rsi
movq %rsi, %rax
mulq %r10
movq %rdx, %rsi
movq %rax, %rdi
movq %rcx, %rax
mulq %r10
movq %rax, %rcx
xorq %rdx, %rcx
xorq %rdi, %rsi
movq %rsi, %rax
mulq %r11
movq %rdx, %rsi
movq %rcx, %rax
mulq %r11
movq %rdx, %xmm3
movq %rsi, %xmm4
punpcklqdq %xmm4, %xmm3    # xmm3 = xmm3[0],xmm4[0]
movdqu %xmm3, (%rbx,%r8,8)
addq $0x2, %r8
paddq %xmm2, %xmm0
cmpq $0x989680, %r8          # imm = 0x989680
jne 0x2714
movabsq $-0x1428c697dea9d991, %rax # imm = 0xEBD739682156266F
movq %rax, 0x5985(%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 0x2ac5
movl 0x50(%rsp), %ebp
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x27f8
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2120
leaq 0x2967(%rip), %rdi      # 0x5166
leaq 0x2964(%rip), %rdx      # 0x516a
movl %ebp, %esi
xorl %eax, %eax
callq 0x2040
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
cmpq %r13, %r12
je 0x283c
leaq 0x294a(%rip), %r15      # 0x516f
movq (%r12), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x2040
addq $0x10, %r12
cmpq %r13, %r12
jne 0x2825
movl $0x3e8, %r12d           # imm = 0x3E8
leaq 0x292a(%rip), %rdi      # 0x5173
movl %ebp, %esi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2040
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %r15
cmpq %r15, %r13
je 0x287b
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x246c
addq $0x10, %r13
jmp 0x285f
leaq (%r12,%r12), %rax
leaq (%rax,%rax,4), %rax
cmpq $0xf4241, %r12          # imm = 0xF4241
movq %rax, %r12
jb 0x2842
movl $0xa, %edi
callq 0x2180
movq %r14, %rdi
callq 0x2160
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x28b8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x28cf
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 0x28f5
jmp 0x28f5
jmp 0x291a
jmp 0x28f5
movq %rax, %rbx
jmp 0x2925
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2925
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2120
jmp 0x2925
movq %rax, %rbx
movq %r14, %rdi
callq 0x2160
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x293c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2953
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21d0
nop