// File: /workspace/github_cpp_makefile_star2_O3/s-yata[P]louds-patricia/louds-patricia.cpp
// Function: louds::PatriciaImpl::lookup(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
int64_t lookup(const string &query) const {
    uint64_t node_id = 0;
    for (uint64_t i = 0; i < query.length(); ++i) {
      uint64_t node_pos = louds_.select(node_id) + 1;

      uint64_t end = node_pos;
      uint64_t word = louds_.words[end / 64] >> (end % 64);
      if (word == 0) {
        end += 64 - (end % 64);
        word = louds_.words[end / 64];
        while (word == 0) {
          end += 64;
          word = louds_.words[end / 64];
        }
      }
      end += Ctz(word);
      uint64_t begin = node_pos - node_id - 1;
      end = begin + end - node_pos;

      uint8_t byte = query[i];
      while (begin < end) {
        node_id = (begin + end) / 2;
        if (byte < labels_[node_id]) {
          end = node_id;
        } else if (byte > labels_[node_id]) {
          begin = node_id + 1;
        } else {
          if (links_.get(node_id)) {
            uint64_t tail_pos = tail_bits_.select(links_.rank(node_id));
            for (++i; i < query.length(); ++i) {
              if (tail_bytes_[tail_pos] != (uint8_t)query[i]) {
                return -1;
              }
              ++tail_pos;
              if (tail_bits_.get(tail_pos)) {
                break;
              }
            }
            if (i == query.length()) {
              return -1;
            }
          }
          break;
        }
      }
      if (begin >= end) {
        return -1;
      }
    }
    if (!outs_.get(node_id)) {
      return -1;
    }
    return outs_.rank(node_id);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x8(%rsi), %rax
movq %rdi, %rbx
movq %rax, (%rsp)
testq %rax, %rax
je 0x3c04
movq 0xe8(%rbx), %rax
movq 0x48(%rbx), %r13
movq (%rsi), %r15
movq 0x138(%rbx), %r14
movq 0x100(%rbx), %rcx
movq 0x1a0(%rbx), %r8
movq 0x150(%rbx), %r9
leaq 0x48(%rbx), %rdi
leaq 0x150(%rbx), %rdx
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %rax, 0x30(%rsp)
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdi, 0x28(%rsp)
movq %r8, 0x10(%rsp)
movq %r9, 0x8(%rsp)
movq %rbp, %rsi
callq 0x2802
leaq 0x1(%rax), %rcx
movl %ecx, %esi
movq %rcx, %rdx
shrq $0x6, %rdx
andl $0x3f, %esi
shrxq %rsi, (%r13,%rdx,8), %rdx
testq %rdx, %rdx
jne 0x3b23
movq %rax, %rcx
subq %rsi, %rcx
addq $0x41, %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
addq $0x40, %rcx
movq (%r13,%rdx,8), %rdx
testq %rdx, %rdx
je 0x3b0a
addq $-0x40, %rcx
tzcntq %rdx, %rsi
movq %rax, %rdx
subq %rbp, %rdx
notq %rax
addq %rdx, %rax
addq %rcx, %rax
addq %rsi, %rax
cmpq %rax, %rdx
jae 0x3c3b
movb (%r15,%r12), %cl
leaq (%rdx,%rax), %rsi
movq %rsi, %rbp
shrq %rbp
cmpb (%r14,%rbp), %cl
jae 0x3b5c
movq %rbp, %rax
jmp 0x3b64
jbe 0x3b6e
incq %rbp
movq %rbp, %rdx
cmpq %rax, %rdx
jb 0x3b47
jmp 0x3c3b
movq 0x30(%rsp), %rdi
shrq $0x7, %rsi
movq (%rdi,%rsi,8), %rax
btq %rbp, %rax
jae 0x3bf0
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x27ba
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x2802
movq (%rsp), %rdx
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
leaq 0x1(%r12), %rcx
cmpq %rcx, %rdx
cmovaq %rdx, %rcx
incq %rax
leaq -0x1(%rcx), %rdx
cmpq %r12, %rdx
je 0x3be7
movb -0x1(%r8,%rax), %sil
cmpb 0x1(%r15,%r12), %sil
jne 0x3c3b
movq %rax, %rsi
shrq $0x6, %rsi
incq %r12
movq (%r9,%rsi,8), %rsi
btq %rax, %rsi
leaq 0x1(%rax), %rax
jae 0x3bbc
jmp 0x3bea
movq %rcx, %r12
cmpq (%rsp), %r12
je 0x3c3b
movq 0x28(%rsp), %rdi
incq %r12
cmpq (%rsp), %r12
jb 0x3adc
jmp 0x3c06
xorl %ebp, %ebp
movq 0x98(%rbx), %rdi
movq %rbp, %rax
shrq $0x6, %rax
movq (%rdi,%rax,8), %rax
btq %rbp, %rax
jae 0x3c3b
movq 0xb0(%rbx), %rsi
movq %rbp, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27ba
movq $-0x1, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop