// File: epfml[P]Bi-Sent2Vec/src/fasttext.cc
// Function: fasttext::FastText::loadVectors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void FastText::loadVectors(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();

  input_ = std::make_shared<Matrix>(dict_->nwords()+args_->bucket, args_->dim);
  input_->uniform(1.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++) {
      input_->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 0x30602
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x30660
jmp 0x3060e
movq 0x2e9db(%rip), %rdi     # 0x5eff0
leaq 0x132d7(%rip), %rsi     # 0x438f3
callq 0x5420
movq %rax, -0x300(%rbp)
jmp 0x3062a
movq -0x300(%rbp), %rdi
movq 0x2e958(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x3063f
movl $0x1, %edi
callq 0x54f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x30ba6
leaq -0x218(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x52c0
movq %rax, -0x308(%rbp)
jmp 0x3067c
movq -0x308(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x52c0
jmp 0x30691
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 0x306fc
movq 0x2e928(%rip), %rdi     # 0x5eff0
leaq 0x1324e(%rip), %rsi     # 0x4391d
callq 0x5420
movq %rax, -0x318(%rbp)
jmp 0x306dd
movq -0x318(%rbp), %rdi
movq 0x2e8a5(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x306f2
movl $0x1, %edi
callq 0x54f0
leaq -0x278(%rbp), %rdi
leaq -0x248(%rbp), %rsi
leaq -0x250(%rbp), %rdx
callq 0x35640
jmp 0x30718
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 0x30905
leaq -0x2a0(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x5600
movq -0x320(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x5560
jmp 0x3077e
movq -0x2f8(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x8570
movl %eax, -0x324(%rbp)
jmp 0x307a5
movl -0x324(%rbp), %eax
cmpl $-0x1, %eax
je 0x3089a
leaq -0x230(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0xe640
jmp 0x307c9
movq -0x2f8(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x81a0
jmp 0x307ea
movq $0x0, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rax
cmpq -0x250(%rbp), %rax
jae 0x30898
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 0x3085f
jmp 0x30861
movq -0x2a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2a8(%rbp)
jmp 0x307f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x58d8
jmp 0x30ba6
jmp 0x308e2
movq $0x0, -0x2b0(%rbp)
movq -0x2b0(%rbp), %rax
cmpq -0x250(%rbp), %rax
jae 0x308e0
leaq -0x218(%rbp), %rdi
leaq -0x254(%rbp), %rsi
callq 0x50e0
jmp 0x308ca
jmp 0x308cc
movq -0x2b0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2b0(%rbp)
jmp 0x308a5
jmp 0x308e2
leaq -0x2a0(%rbp), %rdi
callq 0x58d8
movq -0x280(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x280(%rbp)
jmp 0x30742
leaq -0x218(%rbp), %rdi
callq 0x50f0
jmp 0x30913
movq -0x2f8(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
callq 0x8340
movl %eax, -0x334(%rbp)
jmp 0x30933
movq -0x2f8(%rbp), %rdi
callq 0xe6e0
movq -0x2f8(%rbp), %rdi
movq %rax, %rcx
movl -0x334(%rbp), %eax
movl 0xc4(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x2c4(%rbp)
callq 0xe6e0
movq %rax, %rdx
addq $0x94, %rdx
leaq -0x2c0(%rbp), %rdi
leaq -0x2c4(%rbp), %rsi
callq 0x356c0
jmp 0x30981
movq -0x2f8(%rbp), %rdi
addq $0x20, %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
movsd 0x11ed0(%rip), %xmm0    # 0x428b8
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x1e020
jmp 0x309f7
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 0x30b79
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 0x30a70
movl -0x35c(%rbp), %eax
movl %eax, -0x2d4(%rbp)
cmpl $0x0, -0x2d4(%rbp)
jl 0x30ac1
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 0x30ab1
movl -0x370(%rbp), %eax
movl -0x36c(%rbp), %ecx
cmpl %ecx, %eax
jl 0x30ac6
jmp 0x30b62
movq $0x0, -0x2e0(%rbp)
movq -0x2e0(%rbp), %rax
cmpq -0x250(%rbp), %rax
jae 0x30b60
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 $0x20, %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 0x30ad1
jmp 0x30b62
movq -0x2d0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2d0(%rbp)
jmp 0x30a02
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 %cs:(%rax,%rax)