// File: /workspace/github_cpp_makefile_star2_O2/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 0x5f8f(%rip), %rdi      # 0x8a03
callq 0x2190
leaq 0x13f0(%rsp), %r14
movq %r14, %rdi
callq 0x6304
leaq 0x28(%rsp), %rdi
pushq $0x1
popq %rbx
movq %r14, %rsi
movl %ebx, %edx
movl %ebx, %ecx
movl %ebx, %r8d
movl %ebx, %r9d
callq 0x64bc
leaq 0x8(%rsp), %r14
xorl %r15d, %r15d
cmpq $0xc350, %r15           # imm = 0xC350
je 0x2cbf
movl %r15d, %eax
xorl %edx, %edx
movw $0x1f4, %cx             # imm = 0x1F4
divw %cx
testw %dx, %dx
jne 0x2af3
cvtsi2sd %r15, %xmm0
divsd 0x56fa(%rip), %xmm0     # 0x81d0
mulsd 0x56fa(%rip), %xmm0     # 0x81d8
leaq 0x5ca2(%rip), %rdi      # 0x8787
movb $0x1, %al
callq 0x2030
xorl %edi, %edi
callq 0x2150
callq 0x2040
cltd
movl $0x100, %ecx            # imm = 0x100
idivl %ecx
movslq %edx, %rdx
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
callq 0x6548
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2311
testl %eax, %eax
jne 0x2e1e
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x231b
testl %eax, %eax
jne 0x2e1e
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2325
testl %eax, %eax
jne 0x2e1e
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %r14
subq %rbp, %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2eac
testl %eax, %eax
jne 0x2e3e
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2ef2
testl %eax, %eax
jne 0x2e59
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2fc8
testl %eax, %eax
jne 0x2e50
movq %r15, 0x20(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x321d
testl %eax, %eax
jne 0x2e47
movl $0x2711, %r13d          # imm = 0x2711
decq %r13
je 0x2ca5
callq 0x2040
andb $0x7, %al
movl %ebx, %ebp
movl %eax, %ecx
shll %cl, %ebp
callq 0x2040
cltq
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rsi
subq %rcx, %rsi
xorl %edx, %edx
divq %rsi
xorb %bpl, (%rcx,%rdx)
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %r12
subq %r15, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x2384
movl %eax, %r14d
movq %r15, %rdi
movq %r12, %rsi
callq 0x231b
movl %eax, %ebp
cmpl %r14d, %eax
jne 0x2d24
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2325
movl %eax, %ebp
cmpl %eax, %r14d
jne 0x2cf7
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %r12
subq %rbp, %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2eac
cmpl %r14d, %eax
jne 0x2dde
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2ef2
cmpl %r14d, %eax
jne 0x2db4
movq %rbp, %rdi
movq %r12, %rsi
callq 0x321d
cmpl %r14d, %eax
jne 0x2d8a
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2fc8
cmpl %r14d, %eax
je 0x2bc2
jmp 0x2d60
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x6490
movq 0x20(%rsp), %r15
incq %r15
jmp 0x2aab
leaq 0x5d57(%rip), %rdi      # 0x8a1d
callq 0x2190
leaq 0x13b0(%rsp), %rdi
callq 0x6446
leaq 0x13f0(%rsp), %rdi
callq 0x635a
addq $0x2778, %rsp           # imm = 0x2778
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rbx
movl 0x8(%rbx), %esi
movq (%rbx), %rdx
subl %edx, %esi
leaq 0x5b5b(%rip), %rdi      # 0x8866
xorl %eax, %eax
callq 0x2030
testl %ebp, %ebp
leaq 0x5dc4(%rip), %rax      # 0x8adf
leaq 0x5da2(%rip), %rdi      # 0x8ac4
jmp 0x2d4f
leaq 0x8(%rsp), %rbx
movl 0x8(%rbx), %esi
movq (%rbx), %rdx
subl %edx, %esi
leaq 0x5b0a(%rip), %rdi      # 0x8842
xorl %eax, %eax
callq 0x2030
testl %ebp, %ebp
leaq 0x5dc9(%rip), %rax      # 0x8b11
leaq 0x5da7(%rip), %rdi      # 0x8af6
cmoveq %rax, %rdi
callq 0x2190
movq %rbx, %rdi
jmp 0x2e14
movl %eax, %r15d
leaq 0x5a46(%rip), %rdi      # 0x87b0
movl %r12d, %esi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2030
testl %r15d, %r15d
leaq 0x5cbe(%rip), %rax      # 0x8a3f
leaq 0x5c9a(%rip), %rdi      # 0x8a22
jmp 0x2e06
movl %eax, %r15d
leaq 0x5a1c(%rip), %rdi      # 0x87b0
movl %r12d, %esi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2030
testl %r15d, %r15d
leaq 0x5cc9(%rip), %rax      # 0x8a74
leaq 0x5ca6(%rip), %rdi      # 0x8a58
jmp 0x2e06
movl %eax, %r15d
leaq 0x59f2(%rip), %rdi      # 0x87b0
movl %r12d, %esi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2030
testl %r15d, %r15d
leaq 0x5cd5(%rip), %rax      # 0x8aaa
leaq 0x5cb0(%rip), %rdi      # 0x8a8c
jmp 0x2e06
movl %eax, %r15d
leaq 0x59c8(%rip), %rdi      # 0x87b0
movl %r12d, %esi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2030
testl %r15d, %r15d
leaq 0x5c7a(%rip), %rax      # 0x8a79
leaq 0x5c57(%rip), %rdi      # 0x8a5d
cmoveq %rax, %rdi
callq 0x2190
leaq 0x8(%rsp), %rdi
callq 0x29f5
callq 0x20c0
leaq 0x8(%rsp), %rbx
movl 0x8(%rbx), %esi
movq (%rbx), %rdx
subl %edx, %esi
leaq 0x5962(%rip), %rdi      # 0x8794
xorl %eax, %eax
callq 0x2030
jmp 0x2d58
leaq 0x596b(%rip), %rdi      # 0x87b0
jmp 0x2e60
leaq 0x59cf(%rip), %rdi      # 0x881d
jmp 0x2e60
leaq 0x59a0(%rip), %rdi      # 0x87f7
jmp 0x2e60
leaq 0x5970(%rip), %rdi      # 0x87d0
movl %r14d, %esi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2030
jmp 0x2e0f
movq %rax, %rbx
jmp 0x2e97
movq %rax, %rbx
jmp 0x2e8a
jmp 0x2e7d
jmp 0x2e7d
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x6490
leaq 0x13b0(%rsp), %rdi
callq 0x6446
leaq 0x13f0(%rsp), %rdi
callq 0x635a
movq %rbx, %rdi
callq 0x21c0