// File: lemire[P]backward_multiplication/benchmarks/benchmark.cpp
// Function: demo(unsigned long)
void demo(size_t integer_size = 32) {
  size_t seed = 17;
  std::vector<uint64_t> out1, out2;
  std::chrono::time_point<std::chrono::steady_clock> start_clock, end_clock;
  std::chrono::duration<double> elapsed1 = std::chrono::duration<double>::max();
  std::chrono::duration<double> elapsed2 = std::chrono::duration<double>::max();

  for (size_t t = 0; t < 100; t++) {
    std::vector<uint64_t> v;
    for(size_t i = 0; i < integer_size; i++) v.push_back(rng(seed++));
    uint64_t multiplier = rng(seed++);
    out1.resize(v.size() + 1);
    start_clock = std::chrono::steady_clock::now();
    backwardmultiply::multiplication(multiplier, v.data(), v.size(),
                                     out1.data());

    end_clock = std::chrono::steady_clock::now();
    elapsed1 =
        end_clock - start_clock < elapsed1 ? end_clock - start_clock : elapsed1;
    out2.resize(v.size() + 1);
    start_clock = std::chrono::steady_clock::now();
    backwardmultiply::multiplication_backward(multiplier, v.data(), v.size(),
                                              out2.data());
    end_clock = std::chrono::steady_clock::now();
    elapsed2 =
        end_clock - start_clock < elapsed2 ? end_clock - start_clock : elapsed2;

  }
    std::cout
      << "forward      : "
      << std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed1).count() /
             128.0
      << " ns" << std::endl;
    std::cout
      << "backward      : "
      << std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed2).count() /
             128.0
      << " ns" << std::endl;
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x1d0(%rsp)
movq $0x11, 0x1c8(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x2250
leaq 0x198(%rsp), %rdi
callq 0x2250
leaq 0x190(%rsp), %rdi
callq 0x2260
jmp 0x1b64
leaq 0x178(%rsp), %rdi
callq 0x2260
jmp 0x1b73
movq 0x249e(%rip), %rax      # 0x4018
movq %rax, 0x170(%rsp)
movq 0x248f(%rip), %rax      # 0x4018
movq %rax, 0x168(%rsp)
movq $0x0, 0x160(%rsp)
cmpq $0x64, 0x160(%rsp)
jae 0x1fd3
leaq 0x148(%rsp), %rdi
callq 0x2250
movq $0x0, 0x140(%rsp)
movq 0x140(%rsp), %rax
cmpq 0x1d0(%rsp), %rax
jae 0x1c7e
movq 0x1c8(%rsp), %rdi
movq %rdi, %rax
incq %rax
movq %rax, 0x1c8(%rsp)
callq 0x2160
movq %rax, 0xc8(%rsp)
jmp 0x1c00
movq 0xc8(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x2290
jmp 0x1c27
jmp 0x1c29
movq 0x140(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x140(%rsp)
jmp 0x1bc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
jmp 0x2135
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x188(%rsp)
movl %eax, 0x184(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x2490
jmp 0x2135
movq 0x1c8(%rsp), %rdi
movq %rdi, %rax
incq %rax
movq %rax, 0x1c8(%rsp)
callq 0x2160
movq %rax, 0xc0(%rsp)
jmp 0x1ca3
movq 0xc0(%rsp), %rax
movq %rax, 0x130(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x2360
movq %rax, %rsi
incq %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x22c0
jmp 0x1cd5
callq 0x10d0
movq %rax, 0x128(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x148(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x2380
movq 0xa0(%rsp), %rdi
movq %rax, 0xb0(%rsp)
callq 0x2360
movq %rax, 0xb8(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x2380
movq 0xa8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq %rax, %rcx
callq 0x12c0
jmp 0x1d63
callq 0x10d0
movq %rax, 0x120(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x178(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x2400
movq %rax, 0x98(%rsp)
jmp 0x1d9f
movq 0x98(%rsp), %rax
movq %rax, 0x110(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x23a0
movb %al, 0x97(%rsp)
jmp 0x1dcd
movb 0x97(%rsp), %al
testb $0x1, %al
jne 0x1dda
jmp 0x1e22
leaq 0x178(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x2400
movq %rax, 0x88(%rsp)
jmp 0x1df9
movq 0x88(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x2450
jmp 0x1e20
jmp 0x1e32
movq 0x170(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x170(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x2360
movq %rax, %rsi
incq %rsi
leaq 0x198(%rsp), %rdi
callq 0x22c0
jmp 0x1e64
callq 0x10d0
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x148(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x2380
movq 0x68(%rsp), %rdi
movq %rax, 0x78(%rsp)
callq 0x2360
movq %rax, 0x80(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x2380
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq %rax, %rcx
callq 0x13f0
jmp 0x1ee0
callq 0x10d0
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x178(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x2400
movq %rax, 0x60(%rsp)
jmp 0x1f19
movq 0x60(%rsp), %rax
movq %rax, 0xe8(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x23a0
movb %al, 0x5f(%rsp)
jmp 0x1f41
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0x1f4b
jmp 0x1f8d
leaq 0x178(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x2400
movq %rax, 0x50(%rsp)
jmp 0x1f67
movq 0x50(%rsp), %rax
movq %rax, 0xe0(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x2450
jmp 0x1f8b
jmp 0x1f9d
movq 0x168(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x168(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x2490
movq 0x160(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x160(%rsp)
jmp 0x1b9d
movq 0x4ffe(%rip), %rdi      # 0x6fd8
leaq 0x203f(%rip), %rsi      # 0x4020
callq 0x1090
movq %rax, 0x48(%rsp)
jmp 0x1fed
leaq 0x170(%rsp), %rdi
callq 0x24f0
movq %rax, 0x40(%rsp)
jmp 0x2001
movq 0x40(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x2520
movq %rax, 0x38(%rsp)
jmp 0x2022
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x1fcf(%rip), %xmm1     # 0x4008
mulsd %xmm1, %xmm0
callq 0x1130
movq %rax, 0x30(%rsp)
jmp 0x2049
movq 0x30(%rsp), %rdi
leaq 0x1fdb(%rip), %rsi      # 0x4030
callq 0x1090
movq %rax, 0x28(%rsp)
jmp 0x2061
movq 0x28(%rsp), %rdi
movq 0x4f5b(%rip), %rsi      # 0x6fc8
callq 0x10c0
jmp 0x2074
movq 0x4f5d(%rip), %rdi      # 0x6fd8
leaq 0x1fb2(%rip), %rsi      # 0x4034
callq 0x1090
movq %rax, 0x20(%rsp)
jmp 0x208e
leaq 0x168(%rsp), %rdi
callq 0x24f0
movq %rax, 0x18(%rsp)
jmp 0x20a2
movq 0x18(%rsp), %rax
movq %rax, 0xd0(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x2520
movq %rax, 0x10(%rsp)
jmp 0x20c3
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x1f2e(%rip), %xmm1     # 0x4008
mulsd %xmm1, %xmm0
callq 0x1130
movq %rax, 0x8(%rsp)
jmp 0x20ea
movq 0x8(%rsp), %rdi
leaq 0x1f3a(%rip), %rsi      # 0x4030
callq 0x1090
movq %rax, (%rsp)
jmp 0x2101
movq (%rsp), %rdi
movq 0x4ebc(%rip), %rsi      # 0x6fc8
callq 0x10c0
jmp 0x2113
leaq 0x198(%rsp), %rdi
callq 0x2490
leaq 0x1b0(%rsp), %rdi
callq 0x2490
addq $0x1d8, %rsp            # imm = 0x1D8
retq
leaq 0x198(%rsp), %rdi
callq 0x2490
leaq 0x1b0(%rsp), %rdi
callq 0x2490
movq 0x188(%rsp), %rdi
callq 0x1120
nopl (%rax)