// File: /workspace/github_cpp_makefile_star2_O2/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 %rdi, %rbx
movq 0xe8(%rbx), %rax
movq (%rsi), %r8
movq 0x8(%rsi), %r15
movq 0x48(%rbx), %r12
movq 0x138(%rbx), %r14
movq 0x1a0(%rbx), %r9
movq 0x150(%rbx), %r10
addq $0x48, %rdi
leaq 0xe8(%rbx), %rdx
leaq 0x150(%rbx), %rcx
xorl %ebp, %ebp
xorl %r13d, %r13d
movq %rax, 0x30(%rsp)
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %r8, (%rsp)
movq %rdi, 0x28(%rsp)
movq %r9, 0x10(%rsp)
movq %r10, 0x8(%rsp)
cmpq %r15, %rbp
jae 0x3700
movq %r13, %rsi
callq 0x277c
leaq 0x1(%rax), %rcx
movq (%rsp), %r8
movl %ecx, %esi
movq %rcx, %rdx
shrq $0x6, %rdx
andl $0x3f, %esi
shrxq %rsi, (%r12,%rdx,8), %rdx
testq %rdx, %rdx
jne 0x362d
movq %rax, %rcx
subq %rsi, %rcx
addq $0x41, %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
addq $0x40, %rcx
movq (%r12,%rdx,8), %rdx
testq %rdx, %rdx
je 0x3615
addq $-0x40, %rcx
tzcntq %rdx, %rsi
movq %rax, %rdx
subq %r13, %rdx
notq %rax
addq %rdx, %rax
addq %rcx, %rax
movb (%r8,%rbp), %cl
addq %rsi, %rax
cmpq %rax, %rdx
jae 0x3738
leaq (%rdx,%rax), %rsi
movq %rsi, %r13
shrq %r13
cmpb (%r14,%r13), %cl
jb 0x366b
jbe 0x3670
incq %r13
movq %r13, %rdx
jmp 0x3648
movq %r13, %rax
jmp 0x3648
movq 0x30(%rsp), %rax
shrq $0x7, %rsi
movq (%rax,%rsi,8), %rax
btq %r13, %rax
jae 0x36f3
movq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x272c
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x277c
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %r9
movq (%rsp), %r8
leaq 0x1(%rbp), %rcx
cmpq %rcx, %r15
cmovaq %r15, %rcx
incq %rax
leaq 0x1(%rbp), %rdx
cmpq %r15, %rdx
jae 0x36e8
movb -0x1(%r9,%rax), %sil
cmpb 0x1(%r8,%rbp), %sil
jne 0x3738
movq %rax, %rsi
shrq $0x6, %rsi
movq %rdx, %rbp
movq (%r10,%rsi,8), %rsi
btq %rax, %rsi
leaq 0x1(%rax), %rax
jae 0x36b9
jmp 0x36eb
movq %rcx, %rdx
movq %rdx, %rbp
cmpq %r15, %rdx
je 0x3738
movq 0x28(%rsp), %rdi
incq %rbp
jmp 0x35db
movq 0x98(%rbx), %rcx
movq %r13, %rax
shrq $0x6, %rax
movq (%rcx,%rax,8), %rax
btq %r13, %rax
jae 0x3738
addq $0x98, %rbx
movq %r13, %rsi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x272c
pushq $-0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq