// File: epfml[P]Bi-Sent2Vec/src/fasttext.cc
// Function: fasttext::FastText::findNNSent(fasttext::Matrix const&, fasttext::Vector const&, int, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, long, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
void FastText::findNNSent(const Matrix& sentenceVectors, const Vector& queryVec,
                          int32_t k, const std::set<std::string>& banSet, int64_t numSent,
                          const std::vector<std::string>& sentences) {
  real queryNorm = queryVec.norm();
  if (std::abs(queryNorm) < 1e-8) {
    queryNorm = 1;
  }
  std::priority_queue<std::pair<real, std::string>> heap;
  Vector vec(args_->dim);

  for (int32_t i = 0; i < numSent; i++) {
    std::string sentence = std::to_string(i) + " " + sentences[i];
    real dp = sentenceVectors.dotRow(queryVec, i);
    heap.push(std::make_pair(dp / queryNorm, sentence));
  }

  int32_t i = 0;
  while (i < k && heap.size() > 0) {
    auto it = banSet.find(heap.top().second);
    if (!std::isnan(heap.top().first)) {
      std::cout << heap.top().first << " "
                                    << heap.top().second << " "
                                    << std::endl;
      i++;
    }
    heap.pop();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20d00
movss %xmm0, -0x34(%rbp)
movss -0x34(%rbp), %xmm0
callq 0x352f0
cvtss2sd %xmm0, %xmm1
movsd 0x1516b(%rip), %xmm0    # 0x43690
ucomisd %xmm1, %xmm0
jbe 0x2e538
movss 0x14395(%rip), %xmm0    # 0x428c8
movss %xmm0, -0x34(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x35310
movq -0x120(%rbp), %rdi
callq 0xe6e0
movslq 0x94(%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0x20c00
jmp 0x2e55f
movl $0x0, -0x78(%rbp)
movslq -0x78(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x2e706
movl -0x78(%rbp), %esi
leaq -0xd8(%rbp), %rdi
callq 0x34190
jmp 0x2e585
leaq 0x145b5(%rip), %rdx     # 0x42b41
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x34070
jmp 0x2e5a1
movq 0x10(%rbp), %rdi
movslq -0x78(%rbp), %rsi
callq 0x35510
movq %rax, %rdx
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xe460
jmp 0x2e5c6
leaq -0xb8(%rbp), %rdi
callq 0x58d8
leaq -0xd8(%rbp), %rdi
callq 0x58d8
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x78(%rbp), %rdx
callq 0x1e0d0
movss %xmm0, -0x124(%rbp)
jmp 0x2e5f9
movss -0x124(%rbp), %xmm0
movss %xmm0, -0xdc(%rbp)
movss -0xdc(%rbp), %xmm0
movss -0x34(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x10c(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x10c(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x35390
jmp 0x2e63e
leaq -0x58(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x35340
jmp 0x2e650
leaq -0x108(%rbp), %rdi
callq 0x34f90
leaq -0x98(%rbp), %rdi
callq 0x58d8
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x2e566
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2e8d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2e8c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2e6be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x58d8
leaq -0xd8(%rbp), %rdi
callq 0x58d8
jmp 0x2e8c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2e6f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x34f90
leaq -0x98(%rbp), %rdi
callq 0x58d8
jmp 0x2e8c8
movl $0x0, -0x110(%rbp)
movl -0x110(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0x125(%rbp)
jge 0x2e749
leaq -0x58(%rbp), %rdi
callq 0x353d0
movq %rax, -0x130(%rbp)
jmp 0x2e735
movq -0x130(%rbp), %rax
cmpq $0x0, %rax
seta %al
movb %al, -0x125(%rbp)
movb -0x125(%rbp), %al
testb $0x1, %al
jne 0x2e758
jmp 0x2e8ad
movq -0x28(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x35420
movq %rax, -0x138(%rbp)
jmp 0x2e775
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rsi
addq $0x8, %rsi
callq 0x353f0
movq %rax, -0x148(%rbp)
jmp 0x2e795
movq -0x148(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x35420
movq %rax, -0x150(%rbp)
jmp 0x2e7b5
movq -0x150(%rbp), %rax
movss (%rax), %xmm0
callq 0x35530
movb %al, -0x151(%rbp)
jmp 0x2e7cd
movb -0x151(%rbp), %al
testb $0x1, %al
jne 0x2e89d
jmp 0x2e7dd
leaq -0x58(%rbp), %rdi
callq 0x35420
movq %rax, -0x160(%rbp)
jmp 0x2e7ef
movq -0x160(%rbp), %rax
movss (%rax), %xmm0
movq 0x307b7(%rip), %rdi     # 0x5efb8
callq 0x5330
movq %rax, -0x168(%rbp)
jmp 0x2e80f
movq -0x168(%rbp), %rdi
leaq 0x14324(%rip), %rsi     # 0x42b41
callq 0x5420
movq %rax, -0x170(%rbp)
jmp 0x2e82b
leaq -0x58(%rbp), %rdi
callq 0x35420
movq %rax, -0x178(%rbp)
jmp 0x2e83d
movq -0x170(%rbp), %rdi
movq -0x178(%rbp), %rsi
addq $0x8, %rsi
callq 0x53e0
movq %rax, -0x180(%rbp)
jmp 0x2e85d
movq -0x180(%rbp), %rdi
leaq 0x142d6(%rip), %rsi     # 0x42b41
callq 0x5420
movq %rax, -0x188(%rbp)
jmp 0x2e879
movq -0x188(%rbp), %rdi
movq 0x30709(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x2e88e
movl -0x110(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x110(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x354a0
jmp 0x2e8a8
jmp 0x2e710
leaq -0x68(%rbp), %rdi
callq 0x20c60
leaq -0x58(%rbp), %rdi
callq 0x354f0
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0x20c60
leaq -0x58(%rbp), %rdi
callq 0x354f0
movq -0x70(%rbp), %rdi
callq 0x57a0
nopw %cs:(%rax,%rax)