// File: /workspace/github_cpp_makefile_star2_O3/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 0x2d59(%rip), %rdi      # 0x8a03
callq 0x2180
leaq 0x13f0(%rsp), %rbx
movq %rbx, %rdi
callq 0x68fc
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x6a54
leaq 0x8(%rsp), %r14
xorl %r12d, %r12d
movq %rsp, %r13
leaq 0x245c(%rip), %r15      # 0x8150
leaq 0x2355(%rip), %rbx      # 0x8050
imull $0x78d5, %r12d, %eax    # imm = 0x78D5
rorw $0x2, %ax
movzwl %ax, %eax
cmpl $0x83, %eax
ja 0x5d3a
cvtsi2sd %r12, %xmm0
divsd 0x22fb(%rip), %xmm0     # 0x8018
mulsd 0x22fb(%rip), %xmm0     # 0x8020
leaq 0x2a5b(%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 %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0x6b18
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x259f
movl %eax, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x25db
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x25a4
movl %eax, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2606
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x25a9
movq %r12, 0x18(%rsp)
movl %eax, %edi
movq %r13, %rsi
movq %r14, %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 0x5548
movl %eax, %ebp
movq %r14, %rdi
movq %r12, %rsi
callq 0x25a4
movl %eax, %edi
movl %ebp, %esi
leaq 0x8(%rsp), %rdx
movq %rsp, %rcx
callq 0x280a
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x25a9
movl %eax, %r14d
cmpl %eax, %ebp
jne 0x6098
movq (%rsp), %r13
movq 0x8(%rsp), %rax
movq %rax, %r14
subq %r13, %r14
je 0x5e7c
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 0x5e94
incq %rdx
cmpq %rdx, %r14
jne 0x5e5a
jmp 0x5e7e
xorl %ecx, %ecx
movb (%rcx,%r15), %r12b
xorl %ecx, %ecx
cmpb $0x10, %r12b
sete %cl
cmpl %ecx, %ebp
je 0x5e9d
jmp 0x615f
cmpl $0x1, %ebp
jne 0x6182
cmpq $0x1f, %r14
ja 0x5ed9
cmpq %r13, %rax
je 0x5f5e
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 0x5f56
incq %rcx
cmpq %rcx, %r14
jne 0x5eb0
jmp 0x5faf
movq %r14, %rcx
shrq %rcx
cmpb $-0x41, (%r13,%rcx)
jle 0x5eed
leaq (%rcx,%r13), %rax
jmp 0x5f0a
movq %rcx, %rax
subq $0x1, %rcx
jb 0x5f56
cmpb $-0x41, -0x1(%r13,%rax)
movq %rcx, %rax
jle 0x5ef0
leaq (%rcx,%r13), %rax
testq %rcx, %rcx
je 0x5f62
xorl %edi, %edi
xorl %edx, %edx
xorl %esi, %esi
movzbl (%r13,%rdi), %r8d
movzbl (%r8,%rbx), %r8d
addq %rsi, %r8
movzbl (%r15,%r8), %esi
movl $0x1, %r12d
cmpq $0x10, %rsi
je 0x5fbb
movzbl (%rax,%rdi), %r8d
movzbl (%r8,%rbx), %r8d
movl %edx, %edx
addq %r8, %rdx
movzbl (%r15,%rdx), %edx
cmpl $0x10, %edx
je 0x5fbb
incq %rdi
cmpq %rdi, %rcx
jne 0x5f10
jmp 0x5f68
movl $0x1, %r12d
jmp 0x5fbb
xorl %eax, %eax
jmp 0x5faf
xorl %ecx, %ecx
xorl %esi, %esi
xorl %edx, %edx
movl $0x1, %r12d
cmpb $0x10, (%rsi,%r15)
je 0x5fbb
movq %r14, %rsi
subq %rcx, %rsi
cmpq %rsi, %rcx
jae 0x5fad
movq %r14, %rsi
subq %rcx, %rsi
subq %rcx, %rsi
addq %rcx, %rax
xorl %ecx, %ecx
movzbl (%rax,%rcx), %edi
movzbl (%rdi,%rbx), %edi
movl %edx, %edx
addq %rdi, %rdx
movzbl (%r15,%rdx), %edx
cmpl $0x10, %edx
je 0x5fbb
incq %rcx
cmpq %rcx, %rsi
jne 0x5f8e
movl %edx, %eax
xorl %r12d, %r12d
cmpb $0x10, (%rax,%r15)
sete %r12b
cmpl %ebp, %r12d
jne 0x60d3
movq %r13, %rdi
movq %r14, %rsi
callq 0x644d
cmpl %ebp, %eax
jne 0x60fa
movq %r13, %rdi
movq %r14, %rsi
callq 0x61ef
movl %eax, %r12d
cmpl %ebp, %eax
movq 0x20(%rsp), %rax
jne 0x6124
incq %rax
cmpq $0x2710, %rax           # imm = 0x2710
jne 0x5dc3
testq %r13, %r13
je 0x6016
movq 0x10(%rsp), %rsi
subq %r13, %rsi
movq %r13, %rdi
callq 0x2130
movq 0x18(%rsp), %r12
incq %r12
cmpq $0xc350, %r12           # imm = 0xC350
leaq 0x8(%rsp), %r14
movq %rsp, %r13
jne 0x5cfb
leaq 0x29e3(%rip), %rdi      # 0x8a1d
callq 0x2180
movq 0x13c8(%rsp), %rdi
testq %rdi, %rdi
je 0x605c
movq 0x13d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
movq 0x13b0(%rsp), %rdi
testq %rdi, %rdi
je 0x6079
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 0x27bc(%rip), %rdi      # 0x8866
xorl %eax, %eax
callq 0x2030
testl %r14d, %r14d
leaq 0x2a24(%rip), %rax      # 0x8adf
leaq 0x2a02(%rip), %rdi      # 0x8ac4
cmoveq %rax, %rdi
callq 0x2180
movq %rbx, %rdi
jmp 0x6155
leaq 0x26d6(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
testl %r12d, %r12d
leaq 0x29b9(%rip), %rax      # 0x8aaa
leaq 0x2994(%rip), %rdi      # 0x8a8c
jmp 0x6149
movl %eax, %r12d
leaq 0x26ac(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
testl %r12d, %r12d
leaq 0x2959(%rip), %rax      # 0x8a74
leaq 0x2936(%rip), %rdi      # 0x8a58
jmp 0x6149
leaq 0x2685(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
testl %r12d, %r12d
leaq 0x28fd(%rip), %rax      # 0x8a3f
leaq 0x28d9(%rip), %rdi      # 0x8a22
cmoveq %rax, %rdi
callq 0x2180
movq %rsp, %rdi
callq 0x5c24
callq 0x20b0
leaq 0x264a(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
cmpb $0x10, %r12b
je 0x6196
leaq 0x28f9(%rip), %rdi      # 0x8a79
jmp 0x614d
leaq 0x2627(%rip), %rdi      # 0x87b0
movl %r14d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
leaq 0x28c0(%rip), %rdi      # 0x8a5d
jmp 0x614d
jmp 0x61e7
movq %rax, %rbx
jmp 0x61d2
jmp 0x61af
movq %rax, %rbx
jmp 0x61c8
jmp 0x61af
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x61c8
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
leaq 0x28(%rsp), %rdi
callq 0x6976
leaq 0x13f0(%rsp), %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x6a49