// File: /workspace/github_cpp_makefile_star2_O2/epfml[P]Bi-Sent2Vec/src/fasttext.cc
// Function: fasttext::FastText::loadOutputVectors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void FastText::loadOutputVectors(std::string filename) {
  std::ifstream in(filename);
  std::vector<std::string> words;
  std::shared_ptr<Matrix> mat; // temp. matrix for pretrained vectors
  int64_t n, dim;
  real x;
  if (!in.is_open()) {
    std::cerr << "Pretrained vectors file cannot be opened!" << std::endl;
    exit(EXIT_FAILURE);
  }
  in >> n >> dim;
  if (dim != args_->dim) {
    std::cerr << "Dimension of pretrained vectors does not match -dim option"
              << std::endl;
    exit(EXIT_FAILURE);
  }
  mat = std::make_shared<Matrix>(n, dim);
  for (size_t i = 0; i < n; i++) {
    std::string word;
    in >> word;
    if (dict_->getId(word) != -1){
      words.push_back(word);
      dict_->add(word);

      for (size_t j = 0; j < dim; j++) {
        in >> mat->data_[(words.size() -1) * dim + j];
      }

    }
    else{
      for (size_t j = 0; j < dim; j++) {
        in >> x;
      }
    }
  }
  in.close();

  output_ = std::make_shared<Matrix>(dict_->nwords(), args_->dim);
  output_->uniform(0.0 / args_->dim);

  for (size_t i = 0; i < words.size(); i++) {
    int32_t idx = dict_->getId(words[i]);

    if (idx < 0 || idx >= dict_->nwords()) continue;
    for (size_t j = 0; j < dim; j++) {
      output_->data_[idx * dim + j] = mat->data_[i * dim + j];
    }
  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdi, %rbx
leaq 0x70(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x4520
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x40c0
testb %al, %al
je 0x14c8f
leaq 0x70(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x4360
movq %rsp, %rsi
movq %rax, %rdi
callq 0x4360
movq (%rbx), %rax
movslq 0x94(%rax), %rax
cmpq %rax, (%rsp)
jne 0x14cac
movq %rbx, 0x8(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movq %rsp, %rdx
callq 0x15d7b
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0x1648e
leaq 0x50(%rsp), %rdi
callq 0x8b66
xorl %r13d, %r13d
leaq 0x70(%rsp), %r15
leaq 0x6c(%rsp), %r12
cmpq 0x40(%rsp), %r13
jae 0x14b6e
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
andq $0x0, 0x50(%rsp)
movb $0x0, 0x58(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4400
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movq %r14, %rsi
callq 0x5f5e
cmpl $-0x1, %eax
je 0x14b46
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x87e2
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movq %r14, %rsi
callq 0x5d56
xorl %ebp, %ebp
xorl %ebx, %ebx
movq (%rsp), %rax
cmpq %rax, %rbx
jae 0x14b5e
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rcx
sarq $0x5, %rsi
decq %rsi
imulq %rax, %rsi
shlq $0x2, %rsi
addq (%rcx), %rsi
addq %rbp, %rsi
movq %r15, %rdi
callq 0x46b0
incq %rbx
addq $0x4, %rbp
jmp 0x14b08
xorl %ebx, %ebx
cmpq (%rsp), %rbx
jae 0x14b5e
movq %r15, %rdi
movq %r12, %rsi
callq 0x46b0
incq %rbx
jmp 0x14b48
movq %r14, %rdi
callq 0x46c8
incq %r13
jmp 0x14aa5
leaq 0x70(%rsp), %rdi
callq 0x40a0
movq 0x8(%rsp), %rbx
movq 0x10(%rbx), %rdi
callq 0x5e34
leaq 0x68(%rsp), %rsi
movl %eax, (%rsi)
movl $0x94, %edx
addq (%rbx), %rdx
leaq 0x48(%rsp), %rdi
callq 0x15d9c
leaq 0x30(%rbx), %r14
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x1648e
leaq 0x50(%rsp), %rdi
callq 0x8b66
movq (%rbx), %rax
movq 0x30(%rbx), %rdi
cvtsi2sdl 0x94(%rax), %xmm0
xorpd %xmm1, %xmm1
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
callq 0xbefe
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jae 0x14c5f
movq 0x10(%rbx), %rdi
movq %r12, %rax
shlq $0x5, %rax
addq %rax, %rsi
callq 0x5f5e
movl %eax, %ebp
testl %eax, %eax
js 0x14c56
movq 0x10(%rbx), %rdi
callq 0x5e34
cmpl %eax, %ebp
jge 0x14c56
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%r14), %rdx
movl %ebp, %esi
imulq %rax, %rsi
movq %rax, %rdi
imulq %r15, %rdi
subq $0x1, %rax
jb 0x14c56
movq (%rcx), %r8
movss (%r8,%rdi), %xmm0
movq (%rdx), %r8
movss %xmm0, (%r8,%rsi,4)
incq %rsi
addq $0x4, %rdi
jmp 0x14c35
incq %r12
addq $0x4, %r15
jmp 0x14be0
leaq 0x18(%rsp), %rdi
callq 0x8b66
leaq 0x20(%rsp), %rdi
callq 0x880e
leaq 0x70(%rsp), %rdi
callq 0x40e0
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1335a(%rip), %rdi     # 0x27ff0
leaq 0x6cbe(%rip), %rsi      # 0x1b95b
callq 0x4330
movq %rax, %rdi
callq 0x4190
jmp 0x14cc7
movq 0x1333d(%rip), %rdi     # 0x27ff0
leaq 0x6ccb(%rip), %rsi      # 0x1b985
callq 0x4330
movq %rax, %rdi
callq 0x4190
pushq $0x1
popq %rdi
callq 0x43b0
jmp 0x14cd5
jmp 0x14cd5
jmp 0x14cd5
movq %rax, %rbx
jmp 0x14ceb
jmp 0x14cde
jmp 0x14cde
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x46c8
leaq 0x18(%rsp), %rdi
callq 0x8b66
leaq 0x20(%rsp), %rdi
callq 0x880e
leaq 0x70(%rsp), %rdi
callq 0x40e0
movq %rbx, %rdi
callq 0x45d0
nop