// File: epfml[P]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;
  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;
    words.push_back(word);
    dict_->add(word);
    for (size_t j = 0; j < dim; j++) {
      in >> mat->data_[i * dim + j];
    }
  }
  in.close();

  dict_->threshold(1, 0);
  input_ = std::make_shared<Matrix>(dict_->nwords()+args_->bucket, args_->dim);
  input_->uniform(1.0 / args_->dim);

  for (size_t i = 0; i < n; 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 $0x350, %rsp            # imm = 0x350
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2e8(%rbp)
leaq -0x218(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
movl $0x8, %edx
callq 0x56d0
leaq -0x230(%rbp), %rdi
callq 0xeab0
leaq -0x240(%rbp), %rdi
callq 0x23930
movq -0x2e0(%rbp), %rdi
callq 0x56c0
movb %al, -0x2d1(%rbp)
jmp 0x30642
movb -0x2d1(%rbp), %al
testb $0x1, %al
jne 0x306a0
jmp 0x3064e
movq 0x2e99b(%rip), %rdi     # 0x5eff0
leaq 0x132f8(%rip), %rsi     # 0x43954
callq 0x5420
movq %rax, -0x2f0(%rbp)
jmp 0x3066a
movq -0x2f0(%rbp), %rdi
movq 0x2e918(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x3067f
movl $0x1, %edi
callq 0x54f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
jmp 0x30b53
leaq -0x218(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x52c0
movq %rax, -0x2f8(%rbp)
jmp 0x306bc
movq -0x2f8(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x52c0
jmp 0x306d1
movq -0x2e8(%rbp), %rdi
movq -0x250(%rbp), %rax
movq %rax, -0x300(%rbp)
callq 0xea70
movq %rax, %rcx
movq -0x300(%rbp), %rax
movslq 0x94(%rcx), %rcx
cmpq %rcx, %rax
je 0x3073c
movq 0x2e8e8(%rip), %rdi     # 0x5eff0
leaq 0x1326f(%rip), %rsi     # 0x4397e
callq 0x5420
movq %rax, -0x308(%rbp)
jmp 0x3071d
movq -0x308(%rbp), %rdi
movq 0x2e865(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x30732
movl $0x1, %edi
callq 0x54f0
leaq -0x270(%rbp), %rdi
leaq -0x248(%rbp), %rsi
leaq -0x250(%rbp), %rdx
callq 0x35220
jmp 0x30758
leaq -0x240(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x33f20
leaq -0x270(%rbp), %rdi
callq 0x23bb0
movq $0x0, -0x278(%rbp)
movq -0x278(%rbp), %rax
cmpq -0x248(%rbp), %rax
jae 0x308a8
leaq -0x298(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x5600
movq -0x310(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x5560
jmp 0x307be
leaq -0x230(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0xe9d0
jmp 0x307d3
movq -0x2e8(%rbp), %rdi
addq $0x10, %rdi
callq 0x33af0
movq %rax, %rdi
leaq -0x298(%rbp), %rsi
callq 0x83a0
jmp 0x307f4
movq $0x0, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
cmpq -0x250(%rbp), %rax
jae 0x30885
leaq -0x240(%rbp), %rdi
callq 0x23990
movq (%rax), %rax
movq -0x278(%rbp), %rcx
movq -0x250(%rbp), %rdx
imulq %rdx, %rcx
movq -0x2a0(%rbp), %rdx
addq %rdx, %rcx
leaq (%rax,%rcx,4), %rsi
leaq -0x218(%rbp), %rdi
callq 0x50e0
jmp 0x3084c
jmp 0x3084e
movq -0x2a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2a0(%rbp)
jmp 0x307ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x58d8
jmp 0x30b53
leaq -0x298(%rbp), %rdi
callq 0x58d8
movq -0x278(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x278(%rbp)
jmp 0x30782
leaq -0x218(%rbp), %rdi
callq 0x50f0
jmp 0x308b6
movq -0x2e8(%rbp), %rdi
addq $0x10, %rdi
callq 0x33af0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %esi
callq 0x9b70
jmp 0x308d9
movq -0x2e8(%rbp), %rdi
addq $0x10, %rdi
callq 0x33af0
movq %rax, %rdi
callq 0x8540
movl %eax, -0x314(%rbp)
jmp 0x308f9
movq -0x2e8(%rbp), %rdi
callq 0xea70
movq -0x2e8(%rbp), %rdi
movq %rax, %rcx
movl -0x314(%rbp), %eax
movl 0xc4(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x2b4(%rbp)
callq 0xea70
movq %rax, %rdx
addq $0x94, %rdx
leaq -0x2b0(%rbp), %rdi
leaq -0x2b4(%rbp), %rsi
callq 0x352a0
jmp 0x30947
movq -0x2e8(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x328(%rbp)
leaq -0x2b0(%rbp), %rsi
movq %rsi, -0x330(%rbp)
callq 0x33f20
movq -0x330(%rbp), %rdi
callq 0x23bb0
movq -0x328(%rbp), %rdi
callq 0x23990
movq -0x2e8(%rbp), %rdi
movq %rax, -0x320(%rbp)
callq 0xea70
movq -0x320(%rbp), %rdi
cvtsi2sdl 0x94(%rax), %xmm1
movsd 0x11f82(%rip), %xmm0    # 0x42930
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x1e3b0
jmp 0x309bd
movq $0x0, -0x2c0(%rbp)
movq -0x2c0(%rbp), %rax
cmpq -0x248(%rbp), %rax
jae 0x30b26
movq -0x2e8(%rbp), %rdi
addq $0x10, %rdi
callq 0x33af0
movq %rax, -0x340(%rbp)
movq -0x2c0(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x34d50
movq -0x340(%rbp), %rdi
movq %rax, %rsi
callq 0x8770
movl %eax, -0x334(%rbp)
jmp 0x30a1d
movl -0x334(%rbp), %eax
movl %eax, -0x2c4(%rbp)
cmpl $0x0, -0x2c4(%rbp)
jl 0x30a6e
movq -0x2e8(%rbp), %rdi
movl -0x2c4(%rbp), %eax
movl %eax, -0x348(%rbp)
addq $0x10, %rdi
callq 0x33af0
movq %rax, %rdi
callq 0x8540
movl %eax, -0x344(%rbp)
jmp 0x30a5e
movl -0x348(%rbp), %eax
movl -0x344(%rbp), %ecx
cmpl %ecx, %eax
jl 0x30a73
jmp 0x30b0f
movq $0x0, -0x2d0(%rbp)
movq -0x2d0(%rbp), %rax
cmpq -0x250(%rbp), %rax
jae 0x30b0d
leaq -0x240(%rbp), %rdi
callq 0x23990
movq -0x2e8(%rbp), %rdi
movq (%rax), %rax
movq -0x2c0(%rbp), %rcx
imulq -0x250(%rbp), %rcx
addq -0x2d0(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x34c(%rbp)
addq $0x20, %rdi
callq 0x23990
movss -0x34c(%rbp), %xmm0
movq (%rax), %rax
movslq -0x2c4(%rbp), %rcx
imulq -0x250(%rbp), %rcx
addq -0x2d0(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x2d0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2d0(%rbp)
jmp 0x30a7e
jmp 0x30b0f
movq -0x2c0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2c0(%rbp)
jmp 0x309c8
leaq -0x240(%rbp), %rdi
callq 0x23bb0
leaq -0x230(%rbp), %rdi
callq 0xebb0
leaq -0x218(%rbp), %rdi
callq 0x5130
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
leaq -0x240(%rbp), %rdi
callq 0x23bb0
leaq -0x230(%rbp), %rdi
callq 0xebb0
leaq -0x218(%rbp), %rdi
callq 0x5130
movq -0x258(%rbp), %rdi
callq 0x57a0
nopw %cs:(%rax,%rax)