// File: /workspace/github_cpp_makefile_star2_O3/lemire[P]backward_multiplication/unit/basictests.cpp
// Function: unittest(bool)
bool unittest(bool smallmultiplier) {
  uint64_t seed = 1;
  std::vector<uint64_t> out1, out2;
  for (size_t t = 0; t < 2000000; t++) {
    if ((t % 10000) == 0) {
      std::cout << ".";
      std::cout.flush();
    }
    std::vector<uint64_t> v = {rng(seed++), rng(seed++), rng(seed++),
                               rng(seed++), rng(seed++), rng(seed++),
                               rng(seed++), rng(seed++), rng(seed++)};
    uint64_t multiplier = rng(seed++);
    if (smallmultiplier) {
      multiplier &= 7;
    }
    out1.resize(v.size() + 1);
    backwardmultiply::multiplication(multiplier, v.data(), v.size(),
                                     out1.data());
    out2.resize(v.size() + 1);
    backwardmultiply::multiplication_backward(multiplier, v.data(), v.size(),
                                              out2.data());
    if (out1 != out2) {
      printf("out1 and out2 differs\n");
      std::cout << "input : ";
      print(v);
      std::cout << std::endl;
      std::cout << multiplier << std::endl;
      printf("out1:");
      print(out1);
      std::cout << std::endl;
      printf("out2:");
      print(out2);
      std::cout << std::endl;
      std::cerr << "bug\n" << std::endl;
      return false;
    }
    ////////////
    /// multiplication_backward_limit
    //////////////
    for (size_t words = 1; words <= v.size(); words++) {
      out2.resize(v.size() + 1);
      std::fill(out2.begin(), out2.end(), 0); // clearing to be sure
      size_t exactwords = backwardmultiply::multiplication_backward_limit(
          multiplier, v.data(), v.size(), out2.data(), words);
      if (exactwords < words) {
        printf("exactwords = %zu words = %zu\n", exactwords, words);
        printf("bug\n");
        abort();
      }

      size_t n = out2.size();

      // check that we are good...
      for (size_t i = n - exactwords; i < n; i++) {
        if (out2[i] != out1[i]) {
          printf("bug in multiplication_backward_limit\n");
          return false;
        }
      }
    }
    ////////////
    /// multiplication_backward_limit_resume
    //////////////
    for (size_t words = 1; words <= v.size(); words++) {
      std::fill(out2.begin(), out2.end(), 0); // clearing to be sure
      size_t index = v.size();
      size_t exactwords =
          backwardmultiply::multiplication_backward_limit_resume(
              multiplier, v.data(), v.size(), out2.data(), words, index);
      if (exactwords < words) {
        printf("exactwords = %zu words = %zu\n", exactwords, words);
        printf("bug\n");
        abort();
      }

      size_t n = out2.size();
      // check that we are good...
      for (size_t i = n - exactwords; i < n; i++) {
        if (out2[i] != out1[i]) {
          printf("out : ");
          print(out2);
          printf("\n");
          printf("true: ");
          print(out1);
          printf("\n");

          printf("bug in multiplication_backward_limit_resume\n");
          return false;
        }
      }
      while (exactwords != n) {
        exactwords = backwardmultiply::multiplication_backward_limit_resume(
            multiplier, v.data(), v.size(), out2.data(), exactwords + 1, index);

        for (size_t i = n - exactwords; i < n; i++) {
          if (out2[i] != out1[i]) {
            printf("out : ");
            print(out2);
            printf("\n");
            printf("true: ");
            print(out1);
            printf("\n");

            printf("**bug in multiplication_backward_limit_resume\n");
            return false;
          }
        }
      }
    }
  }
  std::cout << std::endl;
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %edi, %r15d
movabsq $-0xae502812aa7333, %rbp # imm = 0xFF51AFD7ED558CCD
movabsq $-0x3b314601e57a13ad, %r13 # imm = 0xC4CEB9FE1A85EC53
pxor %xmm0, %xmm0
leaq 0x50(%rsp), %rcx
movdqa %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x20(%rsp), %rcx
movq %rax, 0x10(%rcx)
movdqa %xmm0, (%rcx)
movl $0x1, %r12d
movq $0x0, 0x78(%rsp)
xorl %ebx, %ebx
movl %edi, 0x4c(%rsp)
imull $0x3afb7e91, %ebx, %eax # imm = 0x3AFB7E91
rorl $0x4, %eax
cmpl $0x68db8, %eax          # imm = 0x68DB8
ja 0x1696
movl $0x1, %edx
movq 0x3952(%rip), %rdi      # 0x4fd0
leaq 0x1af7(%rip), %rsi      # 0x317c
callq 0x1110
movq 0x393f(%rip), %rdi      # 0x4fd0
callq 0x10a0
movq %rbx, 0x40(%rsp)
leaq 0x1(%r12), %rax
movq %r12, %rcx
shrq $0x21, %rcx
xorq %r12, %rcx
imulq %rbp, %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
xorq %rcx, %rdx
imulq %r13, %rdx
movq %rdx, %rcx
shrq $0x21, %rcx
xorq %rdx, %rcx
movq %rcx, 0x80(%rsp)
leaq 0x2(%r12), %rcx
movq %rax, %rdx
shrq $0x21, %rdx
xorq %rax, %rdx
imulq %rbp, %rdx
movq %rdx, %rax
shrq $0x21, %rax
xorq %rdx, %rax
imulq %r13, %rax
movq %rax, %rdx
shrq $0x21, %rdx
xorq %rax, %rdx
movq %rdx, 0x88(%rsp)
leaq 0x3(%r12), %rax
movq %rcx, %rdx
shrq $0x21, %rdx
xorq %rcx, %rdx
imulq %rbp, %rdx
movq %rdx, %rcx
shrq $0x21, %rcx
xorq %rdx, %rcx
imulq %r13, %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
xorq %rcx, %rdx
movq %rdx, 0x90(%rsp)
movq %r12, %xmm0
pshufd $0x44, %xmm0, %xmm2     # xmm2 = xmm0[0,1,0,1]
movdqa %xmm2, %xmm3
paddq 0x18c6(%rip), %xmm3     # 0x3010
paddq 0x18ce(%rip), %xmm2     # 0x3020
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %rbp, %rcx
movq %rcx, %rax
shrq $0x21, %rax
xorq %rcx, %rax
imulq %r13, %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
movq %rcx, 0x98(%rsp)
leaq 0x8(%r12), %rax
movdqa %xmm2, %xmm1
psrlq $0x21, %xmm1
movdqa %xmm3, %xmm0
psrlq $0x21, %xmm0
pxor %xmm3, %xmm0
pxor %xmm2, %xmm1
movdqa %xmm1, %xmm2
movdqa 0x1885(%rip), %xmm4     # 0x3030
pmuludq %xmm4, %xmm2
movdqa %xmm1, %xmm3
psrlq $0x20, %xmm3
movdqa 0x1880(%rip), %xmm5     # 0x3040
pmuludq %xmm5, %xmm3
paddq %xmm2, %xmm3
psllq $0x20, %xmm3
pmuludq %xmm5, %xmm1
paddq %xmm3, %xmm1
movdqa %xmm0, %xmm2
pmuludq %xmm4, %xmm2
movdqa %xmm0, %xmm3
psrlq $0x20, %xmm3
pmuludq %xmm5, %xmm3
paddq %xmm2, %xmm3
psllq $0x20, %xmm3
pmuludq %xmm5, %xmm0
paddq %xmm3, %xmm0
movdqa %xmm0, %xmm3
psrlq $0x21, %xmm3
movdqa %xmm1, %xmm2
psrlq $0x21, %xmm2
pxor %xmm1, %xmm2
pxor %xmm0, %xmm3
movdqa %xmm3, %xmm0
movdqa 0x182f(%rip), %xmm4     # 0x3050
pmuludq %xmm4, %xmm0
movdqa %xmm3, %xmm1
psrlq $0x20, %xmm1
movdqa 0x182a(%rip), %xmm5     # 0x3060
pmuludq %xmm5, %xmm1
paddq %xmm0, %xmm1
psllq $0x20, %xmm1
pmuludq %xmm5, %xmm3
paddq %xmm1, %xmm3
movdqa %xmm2, %xmm0
pmuludq %xmm4, %xmm0
movdqa %xmm2, %xmm1
psrlq $0x20, %xmm1
pmuludq %xmm5, %xmm1
paddq %xmm0, %xmm1
psllq $0x20, %xmm1
pmuludq %xmm5, %xmm2
paddq %xmm1, %xmm2
movdqa %xmm2, %xmm0
psrlq $0x21, %xmm0
movdqa %xmm3, %xmm1
psrlq $0x21, %xmm1
pxor %xmm3, %xmm1
pxor %xmm2, %xmm0
movdqu %xmm0, 0xb0(%rsp)
movdqu %xmm1, 0xa0(%rsp)
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %rbp, %rcx
movq %rcx, %rax
shrq $0x21, %rax
xorq %rcx, %rax
imulq %r13, %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
movq %rcx, 0xc0(%rsp)
movl $0x9, %edx
movq %rsp, %rdi
leaq 0x80(%rsp), %rsi
leaq 0x1f(%rsp), %rcx
callq 0x2008
leaq 0x9(%r12), %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %rbp, %rcx
movq %rcx, %rax
shrq $0x21, %rax
xorq %rcx, %rax
imulq %r13, %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
movl %ecx, %r14d
andl $0x7, %r14d
testb %r15b, %r15b
cmoveq %rcx, %r14
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
incq %rsi
leaq 0x50(%rsp), %rdi
callq 0x204e
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq 0x50(%rsp), %rcx
movq %r14, %rdi
callq 0x12b3
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
incq %rsi
leaq 0x20(%rsp), %rdi
callq 0x204e
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq 0x20(%rsp), %rcx
movq %r14, %rdi
callq 0x1324
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
movq %rax, %rdx
subq %rdi, %rdx
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rcx
subq %rsi, %rcx
cmpq %rcx, %rdx
jne 0x19c4
cmpq %rdi, %rax
je 0x1b3e
callq 0x1100
testl %eax, %eax
je 0x1b3e
leaq 0x178d(%rip), %rdi      # 0x3158
callq 0x1140
movl $0x8, %edx
movq 0x35f4(%rip), %rdi      # 0x4fd0
leaq 0x168d(%rip), %rsi      # 0x3070
callq 0x1110
movq %rsp, %rdi
callq 0x1550
movq 0x35d9(%rip), %rcx      # 0x4fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x35bb(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x35a7(%rip), %rdi      # 0x4fd0
movq %r14, %rsi
callq 0x1090
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
leaq 0x1617(%rip), %rdi      # 0x3079
xorl %eax, %eax
callq 0x1040
leaq 0x50(%rsp), %rdi
callq 0x1550
movq 0x3556(%rip), %rcx      # 0x4fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3538(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
leaq 0x15d3(%rip), %rdi      # 0x307f
xorl %eax, %eax
callq 0x1040
leaq 0x20(%rsp), %rdi
callq 0x1550
movq 0x350c(%rip), %rcx      # 0x4fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x34ee(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movl $0x4, %edx
movq 0x34f5(%rip), %rdi      # 0x4ff0
leaq 0x1583(%rip), %rsi      # 0x3085
callq 0x1110
movq 0x34e2(%rip), %rcx      # 0x4ff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x34c4(%rip), %rdi      # 0x4ff0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
jmp 0x1da2
movq (%rsp), %rbp
movq 0x8(%rsp), %rax
movq %rax, %r13
subq %rbp, %r13
sarq $0x3, %r13
cmpq %rbp, %rax
je 0x1c30
movl $0x1, %ebx
incq %r13
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x204e
movq 0x20(%rsp), %r13
movq 0x28(%rsp), %rdx
cmpq %rdx, %r13
movabsq $-0xae502812aa7333, %rbp # imm = 0xFF51AFD7ED558CCD
je 0x1ba1
subq %r13, %rdx
addq $-0x8, %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x1070
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq %r14, %rdi
movq %r13, %rcx
movq %rbx, %r8
callq 0x139e
cmpq %rbx, %rax
jb 0x1f39
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
movq %rcx, %rsi
subq %rax, %rsi
cmpq %rcx, %rsi
movabsq $-0x3b314601e57a13ad, %r13 # imm = 0xC4CEB9FE1A85EC53
jae 0x1c11
negq %rax
leaq (%rdx,%rcx,8), %rdx
shlq $0x3, %rcx
addq 0x50(%rsp), %rcx
movq (%rdx,%rax,8), %rsi
cmpq (%rcx,%rax,8), %rsi
jne 0x1d96
incq %rax
jne 0x1bfe
incq %rbx
movq (%rsp), %rbp
movq 0x8(%rsp), %rax
movq %rax, %r13
subq %rbp, %r13
sarq $0x3, %r13
cmpq %r13, %rbx
jbe 0x1b5f
movb $0x1, %bl
cmpq %rbp, %rax
je 0x1ea3
movl $0x1, %eax
movq %rax, 0x70(%rsp)
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rdx
cmpq %rdx, %r15
je 0x1c6d
subq %r15, %rdx
addq $-0x8, %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x1070
movq %r13, 0x80(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq 0x70(%rsp), %r15
movq %r15, %r8
leaq 0x80(%rsp), %r9
callq 0x1470
cmpq %r15, %rax
jb 0x1f5e
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r15
subq %rsi, %r15
sarq $0x3, %r15
movq %r15, %rcx
subq %rax, %rcx
cmpq %r15, %rcx
movabsq $-0xae502812aa7333, %rbp # imm = 0xFF51AFD7ED558CCD
movabsq $-0x3b314601e57a13ad, %r13 # imm = 0xC4CEB9FE1A85EC53
jae 0x1cf9
movq %rax, %rcx
negq %rcx
leaq (,%r15,8), %rdx
leaq (%rsi,%r15,8), %rsi
addq 0x50(%rsp), %rdx
movq (%rsi,%rcx,8), %rdi
cmpq (%rdx,%rcx,8), %rdi
jne 0x1e3f
incq %rcx
jne 0x1ce6
cmpq %rax, %r15
jne 0x1d29
movq 0x70(%rsp), %rax
incq %rax
movq (%rsp), %rbp
movq 0x8(%rsp), %r13
subq %rbp, %r13
sarq $0x3, %r13
movq %rax, 0x70(%rsp)
cmpq %r13, %rax
jbe 0x1c45
jmp 0x1e9e
leaq (,%r15,8), %r13
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq 0x20(%rsp), %rcx
incq %rax
movq %r14, %rdi
movq %rax, %r8
leaq 0x80(%rsp), %r9
callq 0x1470
movq %r15, %rcx
subq %rax, %rcx
cmpq %r15, %rcx
jae 0x1d8c
movq %rax, %rcx
negq %rcx
movq 0x20(%rsp), %rdx
addq %r13, %rdx
movq 0x50(%rsp), %rsi
addq %r13, %rsi
movq (%rdx,%rcx,8), %rdi
cmpq (%rsi,%rcx,8), %rdi
jne 0x1df2
incq %rcx
jne 0x1d7d
cmpq %rax, %r15
jne 0x1d31
jmp 0x1cfe
leaq 0x1364(%rip), %rdi      # 0x3101
callq 0x1140
xorl %ebx, %ebx
movq 0x40(%rsp), %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1dbf
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
testb %bl, %bl
je 0x1ef2
addq $0xa, %r12
cmpq $0x1e847f, %r14         # imm = 0x1E847F
leaq 0x1(%r14), %rax
setae %cl
movq %rcx, 0x78(%rsp)
movq %rax, %rbx
cmpq $0x1e8480, %rax         # imm = 0x1E8480
jne 0x1662
jmp 0x1ebc
leaq 0x12af(%rip), %rdi      # 0x30a8
xorl %eax, %eax
callq 0x1040
leaq 0x20(%rsp), %rdi
callq 0x1550
movabsq $-0x3b314601e57a13ad, %r13 # imm = 0xC4CEB9FE1A85EC53
movl $0xa, %edi
callq 0x1120
leaq 0x128a(%rip), %rdi      # 0x30af
xorl %eax, %eax
callq 0x1040
leaq 0x50(%rsp), %rdi
callq 0x1550
leaq 0x12e9(%rip), %rbx      # 0x3126
jmp 0x1e80
leaq 0x1262(%rip), %rdi      # 0x30a8
xorl %eax, %eax
callq 0x1040
leaq 0x20(%rsp), %rdi
callq 0x1550
movl $0xa, %edi
callq 0x1120
leaq 0x1247(%rip), %rdi      # 0x30af
xorl %eax, %eax
callq 0x1040
leaq 0x50(%rsp), %rdi
callq 0x1550
leaq 0x12a8(%rip), %rbx      # 0x3128
movl $0xa, %edi
callq 0x1120
movq %rbx, %rdi
callq 0x1140
xorl %ebx, %ebx
movl 0x4c(%rsp), %r15d
jmp 0x1da4
movl 0x4c(%rsp), %r15d
movabsq $-0xae502812aa7333, %rbp # imm = 0xFF51AFD7ED558CCD
movabsq $-0x3b314601e57a13ad, %r13 # imm = 0xC4CEB9FE1A85EC53
jmp 0x1da4
movq 0x310d(%rip), %rdi      # 0x4fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x30f2(%rip), %rdi      # 0x4fd0
callq 0x1030
movb $0x1, %cl
movq %rcx, 0x78(%rsp)
movq %rax, %rdi
callq 0x10a0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1f09
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x1f20
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq 0x78(%rsp), %rax
andb $0x1, %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x114a(%rip), %rdi      # 0x308a
movq %rax, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1040
leaq 0x1200(%rip), %rdi      # 0x3154
callq 0x1140
callq 0x1080
leaq 0x1125(%rip), %rdi      # 0x308a
movq %rax, %rsi
movq 0x70(%rsp), %rdx
jmp 0x1f46
jmp 0x1f7e
jmp 0x1f79
jmp 0x1f7e
jmp 0x1f7e
jmp 0x1f79
movq %rax, %rbx
jmp 0x1f97
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1f97
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1fae
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x1fc5
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq %rbx, %rdi
callq 0x1160