// File: epfml[P]Bi-Sent2Vec/src/fasttext.cc
// Function: fasttext::FastText::nnSent(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void FastText::nnSent(int32_t k, std::string filename) {
  std::string sentence;
  std::ifstream in1(filename);
  int64_t n = 0;

  Vector buffer(args_->dim), query(args_->dim);
  std::vector<std::string> sentences;

  std::vector<int32_t> line, labels;
  std::ifstream in2(filename);

  while (in2.peek() != EOF) {
    std::getline(in2, sentence);
    sentences.push_back(sentence);
    n++;
  }
  std::cout << "Number of sentences in the corpus file is " << n << "." << std::endl ;
  Matrix sentenceVectors(n+1, args_->dim);

  precomputeSentenceVectors(sentenceVectors, in1);
  std::set<std::string> banSet;

  std::cerr << "Query sentence? " << std::endl;
  while (std::cin.peek() != EOF) {
    query.zero();
    dict_->getLine(std::cin, line, labels, model_->rng);
    dict_->addNgrams(line, args_->wordNgrams);
    buffer.zero();
    for (auto it = line.cbegin(); it != line.cend(); ++it) {
      buffer.addRow(*input_, *it);
    }
    if (!line.empty()) {
      buffer.mul(1.0 / line.size());
    }
    query.addVector(buffer, 1.0);

    findNNSent(sentenceVectors, query, k, banSet, n, sentences);
    std::cout << std::endl;
    std::cerr << "Query sentence? " << std::endl;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x590, %rsp            # imm = 0x590
movq %rdx, -0x528(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x530(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5600
movq -0x528(%rbp), %rsi
leaq -0x240(%rbp), %rdi
movl $0x8, %edx
callq 0x56d0
jmp 0x2ef1b
movq -0x530(%rbp), %rdi
movq $0x0, -0x258(%rbp)
callq 0xe6e0
movslq 0x94(%rax), %rsi
leaq -0x268(%rbp), %rdi
callq 0x20c00
jmp 0x2ef47
movq -0x530(%rbp), %rdi
callq 0xe6e0
movslq 0x94(%rax), %rsi
leaq -0x278(%rbp), %rdi
callq 0x20c00
jmp 0x2ef68
leaq -0x290(%rbp), %rdi
callq 0xe720
leaq -0x2a8(%rbp), %rdi
callq 0xe440
leaq -0x2c0(%rbp), %rdi
callq 0xe440
movq -0x528(%rbp), %rsi
leaq -0x4c8(%rbp), %rdi
movl $0x8, %edx
callq 0x56d0
jmp 0x2efa6
jmp 0x2efa8
leaq -0x4c8(%rbp), %rdi
callq 0x5190
movl %eax, -0x534(%rbp)
jmp 0x2efbc
movl -0x534(%rbp), %eax
cmpl $-0x1, %eax
je 0x2f076
leaq -0x4c8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x50d0
jmp 0x2efdd
leaq -0x290(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xe640
jmp 0x2efef
movq -0x258(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x258(%rbp)
jmp 0x2efa8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x2f4ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x2f4e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x2f4d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x2f4a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x2f49a
movq 0x2ff3b(%rip), %rdi     # 0x5efb8
leaq 0x147ee(%rip), %rsi     # 0x43872
callq 0x5420
movq %rax, -0x540(%rbp)
jmp 0x2f092
movq -0x540(%rbp), %rdi
movq -0x258(%rbp), %rsi
callq 0x5810
movq %rax, -0x548(%rbp)
jmp 0x2f0ae
movq -0x548(%rbp), %rdi
leaq 0x14762(%rip), %rsi     # 0x4381e
callq 0x5420
movq %rax, -0x550(%rbp)
jmp 0x2f0ca
movq -0x550(%rbp), %rdi
movq 0x2feb8(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x2f0df
movq -0x530(%rbp), %rdi
movq -0x258(%rbp), %rax
incq %rax
movq %rax, -0x558(%rbp)
callq 0xe6e0
movq -0x558(%rbp), %rsi
movslq 0x94(%rax), %rdx
leaq -0x4e0(%rbp), %rdi
callq 0x1de00
jmp 0x2f118
movq -0x530(%rbp), %rdi
leaq -0x4e0(%rbp), %rsi
leaq -0x240(%rbp), %rdx
callq 0x2de30
jmp 0x2f134
leaq -0x510(%rbp), %rdi
callq 0x35550
movq 0x2fea9(%rip), %rdi     # 0x5eff0
leaq 0x1474f(%rip), %rsi     # 0x4389d
callq 0x5420
movq %rax, -0x560(%rbp)
jmp 0x2f15c
movq -0x560(%rbp), %rdi
movq 0x2fe26(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x2f171
jmp 0x2f173
movq 0x2fe5e(%rip), %rdi     # 0x5efd8
callq 0x5190
movl %eax, -0x564(%rbp)
jmp 0x2f187
movl -0x564(%rbp), %eax
cmpl $-0x1, %eax
je 0x2f410
leaq -0x278(%rbp), %rdi
callq 0x20cb0
jmp 0x2f1a4
movq -0x530(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq -0x530(%rbp), %rdi
movq %rax, -0x570(%rbp)
addq $0x60, %rdi
callq 0x34630
movq -0x570(%rbp), %rdi
movq %rax, %r8
addq $0x110, %r8             # imm = 0x110
movq 0x2fdf5(%rip), %rsi     # 0x5efd8
leaq -0x2a8(%rbp), %rdx
leaq -0x2c0(%rbp), %rcx
callq 0xac80
jmp 0x2f1f8
movq -0x530(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq -0x530(%rbp), %rdi
movq %rax, -0x578(%rbp)
callq 0xe6e0
movq -0x578(%rbp), %rdi
movl 0xb4(%rax), %edx
leaq -0x2a8(%rbp), %rsi
callq 0xa820
jmp 0x2f236
leaq -0x268(%rbp), %rdi
callq 0x20cb0
jmp 0x2f244
leaq -0x2a8(%rbp), %rdi
callq 0xf370
movq %rax, -0x518(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0xf3e0
movq %rax, -0x520(%rbp)
leaq -0x518(%rbp), %rdi
leaq -0x520(%rbp), %rsi
callq 0xf3a0
testb $0x1, %al
jne 0x2f286
jmp 0x2f30b
movq -0x530(%rbp), %rdi
addq $0x20, %rdi
callq 0x23880
movq %rax, -0x580(%rbp)
leaq -0x518(%rbp), %rdi
callq 0xf410
movq -0x580(%rbp), %rsi
movslq (%rax), %rdx
leaq -0x268(%rbp), %rdi
callq 0x20f30
jmp 0x2f2c1
jmp 0x2f2c3
leaq -0x518(%rbp), %rdi
callq 0xf430
jmp 0x2f257
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x2f48e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
leaq -0x510(%rbp), %rdi
callq 0x355e0
jmp 0x2f48e
leaq -0x2a8(%rbp), %rdi
callq 0x34ec0
testb $0x1, %al
jne 0x2f36e
leaq -0x2a8(%rbp), %rdi
callq 0xed50
movq %rax, %xmm1
movaps 0x135bd(%rip), %xmm0    # 0x428f0
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x135c1(%rip), %xmm0    # 0x42900
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x13562(%rip), %xmm0    # 0x428b8
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
leaq -0x268(%rbp), %rdi
callq 0x20d80
jmp 0x2f36c
jmp 0x2f36e
leaq -0x278(%rbp), %rdi
leaq -0x268(%rbp), %rsi
movss 0x13544(%rip), %xmm0    # 0x428c8
callq 0x20e80
jmp 0x2f38b
movq -0x530(%rbp), %rdi
movl -0xc(%rbp), %ecx
movq -0x258(%rbp), %r9
movq %rsp, %rax
leaq -0x290(%rbp), %rdx
movq %rdx, (%rax)
leaq -0x4e0(%rbp), %rsi
leaq -0x278(%rbp), %rdx
leaq -0x510(%rbp), %r8
callq 0x2e4d0
jmp 0x2f3c5
movq 0x2fbec(%rip), %rdi     # 0x5efb8
movq 0x2fbbd(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x2f3da
movq 0x2fc0f(%rip), %rdi     # 0x5eff0
leaq 0x144b5(%rip), %rsi     # 0x4389d
callq 0x5420
movq %rax, -0x588(%rbp)
jmp 0x2f3f6
movq -0x588(%rbp), %rdi
movq 0x2fb8c(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x2f40b
jmp 0x2f173
leaq -0x510(%rbp), %rdi
callq 0x355e0
leaq -0x4e0(%rbp), %rdi
callq 0x1df90
leaq -0x4c8(%rbp), %rdi
callq 0x5130
leaq -0x2c0(%rbp), %rdi
callq 0xe530
leaq -0x2a8(%rbp), %rdi
callq 0xe530
leaq -0x290(%rbp), %rdi
callq 0xe820
leaq -0x278(%rbp), %rdi
callq 0x20c60
leaq -0x268(%rbp), %rdi
callq 0x20c60
leaq -0x240(%rbp), %rdi
callq 0x5130
leaq -0x38(%rbp), %rdi
callq 0x58d8
addq $0x590, %rsp            # imm = 0x590
popq %rbp
retq
leaq -0x4e0(%rbp), %rdi
callq 0x1df90
leaq -0x4c8(%rbp), %rdi
callq 0x5130
leaq -0x2c0(%rbp), %rdi
callq 0xe530
leaq -0x2a8(%rbp), %rdi
callq 0xe530
leaq -0x290(%rbp), %rdi
callq 0xe820
leaq -0x278(%rbp), %rdi
callq 0x20c60
leaq -0x268(%rbp), %rdi
callq 0x20c60
leaq -0x240(%rbp), %rdi
callq 0x5130
leaq -0x38(%rbp), %rdi
callq 0x58d8
movq -0x248(%rbp), %rdi
callq 0x57a0
nopw %cs:(%rax,%rax)