// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq 0x8(%rsi), %rax
movq %rax, (%rsp)
testq %rax, %rax
setne %bpl
movq %rdi, 0x20(%rsp)
je 0x3c69
leaq 0x48(%rdi), %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rdi), %r13
movq 0xe8(%rdi), %rax
movq %rax, 0x28(%rsp)
movq (%rsi), %rax
movq %rax, 0x8(%rsp)
movq 0x138(%rdi), %r15
leaq 0xe8(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x150(%rdi), %rax
movq %rax, 0x10(%rsp)
movq 0x1a0(%rdi), %rax
movq %rax, 0x40(%rsp)
movq 0x150(%rdi), %rax
movq %rax, 0x38(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x2808
leaq 0x1(%rax), %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movl %ecx, %esi
andl $0x3f, %esi
shrxq %rsi, (%r13,%rdx,8), %rdx
testq %rdx, %rdx
jne 0x3b5f
movq %rax, %rcx
subq %rsi, %rcx
addq $0x41, %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movq (%r13,%rdx,8), %rdx
addq $0x40, %rcx
testq %rdx, %rdx
je 0x3b46
addq $-0x40, %rcx
tzcntq %rdx, %rsi
movq %rax, %rdx
subq %r14, %rdx
notq %rax
addq %rdx, %rax
addq %rcx, %rax
addq %rsi, %rax
cmpq %rax, %rdx
setb %r12b
jae 0x3baf
movq 0x8(%rsp), %rcx
movb (%rcx,%rbx), %cl
leaq (%rdx,%rax), %rdi
movq %rdi, %r14
shrq %r14
movq %r14, %rsi
cmpb (%r15,%r14), %cl
jb 0x3ba3
jbe 0x3bd2
leaq 0x1(%r14), %rdx
movq %rax, %rsi
movq %rsi, %rax
cmpq %rsi, %rdx
setb %r12b
jb 0x3b87
movq (%rsp), %rsi
testb $0x1, %r12b
je 0x3c6c
incq %rbx
cmpq %rsi, %rbx
setb %bpl
jb 0x3b13
jmp 0x3c6c
shrq $0x7, %rdi
movq 0x28(%rsp), %rax
movq (%rax,%rdi,8), %rax
btq %r14, %rax
jae 0x3baf
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x27b8
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x2808
incq %rbx
movq (%rsp), %rsi
cmpq %rbx, %rsi
movq %rbx, %rcx
cmovaq %rsi, %rcx
incq %rax
cmpq %rsi, %rbx
jae 0x3c50
movq 0x40(%rsp), %rdx
movb -0x1(%rdx,%rax), %dl
movq 0x8(%rsp), %rdi
cmpb (%rdi,%rbx), %dl
jne 0x3c61
movq %rax, %rdx
shrq $0x6, %rdx
movq 0x38(%rsp), %rdi
movq (%rdi,%rdx,8), %rdx
incq %rbx
btq %rax, %rdx
leaq 0x1(%rax), %rax
jae 0x3c13
decq %rbx
movq %rbx, %rcx
jmp 0x3c53
movq %rcx, %rbx
cmpq %rsi, %rcx
setne %al
andb %al, %r12b
jmp 0x3bb3
xorl %r12d, %r12d
jmp 0x3bb3
xorl %r14d, %r14d
testb $0x1, %bpl
movq 0x20(%rsp), %rdi
jne 0x3cac
movq %r14, %rax
shrq $0x6, %rax
movq 0x98(%rdi), %rcx
movq (%rcx,%rax,8), %rax
btq %r14, %rax
jae 0x3cac
addq $0x98, %rdi
movq %r14, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27b8
movq $-0x1, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq