// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, 0x88(%rsp)
movabsq $-0xae502812aa7333, %r12 # imm = 0xFF51AFD7ED558CCD
movabsq $-0x3b314601e57a13ad, %r13 # imm = 0xC4CEB9FE1A85EC53
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rax
movaps %xmm0, (%rax)
xorl %r15d, %r15d
movq %r15, 0x10(%rax)
leaq 0x30(%rsp), %rax
movq %r15, 0x10(%rax)
movaps %xmm0, (%rax)
movsd 0xa58(%rip), %xmm0      # 0x2008
movl $0x11, %ebx
movq %rsp, %rbp
movapd %xmm0, 0x20(%rsp)
movapd %xmm0, 0x70(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x88(%rsp), %rax
movq %rax, %r14
testq %rax, %rax
je 0x1646
movq %rbx, %rax
shrq $0x21, %rax
xorq %rbx, %rax
imulq %r12, %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %r13, %rcx
movq %rcx, %rax
shrq $0x21, %rax
xorq %rcx, %rax
movq %rax, 0xa0(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x162e
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x163e
movq %rbp, %rdi
leaq 0xa0(%rsp), %rdx
callq 0x19ac
incq %rbx
decq %r14
jne 0x15e6
movq %r15, 0x98(%rsp)
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
incq %rsi
leaq 0x50(%rsp), %rdi
callq 0x197a
movq %rbx, %rax
shrq $0x21, %rax
xorq %rbx, %rax
imulq %r12, %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %r13, %rcx
movq %rcx, %r15
shrq $0x21, %r15
xorq %rcx, %r15
callq 0x10e0
movq %rax, %rbp
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq 0x50(%rsp), %rcx
movq %r15, %rdi
callq 0x1273
callq 0x10e0
movq %rax, %r14
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
incq %rsi
leaq 0x30(%rsp), %rdi
callq 0x197a
callq 0x10e0
movq %rax, 0x90(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq 0x30(%rsp), %rcx
movq %r15, %rdi
callq 0x12e4
callq 0x10e0
movq %rax, %r15
movq (%rsp), %rdi
testq %rdi, %rdi
movq 0x98(%rsp), %r12
je 0x1725
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
subq %rbp, %r14
cvtsi2sd %r14, %xmm5
incq %rbx
movapd 0x20(%rsp), %xmm3
movapd %xmm3, %xmm0
movsd 0x8ce(%rip), %xmm2      # 0x2010
mulsd %xmm2, %xmm0
movapd %xmm5, %xmm1
divsd %xmm2, %xmm1
cmpltsd %xmm0, %xmm5
andpd %xmm5, %xmm1
andnpd %xmm3, %xmm5
orpd %xmm1, %xmm5
subq 0x90(%rsp), %r15
cvtsi2sd %r15, %xmm4
movapd 0x70(%rsp), %xmm3
movapd %xmm3, %xmm0
mulsd %xmm2, %xmm0
movapd %xmm4, %xmm1
divsd %xmm2, %xmm1
cmpltsd %xmm0, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm3, %xmm4
orpd %xmm1, %xmm4
incq %r12
movapd %xmm5, 0x20(%rsp)
movapd %xmm4, %xmm0
cmpq $0x64, %r12
movq %r12, %r15
movabsq $-0xae502812aa7333, %r12 # imm = 0xFF51AFD7ED558CCD
movq %rsp, %rbp
jne 0x15be
movapd %xmm5, 0x20(%rsp)
movapd %xmm4, 0x70(%rsp)
movq 0x280b(%rip), %rdi      # 0x3fd8
leaq 0x85c(%rip), %rsi       # 0x2030
movl $0xf, %edx
callq 0x10d0
movapd 0x20(%rsp), %xmm0
mulsd 0x824(%rip), %xmm0      # 0x2010
cvttsd2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x817(%rip), %xmm0      # 0x2018
movq 0x27d0(%rip), %rdi      # 0x3fd8
callq 0x1100
movq %rax, %rbx
leaq 0x829(%rip), %rsi       # 0x2040
movl $0x3, %edx
movq %rax, %rdi
callq 0x10d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq 0x2786(%rip), %rdi      # 0x3fd8
leaq 0x7eb(%rip), %rsi       # 0x2044
movl $0x10, %edx
callq 0x10d0
movapd 0x70(%rsp), %xmm0
mulsd 0x79f(%rip), %xmm0      # 0x2010
cvttsd2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x792(%rip), %xmm0      # 0x2018
movq 0x274b(%rip), %rdi      # 0x3fd8
callq 0x1100
movq %rax, %rbx
leaq 0x7a4(%rip), %rsi       # 0x2040
movl $0x3, %edx
movq %rax, %rdi
callq 0x10d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x18e7
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x18fe
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1914
jmp 0x1914
movq %rax, %rbx
jmp 0x1934
jmp 0x191b
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1934
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x194b
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x1962
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1120