// File: /workspace/github_cpp_makefile_star2_O1/ahupp[P]mural/search.cpp
// Function: find_best_fuzzy_matches(std::vector<TagInfo, std::allocator<TagInfo>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long)
vector<TagInfo> find_best_fuzzy_matches(const vector<TagInfo>& tags,
                                        const string& query,
                                        const size_t max_items) {

  bool ignore_case = query == lowercase(query);

  vector<FuzzyMatch> matches = find_all_fuzzy_matches(tags, query, ignore_case);
  if (matches.size() == 0 && !ignore_case) {
    matches = find_all_fuzzy_matches(tags, lowercase(query), true);
  }
  size_t limit = min(max_items, matches.size());
  partial_sort(matches.begin(), matches.begin()+limit, matches.end(),
               is_better_match);

  vector<TagInfo> result;
  for (size_t i = 0; i < limit; ++i) {
    result.push_back(*(matches[i].first));
  }

  return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %rdx, %rsi
callq 0x39a9
movq 0x8(%r12), %rdx
cmpq 0x8(%r13), %rdx
jne 0x2f1b
testq %rdx, %rdx
je 0x2f1f
movq 0x20(%rsp), %rsi
movq (%r12), %rdi
callq 0x2200
testl %eax, %eax
sete %bpl
jmp 0x2f22
xorl %ebp, %ebp
jmp 0x2f22
movb $0x1, %bpl
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f3d
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21f0
movzbl %bpl, %ebp
movq %rsp, %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %ebp, %ecx
callq 0x2dbf
movq 0x8(%r13), %rax
cmpq (%r13), %rax
setne %al
orb %al, %bpl
jne 0x2ff9
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x39a9
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rsi
movl $0x1, %ecx
callq 0x2dbf
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movaps 0x40(%rsp), %xmm0
movaps %xmm0, (%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testq %rdi, %rdi
je 0x2fc6
subq %rdi, %rsi
callq 0x21f0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2fdd
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2ff9
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21f0
movq (%rsp), %r15
movq 0x8(%rsp), %rdx
movq %rdx, %r12
subq %r15, %r12
sarq $0x4, %r12
cmpq %r14, %r12
cmovaeq %r14, %r12
movq %r12, %r14
shlq $0x4, %r14
addq %r15, %r14
leaq -0x284(%rip), %rcx      # 0x2da0
movq %rcx, 0x20(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3255
leaq 0x20(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x32c8
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
testq %r12, %r12
je 0x3073
xorl %r14d, %r14d
movq (%rsp), %rax
movq (%rax,%r14), %rsi
movq %rbx, %rdi
callq 0x30ec
addq $0x10, %r14
decq %r12
jne 0x305a
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3089
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x30ce
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x30ce
jmp 0x30be
movq %rax, %r14
jmp 0x30ce
movq %rax, %r14
movq %rbx, %rdi
callq 0x2bb4
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x30e4
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %r14, %rdi
callq 0x2330