// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %rdi, %rbx
movabsq $-0xae502812aa7333, %rbp # imm = 0xFF51AFD7ED558CCD
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rax
movaps %xmm0, (%rax)
xorl %r12d, %r12d
movq %r12, 0x10(%rax)
leaq 0x30(%rsp), %rax
movq %r12, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x1(%rdi), %rax
movq %rax, 0x88(%rsp)
movsd 0xaa8(%rip), %xmm0      # 0x2008
movl $0x11, %r13d
movapd %xmm0, 0x20(%rsp)
movapd %xmm0, 0xa0(%rsp)
movq %r12, 0x70(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rbx, %rbx
je 0x161c
leaq (%rbx,%r13), %r14
xorl %r15d, %r15d
movabsq $-0x3b314601e57a13ad, %r12 # imm = 0xC4CEB9FE1A85EC53
leaq (%r15,%r13), %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %rbp, %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
xorq %rcx, %rdx
imulq %r12, %rdx
movq %rdx, %rax
shrq $0x21, %rax
xorq %rdx, %rax
movq %rax, 0x98(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x15f2
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x1602
movq %rsp, %rdi
leaq 0x98(%rsp), %rdx
callq 0x1984
incq %r15
cmpq %r15, %rbx
jne 0x15a6
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
incq %rsi
jmp 0x162e
movl $0x1, %esi
movq %r13, %r14
movabsq $-0x3b314601e57a13ad, %r12 # imm = 0xC4CEB9FE1A85EC53
leaq 0x50(%rsp), %rdi
callq 0x1952
movq %r14, %rax
shrq $0x21, %rax
xorq %r14, %rax
movabsq $-0xae502812aa7333, %rcx # imm = 0xFF51AFD7ED558CCD
imulq %rcx, %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %r12, %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 0x1952
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 0x70(%rsp), %r12
je 0x16fc
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
subq %rbp, %r14
cvtsi2sd %r14, %xmm5
addq 0x88(%rsp), %r13
movapd 0x20(%rsp), %xmm3
movapd %xmm3, %xmm0
movsd 0x8f2(%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 0xa0(%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
movabsq $-0xae502812aa7333, %rbp # imm = 0xFF51AFD7ED558CCD
jne 0x156c
movapd %xmm5, 0x20(%rsp)
movapd %xmm4, 0x70(%rsp)
movq 0x2832(%rip), %rdi      # 0x3fd8
leaq 0x883(%rip), %rsi       # 0x2030
movl $0xf, %edx
callq 0x10d0
movapd 0x20(%rsp), %xmm0
mulsd 0x84b(%rip), %xmm0      # 0x2010
cvttsd2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x83e(%rip), %xmm0      # 0x2018
movq 0x27f7(%rip), %rdi      # 0x3fd8
callq 0x1100
movq %rax, %rbx
leaq 0x850(%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 0x27ad(%rip), %rdi      # 0x3fd8
leaq 0x812(%rip), %rsi       # 0x2044
movl $0x10, %edx
callq 0x10d0
movapd 0x70(%rsp), %xmm0
mulsd 0x7c6(%rip), %xmm0      # 0x2010
cvttsd2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x7b9(%rip), %xmm0      # 0x2018
movq 0x2772(%rip), %rdi      # 0x3fd8
callq 0x1100
movq %rax, %rbx
leaq 0x7cb(%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 0x18c0
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x18d7
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18ed
jmp 0x18ed
movq %rax, %rbx
jmp 0x190d
jmp 0x18f4
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x190d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1924
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x193b
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1120