// File: /workspace/github_cpp_makefile_star2_O1/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, 0x64(%rsp)
movabsq $-0xae502812aa7333, %rbx # imm = 0xFF51AFD7ED558CCD
movabsq $-0x3b314601e57a13ad, %r14 # imm = 0xC4CEB9FE1A85EC53
pxor %xmm0, %xmm0
leaq 0x40(%rsp), %rax
movdqa %xmm0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
leaq 0x20(%rsp), %rax
movq %rcx, 0x10(%rax)
movdqa %xmm0, (%rax)
movl $0x1, %r15d
movq 0x391c(%rip), %r13      # 0x4fd0
xorl %r12d, %r12d
movq %r12, %rax
movabsq $-0x2d77318fc504816f, %rcx # imm = 0xD288CE703AFB7E91
imulq %rcx, %rax
rorq $0x4, %rax
movabsq $0x68db8bac710cb, %rcx  # imm = 0x68DB8BAC710CB
cmpq %rcx, %rax
ja 0x16f7
movl $0x1, %edx
movq %r13, %rdi
leaq 0x1a92(%rip), %rsi      # 0x317c
callq 0x1110
movq %r13, %rdi
callq 0x10a0
movq %r12, 0x70(%rsp)
leaq 0x1(%r15), %rax
movq %r15, %rcx
shrq $0x21, %rcx
xorq %r15, %rcx
imulq %rbx, %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
xorq %rcx, %rdx
imulq %r14, %rdx
movq %rdx, %rcx
shrq $0x21, %rcx
xorq %rdx, %rcx
movq %rcx, 0x80(%rsp)
leaq 0x2(%r15), %rcx
movq %rax, %rdx
shrq $0x21, %rdx
xorq %rax, %rdx
imulq %rbx, %rdx
movq %rdx, %rax
shrq $0x21, %rax
xorq %rdx, %rax
imulq %r14, %rax
movq %rax, %rdx
shrq $0x21, %rdx
xorq %rax, %rdx
movq %rdx, 0x88(%rsp)
leaq 0x3(%r15), %rax
movq %rcx, %rdx
shrq $0x21, %rdx
xorq %rcx, %rdx
imulq %rbx, %rdx
movq %rdx, %rcx
shrq $0x21, %rcx
xorq %rdx, %rcx
imulq %r14, %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
xorq %rcx, %rdx
movq %rdx, 0x90(%rsp)
movq %r15, %xmm0
pshufd $0x44, %xmm0, %xmm2     # xmm2 = xmm0[0,1,0,1]
movdqa %xmm2, %xmm3
paddq 0x1868(%rip), %xmm3     # 0x3010
paddq 0x1870(%rip), %xmm2     # 0x3020
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %rbx, %rcx
movq %rcx, %rax
shrq $0x21, %rax
xorq %rcx, %rax
imulq %r14, %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
movq %rcx, 0x98(%rsp)
leaq 0x8(%r15), %rax
movdqa %xmm2, %xmm1
psrlq $0x21, %xmm1
movdqa %xmm3, %xmm0
psrlq $0x21, %xmm0
pxor %xmm3, %xmm0
pxor %xmm2, %xmm1
movdqa %xmm1, %xmm2
movdqa 0x1828(%rip), %xmm4     # 0x3030
pmuludq %xmm4, %xmm2
movdqa %xmm1, %xmm3
psrlq $0x20, %xmm3
movdqa 0x1823(%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 0x17d2(%rip), %xmm4     # 0x3050
pmuludq %xmm4, %xmm0
movdqa %xmm3, %xmm1
psrlq $0x20, %xmm1
movdqa 0x17cd(%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 %rbx, %rcx
movq %rcx, %rax
shrq $0x21, %rax
xorq %rcx, %rax
imulq %r14, %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 0x20c8
movq %r15, 0x68(%rsp)
leaq 0x9(%r15), %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
imulq %rbx, %rcx
movq %rcx, %rax
shrq $0x21, %rax
xorq %rcx, %rax
imulq %r14, %rax
movq %rax, %rcx
shrq $0x21, %rcx
xorq %rax, %rcx
movl %ecx, %ebp
andl $0x7, %ebp
cmpb $0x0, 0x64(%rsp)
cmoveq %rcx, %rbp
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
incq %rsi
leaq 0x40(%rsp), %rdi
callq 0x210e
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq 0x40(%rsp), %rcx
movq %rbp, %rdi
callq 0x12b3
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
incq %rsi
leaq 0x20(%rsp), %rdi
callq 0x210e
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq 0x20(%rsp), %rcx
movq %rbp, %rdi
callq 0x1324
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rax
movq %rax, %rdx
subq %rdi, %rdx
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rcx
subq %rsi, %rcx
cmpq %rcx, %rdx
jne 0x1a25
cmpq %rdi, %rax
je 0x1bd0
callq 0x1100
testl %eax, %eax
je 0x1bd0
leaq 0x172c(%rip), %rdi      # 0x3158
callq 0x1140
movl $0x8, %edx
movq %r13, %rdi
leaq 0x1630(%rip), %rsi      # 0x3070
callq 0x1110
movq %rsp, %rdi
callq 0x159d
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq %r13, %rdi
movq %rbp, %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 0x15c8(%rip), %rdi      # 0x3079
xorl %eax, %eax
callq 0x1040
leaq 0x40(%rsp), %rdi
callq 0x159d
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
leaq 0x158e(%rip), %rdi      # 0x307f
xorl %eax, %eax
callq 0x1040
leaq 0x20(%rsp), %rdi
callq 0x159d
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movl $0x4, %edx
movq 0x34ba(%rip), %rdi      # 0x4ff0
leaq 0x1548(%rip), %rsi      # 0x3085
callq 0x1110
movq 0x34a7(%rip), %rcx      # 0x4ff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3489(%rip), %rdi      # 0x4ff0
callq 0x1030
movl $0x1, %r12d
movq %rax, %rdi
callq 0x10a0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1b90
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
testl %r12d, %r12d
jne 0x1f83
movq 0x68(%rsp), %r15
addq $0xa, %r15
movq 0x70(%rsp), %r12
incq %r12
cmpq $0x1e8480, %r12         # imm = 0x1E8480
movabsq $-0xae502812aa7333, %rbx # imm = 0xFF51AFD7ED558CCD
movabsq $-0x3b314601e57a13ad, %r14 # imm = 0xC4CEB9FE1A85EC53
jne 0x16b7
jmp 0x1f7d
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
je 0x1cdf
sarq $0x3, %rsi
movl $0x1, %ebx
incq %rsi
leaq 0x20(%rsp), %rdi
callq 0x210e
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rdx
cmpq %rdx, %r15
je 0x1c1d
subq %r15, %rdx
addq $-0x8, %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x1070
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq %rbp, %rdi
movq %r15, %rcx
movq %rbx, %r8
callq 0x139e
cmpq %rbx, %rax
jb 0x1ffc
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
movq %rcx, %rsi
subq %rax, %rsi
xorl %r12d, %r12d
cmpq %rcx, %rsi
setb %r14b
jae 0x1cc1
movq 0x40(%rsp), %rdi
movq (%rdx,%rsi,8), %r8
cmpq (%rdi,%rsi,8), %r8
jne 0x1ca7
negq %rax
leaq (%rdi,%rcx,8), %rsi
addq $0x8, %rsi
leaq (%rdx,%rcx,8), %rdx
addq $0x8, %rdx
cmpq $-0x1, %rax
je 0x1cbb
movq (%rdx,%rax,8), %r8
leaq 0x1(%rax), %rdi
cmpq (%rsi,%rax,8), %r8
movq %rdi, %rax
je 0x1c89
addq %rdi, %rcx
setb %r14b
leaq 0x1453(%rip), %rdi      # 0x3101
callq 0x1140
movl $0x1, %r12d
jmp 0x1cc1
xorl %r14d, %r14d
xorl %r12d, %r12d
testb %r14b, %r14b
jne 0x1ce5
incq %rbx
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x3, %rsi
cmpq %rsi, %rbx
jbe 0x1be8
movl $0x5, %r12d
cmpl $0x5, %r12d
jne 0x1b7a
movq (%rsp), %r15
movq 0x8(%rsp), %r12
subq %r15, %r12
je 0x1f65
sarq $0x3, %r12
movl $0x1, %r14d
movq 0x20(%rsp), %r13
movq 0x28(%rsp), %rdx
cmpq %rdx, %r13
je 0x1d33
subq %r13, %rdx
addq $-0x8, %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x1070
movq %r12, 0x80(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r14, %r8
leaq 0x80(%rsp), %r9
callq 0x14a3
movq %rax, %r15
cmpq %r14, %rax
jb 0x200b
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %r13
subq %rax, %r13
sarq $0x3, %r13
movq %r13, %rcx
subq %r15, %rcx
movl $0xe, %r12d
cmpq %r13, %rcx
setb %bl
movq %r14, 0x78(%rsp)
jae 0x1e2d
movq 0x40(%rsp), %rdx
movq (%rax,%rcx,8), %rsi
cmpq (%rdx,%rcx,8), %rsi
jne 0x1dd3
movq %r15, %rcx
negq %rcx
leaq (%rdx,%r13,8), %rdx
addq $0x8, %rdx
leaq (%rax,%r13,8), %rax
addq $0x8, %rax
cmpq $-0x1, %rcx
je 0x1e2b
movq (%rax,%rcx,8), %rdi
leaq 0x1(%rcx), %rsi
cmpq (%rdx,%rcx,8), %rdi
movq %rsi, %rcx
je 0x1db6
addq %r13, %rsi
setb %bl
leaq 0x12ce(%rip), %rdi      # 0x30a8
xorl %eax, %eax
callq 0x1040
leaq 0x20(%rsp), %rdi
callq 0x159d
movl $0xa, %edi
callq 0x1120
leaq 0x12b3(%rip), %rdi      # 0x30af
xorl %eax, %eax
callq 0x1040
leaq 0x40(%rsp), %rdi
callq 0x159d
movl $0xa, %edi
callq 0x1120
leaq 0x130a(%rip), %rdi      # 0x3128
callq 0x1140
movl $0x1, %r12d
jmp 0x1e2d
xorl %ebx, %ebx
testb %bl, %bl
jne 0x1f38
leaq (,%r13,8), %r14
cmpq %r13, %r15
je 0x1f35
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movq 0x20(%rsp), %rcx
incq %r15
movq %rbp, %rdi
movq %r15, %r8
leaq 0x80(%rsp), %r9
callq 0x14a3
movq %rax, %r15
movq %r13, %rax
subq %r15, %rax
movl $0x13, %r12d
cmpq %r13, %rax
setb %bl
jae 0x1f2b
movq 0x20(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq (%rdx,%rax,8), %rsi
cmpq (%rcx,%rax,8), %rsi
jne 0x1ed1
movq %r15, %rax
negq %rax
addq %r14, %rcx
addq $0x8, %rcx
addq %r14, %rdx
addq $0x8, %rdx
cmpq $-0x1, %rax
je 0x1f29
movq (%rdx,%rax,8), %rdi
leaq 0x1(%rax), %rsi
cmpq (%rcx,%rax,8), %rdi
movq %rsi, %rax
je 0x1eb4
addq %r13, %rsi
setb %bl
leaq 0x11d0(%rip), %rdi      # 0x30a8
xorl %eax, %eax
callq 0x1040
leaq 0x20(%rsp), %rdi
callq 0x159d
movl $0xa, %edi
callq 0x1120
leaq 0x11b5(%rip), %rdi      # 0x30af
xorl %eax, %eax
callq 0x1040
leaq 0x40(%rsp), %rdi
callq 0x159d
movl $0xa, %edi
callq 0x1120
leaq 0x120a(%rip), %rdi      # 0x3126
callq 0x1140
movl $0x1, %r12d
jmp 0x1f2b
xorl %ebx, %ebx
testb %bl, %bl
je 0x1e3d
jmp 0x1f38
xorl %r12d, %r12d
testl %r12d, %r12d
movq 0x308e(%rip), %r13      # 0x4fd0
jne 0x1f6b
movq 0x78(%rsp), %r14
incq %r14
movq (%rsp), %r15
movq 0x8(%rsp), %r12
subq %r15, %r12
sarq $0x3, %r12
cmpq %r12, %r14
jbe 0x1d0b
movl $0xb, %r12d
cmpl $0xb, %r12d
movl $0x0, %eax
cmovel %eax, %r12d
jmp 0x1b7a
movl $0x2, %r12d
cmpl $0x2, %r12d
jne 0x1fb5
movq (%r13), %rax
addq -0x18(%rax), %r13
movq %r13, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x3028(%rip), %rdi      # 0x4fd0
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1fcc
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1fe3
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
cmpl $0x2, %r12d
sete %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1087(%rip), %rdi      # 0x308a
movq %rax, %rsi
movq %rbx, %rdx
jmp 0x2018
leaq 0x1078(%rip), %rdi      # 0x308a
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x1040
leaq 0x112e(%rip), %rdi      # 0x3154
callq 0x1140
callq 0x1080
jmp 0x2034
jmp 0x2034
movq %rax, %rbx
jmp 0x2058
jmp 0x203f
jmp 0x203f
jmp 0x203f
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2058
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x206f
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2086
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq %rbx, %rdi
callq 0x1160