// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %rcx, 0x60(%rsp)
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %rdx, %rsi
callq 0x39c5
movq 0x8(%r12), %rdx
cmpq 0x8(%r13), %rdx
jne 0x2f38
movq 0x20(%rsp), %r13
testq %rdx, %rdx
je 0x2f41
movq (%r12), %rdi
movq %r13, %rsi
callq 0x2200
testl %eax, %eax
sete %bpl
jmp 0x2f44
movq 0x20(%rsp), %r13
xorl %ebp, %ebp
jmp 0x2f44
movb $0x1, %bpl
leaq 0x30(%rsp), %rax
cmpq %rax, %r13
je 0x2f5e
movq 0x30(%rsp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x21f0
movzbl %bpl, %ebp
movq %rsp, %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %ebp, %ecx
callq 0x2dc7
movq (%r14), %r13
movq 0x8(%r14), %rdx
cmpq %r13, %rdx
setne %al
orb %al, %bpl
jne 0x3025
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x39c5
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rsi
movl $0x1, %ecx
callq 0x2dc7
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 0x3000
subq %rdi, %rsi
callq 0x21f0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3000
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x301c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21f0
movq (%rsp), %r13
movq 0x8(%rsp), %rdx
movq %rdx, %r15
subq %r13, %r15
sarq $0x4, %r15
movq 0x60(%rsp), %rax
cmpq %rax, %r15
cmovaeq %rax, %r15
movq %r15, %r14
shlq $0x4, %r14
addq %r13, %r14
leaq -0x2a4(%rip), %rcx      # 0x2da8
movq %rcx, 0x20(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x327d
leaq 0x20(%rsp), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x32f0
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
testq %r15, %r15
je 0x309b
xorl %r14d, %r14d
movq (%rsp), %rax
movq (%rax,%r14), %rsi
movq %rbx, %rdi
callq 0x3114
addq $0x10, %r14
decq %r15
jne 0x3082
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x30b1
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %rbx, %rax
addq $0x68, %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 0x30f6
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x30f6
jmp 0x30e6
movq %rax, %r14
jmp 0x30f6
movq %rax, %r14
movq %rbx, %rdi
callq 0x2bb4
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x310c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %r14, %rdi
callq 0x2330