// File: 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
movq %rsp, %rbp
subq $0x380, %rsp            # imm = 0x380
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2f8(%rbp)
leaq -0x218(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
movl $0x8, %edx
callq 0x56d0
leaq -0x230(%rbp), %rdi
callq 0xe720
leaq -0x240(%rbp), %rdi
callq 0x23590
movq -0x2f0(%rbp), %rdi
callq 0x56c0
movb %al, -0x2e1(%rbp)
jmp 0x30c42
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x30ca0
jmp 0x30c4e
movq 0x2e39b(%rip), %rdi     # 0x5eff0
leaq 0x12c97(%rip), %rsi     # 0x438f3
callq 0x5420
movq %rax, -0x300(%rbp)
jmp 0x30c6a
movq -0x300(%rbp), %rdi
movq 0x2e318(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x30c7f
movl $0x1, %edi
callq 0x54f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x311ca
leaq -0x218(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x52c0
movq %rax, -0x308(%rbp)
jmp 0x30cbc
movq -0x308(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x52c0
jmp 0x30cd1
movq -0x2f8(%rbp), %rdi
movq -0x250(%rbp), %rax
movq %rax, -0x310(%rbp)
callq 0xe6e0
movq %rax, %rcx
movq -0x310(%rbp), %rax
movslq 0x94(%rcx), %rcx
cmpq %rcx, %rax
je 0x30d3c
movq 0x2e2e8(%rip), %rdi     # 0x5eff0
leaq 0x12c0e(%rip), %rsi     # 0x4391d
callq 0x5420
movq %rax, -0x318(%rbp)
jmp 0x30d1d
movq -0x318(%rbp), %rdi
movq 0x2e265(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x30d32
movl $0x1, %edi
callq 0x54f0
leaq -0x278(%rbp), %rdi
leaq -0x248(%rbp), %rsi
leaq -0x250(%rbp), %rdx
callq 0x35640
jmp 0x30d58
leaq -0x240(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x34480
leaq -0x278(%rbp), %rdi
callq 0x23810
movq $0x0, -0x280(%rbp)
movq -0x280(%rbp), %rax
cmpq -0x248(%rbp), %rax
jae 0x30f45
leaq -0x2a0(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x5600
movq -0x320(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x5560
jmp 0x30dbe
movq -0x2f8(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x8570
movl %eax, -0x324(%rbp)
jmp 0x30de5
movl -0x324(%rbp), %eax
cmpl $-0x1, %eax
je 0x30eda
leaq -0x230(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0xe640
jmp 0x30e09
movq -0x2f8(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x81a0
jmp 0x30e2a
movq $0x0, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rax
cmpq -0x250(%rbp), %rax
jae 0x30ed8
leaq -0x240(%rbp), %rdi
callq 0x235f0
movq (%rax), %rax
movq %rax, -0x330(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x122c0
movq %rax, %rcx
movq -0x330(%rbp), %rax
decq %rcx
movq -0x250(%rbp), %rdx
imulq %rdx, %rcx
movq -0x2a8(%rbp), %rdx
addq %rdx, %rcx
leaq (%rax,%rcx,4), %rsi
leaq -0x218(%rbp), %rdi
callq 0x50e0
jmp 0x30e9f
jmp 0x30ea1
movq -0x2a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2a8(%rbp)
jmp 0x30e35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x58d8
jmp 0x311ca
jmp 0x30f22
movq $0x0, -0x2b0(%rbp)
movq -0x2b0(%rbp), %rax
cmpq -0x250(%rbp), %rax
jae 0x30f20
leaq -0x218(%rbp), %rdi
leaq -0x254(%rbp), %rsi
callq 0x50e0
jmp 0x30f0a
jmp 0x30f0c
movq -0x2b0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2b0(%rbp)
jmp 0x30ee5
jmp 0x30f22
leaq -0x2a0(%rbp), %rdi
callq 0x58d8
movq -0x280(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x280(%rbp)
jmp 0x30d82
leaq -0x218(%rbp), %rdi
callq 0x50f0
jmp 0x30f53
movq -0x2f8(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
callq 0x8340
movl %eax, -0x334(%rbp)
jmp 0x30f73
movq -0x2f8(%rbp), %rdi
movl -0x334(%rbp), %eax
movl %eax, -0x2c4(%rbp)
callq 0xe6e0
movq %rax, %rdx
addq $0x94, %rdx
leaq -0x2c0(%rbp), %rdi
leaq -0x2c4(%rbp), %rsi
callq 0x356c0
jmp 0x30faa
movq -0x2f8(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x348(%rbp)
leaq -0x2c0(%rbp), %rsi
movq %rsi, -0x350(%rbp)
callq 0x34480
movq -0x350(%rbp), %rdi
callq 0x23810
movq -0x348(%rbp), %rdi
callq 0x235f0
movq -0x2f8(%rbp), %rdi
movq %rax, -0x340(%rbp)
callq 0xe6e0
movq -0x340(%rbp), %rdi
cvtsi2sdl 0x94(%rax), %xmm1
xorps %xmm0, %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x1e020
jmp 0x3101b
movq $0x0, -0x2d0(%rbp)
movq -0x2d0(%rbp), %rax
movq %rax, -0x358(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x122c0
movq %rax, %rcx
movq -0x358(%rbp), %rax
cmpq %rcx, %rax
jae 0x3119d
movq -0x2f8(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, -0x368(%rbp)
movq -0x2d0(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x35170
movq -0x368(%rbp), %rdi
movq %rax, %rsi
callq 0x8570
movl %eax, -0x35c(%rbp)
jmp 0x31094
movl -0x35c(%rbp), %eax
movl %eax, -0x2d4(%rbp)
cmpl $0x0, -0x2d4(%rbp)
jl 0x310e5
movq -0x2f8(%rbp), %rdi
movl -0x2d4(%rbp), %eax
movl %eax, -0x370(%rbp)
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
callq 0x8340
movl %eax, -0x36c(%rbp)
jmp 0x310d5
movl -0x370(%rbp), %eax
movl -0x36c(%rbp), %ecx
cmpl %ecx, %eax
jl 0x310ea
jmp 0x31186
movq $0x0, -0x2e0(%rbp)
movq -0x2e0(%rbp), %rax
cmpq -0x250(%rbp), %rax
jae 0x31184
leaq -0x240(%rbp), %rdi
callq 0x235f0
movq -0x2f8(%rbp), %rdi
movq (%rax), %rax
movq -0x2d0(%rbp), %rcx
imulq -0x250(%rbp), %rcx
addq -0x2e0(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x374(%rbp)
addq $0x30, %rdi
callq 0x235f0
movss -0x374(%rbp), %xmm0
movq (%rax), %rax
movslq -0x2d4(%rbp), %rcx
imulq -0x250(%rbp), %rcx
addq -0x2e0(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x2e0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2e0(%rbp)
jmp 0x310f5
jmp 0x31186
movq -0x2d0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2d0(%rbp)
jmp 0x31026
leaq -0x240(%rbp), %rdi
callq 0x23810
leaq -0x230(%rbp), %rdi
callq 0xe820
leaq -0x218(%rbp), %rdi
callq 0x5130
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
leaq -0x240(%rbp), %rdi
callq 0x23810
leaq -0x230(%rbp), %rdi
callq 0xe820
leaq -0x218(%rbp), %rdi
callq 0x5130
movq -0x260(%rbp), %rdi
callq 0x57a0
nopw (%rax,%rax)