// File: /workspace/github_cpp_makefile_star2_O2/lemire[P]validateutf8-experiments/benchmarks/hoehrmann.h
// Function: shiftless_validate_dfa_utf8_quad(signed char const*, unsigned long)
static inline fastvalidate::error_code
shiftless_validate_dfa_utf8_quad(const signed char *c, size_t len) {
  if (len < 32) { // if too small, do not bother
    return shiftless_validate_dfa_utf8(c, len);
  }
  size_t middle_point1 = len / 4;
  // backtrack until we find a leading byte
  while (!is_leading(c[middle_point1])) {
    if (middle_point1 == 0) {
      // we have determined that there is an error
      return fastvalidate::error_code::UTF8_ERROR;
    }
    middle_point1 -= 1;
  }
  size_t middle_point2 = len / 2;
  // backtrack until we find a leading byte
  while (!is_leading(c[middle_point2])) {
    if (middle_point2 == middle_point1) {
      // we have determined that there is an error
      return fastvalidate::error_code::UTF8_ERROR;
    }
    middle_point2 -= 1;
  }
  size_t middle_point3 = len / 2;
  // backtrack until we find a leading byte
  while (!is_leading(c[middle_point3])) {
    if (middle_point3 == middle_point2) {
      // we have determined that there is an error
      return fastvalidate::error_code::UTF8_ERROR;
    }
    middle_point3 -= 1;
  }
  uint32_t state1 = 0;
  uint32_t state2 = 0;
  uint32_t state3 = 0;
  uint32_t state4 = 0;

  const unsigned char *cu1 = (const unsigned char *)c;
  const unsigned char *cu2 = (const unsigned char *)(c + middle_point1);
  const unsigned char *cu3 = (const unsigned char *)(c + middle_point2);
  const unsigned char *cu4 = (const unsigned char *)(c + middle_point3);

  size_t smallest_run = middle_point1;
  if (middle_point2 - middle_point1 < smallest_run) {
    smallest_run = middle_point2 - middle_point1;
  }
  if (middle_point3 - middle_point2 < smallest_run) {
    smallest_run = middle_point3 - middle_point2;
  }
  if (len - middle_point3 < smallest_run) {
    smallest_run = len - middle_point3;
  }
  for (size_t i = 0; i < smallest_run; i++) {
    uint32_t byteval1 = (uint32_t)cu1[i];
    uint32_t byteval2 = (uint32_t)cu2[i];
    uint32_t byteval3 = (uint32_t)cu3[i];
    uint32_t byteval4 = (uint32_t)cu4[i];

    if ((shiftless_updatestate(&state1, byteval1) == SHIFTLESS_UTF8_REJECT) ||
        (shiftless_updatestate(&state2, byteval2) == SHIFTLESS_UTF8_REJECT) ||
        (shiftless_updatestate(&state3, byteval3) == SHIFTLESS_UTF8_REJECT) ||
        (shiftless_updatestate(&state4, byteval4) == SHIFTLESS_UTF8_REJECT)) {
      return fastvalidate::error_code::UTF8_ERROR;
    }
  }
  if (middle_point1 > smallest_run) {
    for (size_t i = smallest_run; i < middle_point1 - smallest_run; i++) {
      uint32_t byteval1 = (uint32_t)cu1[i];
      if (shiftless_updatestate(&state1, byteval1) == SHIFTLESS_UTF8_REJECT) {
        return fastvalidate::error_code::UTF8_ERROR;
      }
    }
  }
  if (shiftless_updatestate(&state1, 0) == SHIFTLESS_UTF8_REJECT) {
    return fastvalidate::error_code::UTF8_ERROR;
  }

  if (middle_point2 - middle_point1 > smallest_run) {
    for (size_t i = smallest_run; i < middle_point2 - middle_point1; i++) {
      uint32_t byteval2 = (uint32_t)cu2[i];
      if (shiftless_updatestate(&state2, byteval2) == SHIFTLESS_UTF8_REJECT) {
        return fastvalidate::error_code::UTF8_ERROR;
      }
    }
  }
  if (shiftless_updatestate(&state2, 0) == SHIFTLESS_UTF8_REJECT) {
    return fastvalidate::error_code::UTF8_ERROR;
  }
  if (middle_point3 - middle_point2 > smallest_run) {
    for (size_t i = smallest_run; i < middle_point3 - middle_point2; i++) {
      uint32_t byteval3 = (uint32_t)cu3[i];
      if (shiftless_updatestate(&state3, byteval3) == SHIFTLESS_UTF8_REJECT) {
        return fastvalidate::error_code::UTF8_ERROR;
      }
    }
  }
  if (shiftless_updatestate(&state3, 0) == SHIFTLESS_UTF8_REJECT) {
    return fastvalidate::error_code::UTF8_ERROR;
  }

  if (len - middle_point3 > smallest_run) {
    for (size_t i = smallest_run; i < len - middle_point3; i++) {
      uint32_t byteval4 = (uint32_t)cu4[i];
      if (shiftless_updatestate(&state4, byteval4) == SHIFTLESS_UTF8_REJECT) {
        return fastvalidate::error_code::UTF8_ERROR;
      }
    }
  }
  if (shiftless_updatestate(&state4, 0) == SHIFTLESS_UTF8_REJECT) {
    return fastvalidate::error_code::UTF8_ERROR;
  }
  return fastvalidate::error_code::SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpq $0x1f, %rsi
ja 0x323c
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2eac
movq %rsi, %rdx
shrq $0x2, %rdx
movq %rsi, %r11
shrq %r11
movq %r11, %rcx
subq %rdx, %rcx
leaq (%rdi,%rdx), %r15
movl $0x1, %eax
cmpb $-0x41, (%rdi,%rdx)
jg 0x3270
subq $0x1, %rdx
jb 0x352d
incq %rcx
decq %r15
jmp 0x3258
leaq (%rdi,%r11), %r10
xorl %r8d, %r8d
movq %r11, %r13
cmpb $-0x40, (%rdi,%r13)
jge 0x3298
cmpq %rdx, %r13
je 0x352d
decq %r13
decq %rcx
incq %r8
decq %r10
jmp 0x327a
movq %rsi, %rbx
subq %r11, %rbx
leaq (%rdi,%r11), %r9
cmpb $-0x41, (%rdi,%r11)
jg 0x32c0
cmpq %r13, %r11
je 0x352d
decq %r11
decq %r8
incq %rbx
decq %r9
jmp 0x32a2
movq %r10, -0x20(%rsp)
movq %r9, -0x38(%rsp)
movq %r13, %r9
subq %rdx, %r9
cmpq %rdx, %r9
movq %rdx, %rax
movq %r9, -0x10(%rsp)
cmovbq %r9, %rax
movq %r11, %r9
subq %r13, %r9
cmpq %rax, %r9
movq %r9, -0x18(%rsp)
cmovbq %r9, %rax
subq %r11, %rsi
cmpq %rax, %rsi
movq %rax, -0x28(%rsp)
movq %rsi, -0x30(%rsp)
cmovbq %rsi, %rax
movq %rax, -0x8(%rsp)
cmpq %rcx, %rdx
movq %rcx, %rbp
cmovbq %rdx, %rbp
cmpq %r8, %rbp
cmovaeq %r8, %rbp
cmpq %rbx, %rbp
movq %rbx, -0x40(%rsp)
cmovaeq %rbx, %rbp
negq %rbp
xorl %r12d, %r12d
leaq 0x4dfc(%rip), %r10      # 0x8130
movq %rdi, %r14
xorl %eax, %eax
movl $0x0, -0x44(%rsp)
xorl %esi, %esi
testq %rbp, %rbp
je 0x33e3
movzbl (%r14), %ebx
leaq 0x4cd9(%rip), %r9       # 0x8030
movzbl (%rbx,%r9), %ebx
movl %r12d, %r12d
addq %rbx, %r12
movzbl (%r10,%r12), %r12d
cmpl $0x10, %r12d
je 0x3528
movzbl (%r14,%rdx), %ebx
movzbl (%rbx,%r9), %ebx
movl %eax, %eax
addq %rbx, %rax
movzbl (%r10,%rax), %eax
cmpl $0x10, %eax
je 0x3528
movzbl (%r14,%r13), %ebx
movzbl (%rbx,%r9), %ebx
movl -0x44(%rsp), %r9d
addq %rbx, %r9
movzbl (%r10,%r9), %r9d
movl %r9d, -0x44(%rsp)
cmpl $0x10, %r9d
je 0x3528
movzbl (%r14,%r11), %r9d
leaq 0x4c70(%rip), %rbx      # 0x8030
movzbl (%r9,%rbx), %r9d
movl %esi, %ebx
addq %r9, %rbx
movzbl (%r10,%rbx), %esi
incq %rbp
incq %r14
cmpl $0x10, %esi
jne 0x3343
jmp 0x3528
movl %esi, -0x48(%rsp)
movq %r10, %rbp
movq %rdx, %rsi
movq -0x8(%rsp), %r13
subq %r13, %rsi
jbe 0x342a
movq %r13, %r14
leaq 0x4c2f(%rip), %r11      # 0x8030
cmpq %rsi, %r14
jae 0x342a
movzbl (%rdi,%r14), %r9d
movzbl (%r9,%r11), %r9d
movl %r12d, %ebx
addq %r9, %rbx
movzbl (%rbp,%rbx), %r12d
incq %r14
cmpl $0x10, %r12d
jne 0x3401
jmp 0x3528
movl %r12d, %esi
cmpb $0x10, (%rsi,%rbp)
je 0x3528
movq -0x10(%rsp), %r12
cmpq %r13, %r12
jbe 0x349d
cmpq %rcx, %rdx
movq %rcx, %rsi
cmovbq %rdx, %rsi
cmpq %r8, %rsi
cmovaeq %r8, %rsi
movq -0x40(%rsp), %rbx
cmpq %rbx, %rsi
cmovaeq %rbx, %rsi
addq %rsi, %r15
movq %r13, %rsi
movq -0x30(%rsp), %r9
movq -0x38(%rsp), %r11
leaq 0x4bbb(%rip), %r14      # 0x8030
cmpq %r12, %rsi
jae 0x34b1
movzbl (%r15), %edi
movzbl (%rdi,%r14), %edi
movl %eax, %eax
addq %rdi, %rax
movzbl (%rbp,%rax), %eax
incq %rsi
incq %r15
cmpl $0x10, %eax
jne 0x3475
jmp 0x3528
movq %rbp, %rsi
movq -0x30(%rsp), %r9
movq -0x38(%rsp), %r11
movq -0x40(%rsp), %rbx
jmp 0x34b4
movq %rbp, %rsi
movl %eax, %eax
cmpb $0x10, (%rax,%rsi)
movq -0x18(%rsp), %r14
movl -0x44(%rsp), %r15d
movq -0x20(%rsp), %r10
je 0x3528
cmpq %r13, %r14
jbe 0x351f
cmpq %rcx, %rdx
movq %rcx, %rax
cmovbq %rdx, %rax
cmpq %r8, %rax
cmovaeq %r8, %rax
cmpq %rbx, %rax
cmovaeq %rbx, %rax
addq %rax, %r10
movq %r13, %rax
cmpq %r14, %rax
jae 0x351f
movzbl (%r10), %esi
leaq 0x4b32(%rip), %rdi      # 0x8030
movzbl (%rsi,%rdi), %esi
movl %r15d, %edi
addq %rsi, %rdi
movq %rbp, %rsi
movzbl (%rbp,%rdi), %r15d
incq %rax
incq %r10
cmpl $0x10, %r15d
jne 0x34ee
jmp 0x3528
movl %r15d, %eax
cmpb $0x10, (%rax,%rsi)
jne 0x3538
movl $0x1, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %r9, -0x28(%rsp)
jae 0x3587
cmpq %rcx, %rdx
cmovbq %rdx, %rcx
cmpq %r8, %rcx
cmovaeq %r8, %rcx
cmpq %rbx, %rcx
cmovaeq %rbx, %rcx
addq %rcx, %r11
cmpq %r9, %r13
jae 0x3587
movzbl (%r11), %eax
leaq 0x4ac9(%rip), %rcx      # 0x8030
movzbl (%rax,%rcx), %eax
movl -0x48(%rsp), %ecx
addq %rax, %rcx
movzbl (%rsi,%rcx), %eax
incq %r13
incq %r11
movl %eax, -0x48(%rsp)
cmpl $0x10, %eax
jne 0x3557
jmp 0x3528
movl -0x48(%rsp), %eax
cmpb $0x10, (%rax,%rsi)
movl $0x0, %eax
sete %al
jmp 0x352d