// File: epfml[P]Bi-Sent2Vec/src/fasttext.cc
// Function: fasttext::FastText::savedDictTrain(std::shared_ptr<fasttext::Args>)
void FastText::savedDictTrain(std::shared_ptr<Args> args) {
  loadDict(args_->dict);
  if (args_->input == "-") {
    // manage expectations
    std::cerr << "Cannot use stdin for training!" << std::endl;
    exit(EXIT_FAILURE);
  }
  std::ifstream ifs(args_->input);
  if (!ifs.is_open()) {
    std::cerr << "Input file cannot be opened!" << std::endl;
    exit(EXIT_FAILURE);
  }
  dict_->readFromFile(ifs);
  ifs.close();

  if (args_->pretrainedVectors.size() != 0) {
    loadVectors(args_->pretrainedVectors);
  } else {
    input_ = std::make_shared<Matrix>(dict_->nwords()+args_->bucket, args_->dim);
    input_->uniform(1.0 / args_->dim);
  }

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

  start = clock();
  tokenCount = 0;
  if (args_->thread > 1) {
    std::vector<std::thread> threads;
    for (int32_t i = 0; i < args_->thread; i++) {
      threads.push_back(std::thread([=]() { trainThread(i); }));
    }
    for (auto it = threads.begin(); it != threads.end(); ++it) {
      it->join();
    }
  } else {
    trainThread(0);
  }
  model_ = std::make_shared<Model>(input_, output_, args_, 0);

  saveModel();
  if (args_->model != model_name::bisent2vec) {
    saveVectors();
    if (args_->saveOutput > 0) {
      saveOutput();
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0xe6e0
movq -0x2e0(%rbp), %rdi
movq %rax, %rsi
addq $0x60, %rsi
callq 0x28d90
movq -0x2e0(%rbp), %rdi
callq 0xe6e0
movq %rax, %rdi
leaq 0x1270c(%rip), %rsi     # 0x43958
callq 0x7cc0
testb $0x1, %al
jne 0x31257
jmp 0x31283
movq 0x2dd92(%rip), %rdi     # 0x5eff0
leaq 0x126f5(%rip), %rsi     # 0x4395a
callq 0x5420
movq %rax, %rdi
movq 0x2dd1c(%rip), %rsi     # 0x5ef90
callq 0x5460
movl $0x1, %edi
callq 0x54f0
movq -0x2e0(%rbp), %rdi
callq 0xe6e0
movq %rax, %rsi
leaq -0x218(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
movl $0x8, %edx
callq 0x56d0
movq -0x2f0(%rbp), %rdi
callq 0x56c0
movb %al, -0x2e1(%rbp)
jmp 0x312be
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x3131c
jmp 0x312ca
movq 0x2dd1f(%rip), %rdi     # 0x5eff0
leaq 0x126a1(%rip), %rsi     # 0x43979
callq 0x5420
movq %rax, -0x2f8(%rbp)
jmp 0x312e6
movq -0x2f8(%rbp), %rdi
movq 0x2dc9c(%rip), %rsi     # 0x5ef90
callq 0x5460
jmp 0x312fb
movl $0x1, %edi
callq 0x54f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x317d2
movq -0x2e0(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
leaq -0x218(%rbp), %rsi
callq 0x92c0
jmp 0x3133d
leaq -0x218(%rbp), %rdi
callq 0x50f0
jmp 0x3134b
movq -0x2e0(%rbp), %rdi
callq 0xe6e0
movq %rax, %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x5300
cmpq $0x0, %rax
je 0x313d9
movq -0x2e0(%rbp), %rdi
callq 0xe6e0
movq %rax, %rsi
addq $0x108, %rsi            # imm = 0x108
leaq -0x248(%rbp), %rdi
callq 0x51d0
jmp 0x31390
movq -0x2e0(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x305a0
jmp 0x313a5
leaq -0x248(%rbp), %rdi
callq 0x58d8
jmp 0x314bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x58d8
jmp 0x317d2
movq -0x2e0(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
callq 0x8340
movl %eax, -0x2fc(%rbp)
jmp 0x313f9
movq -0x2e0(%rbp), %rdi
callq 0xe6e0
movq -0x2e0(%rbp), %rdi
movq %rax, %rcx
movl -0x2fc(%rbp), %eax
movl 0xc4(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x25c(%rbp)
callq 0xe6e0
movq %rax, %rdx
addq $0x94, %rdx
leaq -0x258(%rbp), %rdi
leaq -0x25c(%rbp), %rsi
callq 0x356c0
jmp 0x31447
movq -0x2e0(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x310(%rbp)
leaq -0x258(%rbp), %rsi
movq %rsi, -0x318(%rbp)
callq 0x34480
movq -0x318(%rbp), %rdi
callq 0x23810
movq -0x310(%rbp), %rdi
callq 0x235f0
movq -0x2e0(%rbp), %rdi
movq %rax, -0x308(%rbp)
callq 0xe6e0
movq -0x308(%rbp), %rdi
cvtsi2sdl 0x94(%rax), %xmm1
movsd 0x1140a(%rip), %xmm0    # 0x428b8
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x1e020
jmp 0x314bd
jmp 0x314bf
movq -0x2e0(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq %rax, %rdi
callq 0x8340
movl %eax, -0x31c(%rbp)
jmp 0x314df
movq -0x2e0(%rbp), %rdi
movl -0x31c(%rbp), %eax
movl %eax, -0x274(%rbp)
callq 0xe6e0
movq %rax, %rdx
addq $0x94, %rdx
leaq -0x270(%rbp), %rdi
leaq -0x274(%rbp), %rsi
callq 0x356c0
jmp 0x31516
movq -0x2e0(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x328(%rbp)
leaq -0x270(%rbp), %rsi
movq %rsi, -0x330(%rbp)
callq 0x34480
movq -0x330(%rbp), %rdi
callq 0x23810
movq -0x328(%rbp), %rdi
callq 0x235f0
movq %rax, %rdi
callq 0x1dfc0
jmp 0x3155d
callq 0x52e0
movq -0x2e0(%rbp), %rdi
movq %rax, 0x78(%rdi)
addq $0x70, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x348f0
movq -0x2e0(%rbp), %rdi
callq 0xe6e0
cmpl $0x1, 0xd4(%rax)
jle 0x316f5
leaq -0x290(%rbp), %rdi
callq 0x34980
movl $0x0, -0x294(%rbp)
movq -0x2e0(%rbp), %rdi
movl -0x294(%rbp), %eax
movl %eax, -0x334(%rbp)
callq 0xe6e0
movq %rax, %rcx
movl -0x334(%rbp), %eax
cmpl 0xd4(%rcx), %eax
jge 0x31671
movq -0x2e0(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movl -0x294(%rbp), %eax
movl %eax, -0x2a8(%rbp)
leaq -0x2a0(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x317f0
jmp 0x31605
leaq -0x290(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x349a0
jmp 0x3161a
leaq -0x2a0(%rbp), %rdi
callq 0x349d0
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
jmp 0x315a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x316e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x349d0
jmp 0x316e4
leaq -0x290(%rbp), %rdi
callq 0x34a00
movq %rax, -0x2b8(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x34a70
movq %rax, -0x2c0(%rbp)
leaq -0x2b8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x34a30
testb $0x1, %al
jne 0x316b0
jmp 0x316d6
leaq -0x2b8(%rbp), %rdi
callq 0x34aa0
movq %rax, %rdi
callq 0x5750
jmp 0x316c6
jmp 0x316c8
leaq -0x2b8(%rbp), %rdi
callq 0x34ac0
jmp 0x31684
leaq -0x290(%rbp), %rdi
callq 0x34ae0
jmp 0x31707
leaq -0x290(%rbp), %rdi
callq 0x34ae0
jmp 0x317d2
movq -0x2e0(%rbp), %rdi
xorl %esi, %esi
callq 0x2fdf0
jmp 0x31705
jmp 0x31707
movq -0x2e0(%rbp), %rcx
movq %rcx, %rsi
addq $0x20, %rsi
movq %rcx, %rdx
addq $0x30, %rdx
movl $0x0, -0x2d4(%rbp)
leaq -0x2d0(%rbp), %rdi
leaq -0x2d4(%rbp), %r8
callq 0x34550
jmp 0x3173b
movq -0x2e0(%rbp), %rdi
addq $0x60, %rdi
leaq -0x2d0(%rbp), %rsi
movq %rsi, -0x340(%rbp)
callq 0x345e0
movq -0x340(%rbp), %rdi
callq 0x34610
movq -0x2e0(%rbp), %rdi
callq 0x28f90
jmp 0x31773
movq -0x2e0(%rbp), %rdi
callq 0xe6e0
cmpl $0x4, 0xc0(%rax)
je 0x317bd
movq -0x2e0(%rbp), %rdi
callq 0x28020
jmp 0x31796
movq -0x2e0(%rbp), %rdi
callq 0xe6e0
cmpl $0x0, 0x128(%rax)
jle 0x317bb
movq -0x2e0(%rbp), %rdi
callq 0x28800
jmp 0x317b9
jmp 0x317bb
jmp 0x317bd
leaq -0x218(%rbp), %rdi
callq 0x5130
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x218(%rbp), %rdi
callq 0x5130
movq -0x220(%rbp), %rdi
callq 0x57a0
nopw (%rax,%rax)