// File: /workspace/github_cpp_makefile_star2_O1/lemire[P]validateutf8-experiments/tests/unit.cpp
// Function: brute_force_tests()
void brute_force_tests() {
  printf("running brute-force tests\n");
  std::random_device rd{};
  RandomUTF8 gen_1_2_3_4(rd, 1, 1, 1, 1);
  size_t total = 50000;
  for(size_t i = 0; i < total; i++) {
    if((i % (total/100)) == 0) {
      printf("\r\r\r\r%2.0f %%", double(i)/double(total)*100.0); fflush(NULL);
    }
    auto UTF8 = gen_1_2_3_4.generate(rand() % 256);
    if(active_fastvalidate::lookup2::validate(UTF8.data(), UTF8.size()) != fastvalidate::error_code::SUCCESS) {
        printf("bug brute_force_tests %.*s\n", (int) UTF8.size(), UTF8.data());
        display(UTF8);
        abort();
    }
    if(active_fastvalidate::lookup3::validate(UTF8.data(), UTF8.size()) != fastvalidate::error_code::SUCCESS) {
        printf("bug brute_force_tests %.*s\n", (int) UTF8.size(), UTF8.data());
        display(UTF8);
        abort();
    }
    if(active_fastvalidate::lookup4::validate(UTF8.data(), UTF8.size()) != fastvalidate::error_code::SUCCESS) {
        printf("bug brute_force_tests %.*s\n", (int) UTF8.size(), UTF8.data());
        display(UTF8);
        abort();
    }
    if(shiftless_validate_dfa_utf8((const signed char *)UTF8.data(), UTF8.size()) != fastvalidate::error_code::SUCCESS) {
        printf("bug brute_force_tests dfa %.*s\n", (int) UTF8.size(), UTF8.data());
        display(UTF8);
        abort();
    }
    if(shiftless_validate_dfa_utf8_double((const signed char *)UTF8.data(), UTF8.size()) != fastvalidate::error_code::SUCCESS) {
        printf("bug brute_force_tests dfa double %.*s\n", (int) UTF8.size(), UTF8.data());
        display(UTF8);
        abort();
    }
    if(shiftless_validate_dfa_utf8_three((const signed char *)UTF8.data(), UTF8.size()) != fastvalidate::error_code::SUCCESS) {
        printf("bug brute_force_tests dfa three %.*s\n", (int) UTF8.size(), UTF8.data());
        display(UTF8);
        abort();
    }
    if(shiftless_validate_dfa_utf8_quad((const signed char *)UTF8.data(), UTF8.size()) != fastvalidate::error_code::SUCCESS) {
        printf("bug brute_force_tests dfa quad %.*s\n", (int) UTF8.size(), UTF8.data());
        display(UTF8);
        abort();
    }
    for(size_t flip = 0; flip  < 10000; ++flip) {
      // we are going to hack the string as long as it is UTF-8
      UTF8[rand()% UTF8.size()] ^= uint8_t(1) << (rand() % 8); // we flip exactly one bit
      auto e = fidl_validate_string(UTF8.data(), UTF8.size());      
      auto e3 = active_fastvalidate::lookup3::validate(UTF8.data(), UTF8.size());
      
      if(e3 != e) {
        printf("bug brute_force_tests lookup3 %.*s\n", (int) UTF8.size(), UTF8.data());
        if(e3 == fastvalidate::error_code::SUCCESS) {
          printf("lookup3 says it is ok!\n");
        } else {
          printf("lookup3 says it is not ok!\n");
        }
        display(UTF8);
        abort();
      }
      auto e4 = active_fastvalidate::lookup4::validate(UTF8.data(), UTF8.size());
      if(e3 != e4) {
        printf("bug brute_force_tests lookup4 %.*s\n", (int) UTF8.size(), UTF8.data());
        if(e4 == fastvalidate::error_code::SUCCESS) {
          printf("lookup4 says it is ok!\n");
        } else {
          printf("lookup4 says it is not ok!\n");
        }
        display(UTF8);
        abort();
      }      
      
      auto es = shiftless_validate_dfa_utf8((const signed char *)UTF8.data(), UTF8.size());
      
      if(es != e) {
        printf("bug brute_force_tests dfa %.*s\n", (int) UTF8.size(), UTF8.data());
        if(es == fastvalidate::error_code::SUCCESS) {
          printf("dfa says it is ok!\n");
        } else {
          printf("dfa says it is not ok!\n");
        }
        display(UTF8);
        abort();
      }
      auto esd = shiftless_validate_dfa_utf8_double((const signed char *)UTF8.data(), UTF8.size());
      
      if(esd != e) {
        printf("bug brute_force_tests dfa %.*s\n", (int) UTF8.size(), UTF8.data());
        if(esd == fastvalidate::error_code::SUCCESS) {
          printf("double dfa says it is ok!\n");
        } else {
          printf("double dfa says it is not ok!\n");
        }
        display(UTF8);
        abort();
      }
      auto esq = shiftless_validate_dfa_utf8_quad((const signed char *)UTF8.data(), UTF8.size());
      
      if(esq != e) {
        printf("bug brute_force_tests dfa %.*s\n", (int) UTF8.size(), UTF8.data());
        if(esq == fastvalidate::error_code::SUCCESS) {
          printf("quad dfa says it is ok!\n");
        } else {
          printf("quad dfa says it is not ok!\n");
        }
        display(UTF8);
        abort();
      }

      auto est = shiftless_validate_dfa_utf8_three((const signed char *)UTF8.data(), UTF8.size());
      
      if(est != e) {
        printf("bug brute_force_tests dfa %.*s\n", (int) UTF8.size(), UTF8.data());
        if(est == fastvalidate::error_code::SUCCESS) {
          printf("three dfa says it is ok!\n");
        } else {
          printf("three dfa says it is not ok!\n");
        }
        display(UTF8);
        abort();
      }

    }
  }
  printf("\r\r\r\r\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2778, %rsp           # imm = 0x2778
leaq 0x2c33(%rip), %rdi      # 0x8a03
callq 0x2180
leaq 0x13f0(%rsp), %rbx
movq %rbx, %rdi
callq 0x69e4
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x6b38
leaq 0x8(%rsp), %r13
xorl %r14d, %r14d
movq %rsp, %r12
leaq 0x2336(%rip), %r15      # 0x8150
leaq 0x222f(%rip), %rbx      # 0x8050
movq %r14, %rax
movabsq $0x1cac083126e978d5, %rcx # imm = 0x1CAC083126E978D5
imulq %rcx, %rax
rorq $0x2, %rax
movabsq $0x83126e978d4fdf, %rcx # imm = 0x83126E978D4FDF
cmpq %rcx, %rax
ja 0x5e6f
cvtsi2sd %r14, %xmm0
divsd 0x21c6(%rip), %xmm0     # 0x8018
mulsd 0x21c6(%rip), %xmm0     # 0x8020
leaq 0x2926(%rip), %rdi      # 0x8787
movb $0x1, %al
callq 0x2030
xorl %edi, %edi
callq 0x2140
callq 0x2040
leal 0xff(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
subl %ecx, %eax
movslq %eax, %rdx
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0x6bfc
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x259f
movl %eax, %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x25db
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x25a4
movl %eax, %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2606
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x25a9
movq %r14, 0x18(%rsp)
movl %eax, %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2631
xorl %eax, %eax
movq %rax, 0x20(%rsp)
callq 0x2040
andb $0x7, %al
movl $0x1, %ebp
movl %eax, %ecx
shll %cl, %ebp
callq 0x2040
cltq
movq (%rsp), %rcx
movq 0x8(%rsp), %rsi
subq %rcx, %rsi
xorl %edx, %edx
divq %rsi
xorb %bpl, (%rcx,%rdx)
movq (%rsp), %r14
movq 0x8(%rsp), %r12
subq %r14, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x5628
movl %eax, %ebp
movq %r14, %rdi
movq %r12, %rsi
callq 0x25a4
movl %eax, %r14d
movl %eax, %edi
movl %ebp, %esi
movq %r13, %rdx
movq %rsp, %rcx
callq 0x2820
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x25a9
movl %eax, %r13d
cmpl %eax, %r14d
jne 0x61ba
movq (%rsp), %r13
movq 0x8(%rsp), %rax
movq %rax, %r14
subq %r13, %r14
je 0x5fb3
xorl %edx, %edx
xorl %ecx, %ecx
movzbl (%r13,%rdx), %esi
movzbl (%rsi,%rbx), %esi
addq %rcx, %rsi
movzbl (%r15,%rsi), %ecx
cmpq $0x10, %rcx
je 0x5fc3
incq %rdx
cmpq %rdx, %r14
jne 0x5f91
jmp 0x5fb5
xorl %ecx, %ecx
xorl %r12d, %r12d
cmpb $0x10, (%rcx,%r15)
sete %r12b
jmp 0x5fc9
movl $0x1, %r12d
cmpl %ebp, %r12d
jne 0x61f5
cmpq $0x1f, %r14
ja 0x600e
cmpq %r13, %rax
je 0x608d
xorl %ecx, %ecx
xorl %eax, %eax
movzbl (%r13,%rcx), %edx
movzbl (%rdx,%rbx), %edx
addq %rax, %rdx
movzbl (%r15,%rdx), %eax
cmpq $0x10, %rax
je 0x6088
incq %rcx
cmpq %rcx, %r14
jne 0x5fe5
jmp 0x60d0
movq %r14, %rax
shrq %rax
cmpb $-0x41, (%r13,%rax)
jg 0x6030
movq %rax, %rcx
subq $0x1, %rcx
jb 0x6088
cmpb $-0x41, -0x1(%r13,%rax)
movq %rcx, %rax
jle 0x601c
testq %rax, %rax
je 0x6091
leaq (%rax,%r13), %rsi
movq %rax, %rdi
negq %rdi
xorl %r8d, %r8d
xorl %ecx, %ecx
xorl %edx, %edx
movzbl (%r13,%r8), %r9d
movzbl (%r9,%rbx), %r9d
addq %rdx, %r9
movzbl (%r15,%r9), %edx
movb $0x1, %r12b
cmpq $0x10, %rdx
je 0x60d9
movzbl (%rsi,%r8), %r9d
movzbl (%r9,%rbx), %r9d
movl %ecx, %ecx
addq %r9, %rcx
movzbl (%r15,%rcx), %ecx
cmpl $0x10, %ecx
je 0x60d9
incq %r8
movq %rdi, %r9
addq %r8, %r9
jne 0x6046
jmp 0x6095
movb $0x1, %r12b
jmp 0x60d9
xorl %eax, %eax
jmp 0x60d0
xorl %edx, %edx
xorl %ecx, %ecx
movb $0x1, %r12b
cmpb $0x10, (%rdx,%r15)
je 0x60d9
movq %r14, %rdx
subq %rax, %rdx
cmpq %rdx, %rax
jae 0x60ce
addq %rax, %rax
movzbl (%r13,%rax), %edx
movzbl (%rdx,%rbx), %edx
movl %ecx, %ecx
addq %rdx, %rcx
movzbl (%r15,%rcx), %ecx
cmpl $0x10, %ecx
je 0x60d9
incq %rax
cmpq %rax, %r14
jne 0x60ad
movl %ecx, %eax
cmpb $0x10, (%rax,%r15)
sete %r12b
movzbl %r12b, %eax
cmpl %eax, %ebp
jne 0x621c
movq %r13, %rdi
movq %r14, %rsi
callq 0x655a
cmpl %ebp, %eax
jne 0x6247
movq %r13, %rdi
movq %r14, %rsi
callq 0x62fc
movl %eax, %r12d
cmpl %ebp, %eax
movq 0x20(%rsp), %rax
jne 0x6271
incq %rax
cmpq $0x2710, %rax           # imm = 0x2710
leaq 0x8(%rsp), %r13
jne 0x5ef8
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x613d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
movq 0x18(%rsp), %r14
incq %r14
cmpq $0xc350, %r14           # imm = 0xC350
movq %rsp, %r12
jne 0x5e21
leaq 0x28c1(%rip), %rdi      # 0x8a1d
callq 0x2180
movq 0x13c8(%rsp), %rdi
testq %rdi, %rdi
je 0x617e
movq 0x13d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
movq 0x13b0(%rsp), %rdi
testq %rdi, %rdi
je 0x619b
movq 0x13c0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
leaq 0x13f0(%rsp), %rdi
callq 0x2110
addq $0x2778, %rsp           # imm = 0x2778
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rbx
movl 0x8(%rbx), %esi
movq (%rbx), %rdx
subl %edx, %esi
leaq 0x269a(%rip), %rdi      # 0x8866
xorl %eax, %eax
callq 0x2030
testl %r13d, %r13d
leaq 0x2902(%rip), %rax      # 0x8adf
leaq 0x28e0(%rip), %rdi      # 0x8ac4
cmoveq %rax, %rdi
callq 0x2180
movq %rbx, %rdi
jmp 0x62a2
leaq 0x25b4(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
testl %r12d, %r12d
leaq 0x2866(%rip), %rax      # 0x8a79
leaq 0x2843(%rip), %rdi      # 0x8a5d
jmp 0x6296
leaq 0x258d(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
leaq 0x2855(%rip), %rax      # 0x8a8c
leaq 0x286c(%rip), %rdi      # 0x8aaa
testb %r12b, %r12b
cmovneq %rax, %rdi
jmp 0x629a
movl %eax, %r12d
leaq 0x255f(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
testl %r12d, %r12d
leaq 0x280c(%rip), %rax      # 0x8a74
leaq 0x27e9(%rip), %rdi      # 0x8a58
jmp 0x6296
leaq 0x2538(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
testl %r12d, %r12d
leaq 0x27b0(%rip), %rax      # 0x8a3f
leaq 0x278c(%rip), %rdi      # 0x8a22
cmoveq %rax, %rdi
callq 0x2180
movq %rsp, %rdi
callq 0x5d4d
callq 0x20b0
jmp 0x62f4
movq %rax, %rbx
jmp 0x62df
jmp 0x62bc
movq %rax, %rbx
jmp 0x62d5
jmp 0x62bc
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x62d5
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
leaq 0x28(%rsp), %rdi
callq 0x6a5e
leaq 0x13f0(%rsp), %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x6b2c