// File: /workspace/github_cpp_makefile_star2_O2/epfml[P]Bi-Sent2Vec/src/fasttext.cc
// Function: fasttext::FastText::train(std::shared_ptr<fasttext::Args>)
void FastText::train(std::shared_ptr<Args> args) {
  args_ = args;
  dict_ = std::make_shared<Dictionary>(args_);
  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);
    loadOutputVectors(args_->pretrainedVectors);
  } else {
    input_ = std::make_shared<Matrix>(dict_->nwords()+args_->bucket+args_->bucketChar, 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();
  saveVectors();
  if (args_->saveOutput > 0) {
    saveOutput();
  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdi, %rbx
callq 0xeb9a
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x15ba7
leaq 0x10(%rbx), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x162fc
leaq 0x78(%rsp), %rdi
callq 0x8b66
movq (%rbx), %rdi
leaq 0x680e(%rip), %rsi      # 0x1b9c0
callq 0x5b9f
testb %al, %al
jne 0x15454
movq (%rbx), %rsi
leaq 0x70(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x4520
leaq 0xe8(%rsp), %rdi
callq 0x40c0
testb %al, %al
je 0x15477
movq (%r14), %rdi
leaq 0x70(%rsp), %rsi
callq 0x66a2
leaq 0x70(%rsp), %rdi
callq 0x40a0
movq (%rbx), %rsi
cmpq $0x0, 0x110(%rsi)
je 0x1525e
addq $0x108, %rsi            # imm = 0x108
leaq 0x50(%rsp), %rdi
callq 0x4460
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x146be
leaq 0x50(%rsp), %rdi
callq 0x46c8
movl $0x108, %esi            # imm = 0x108
addq (%rbx), %rsi
leaq 0x30(%rsp), %rdi
callq 0x4460
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x149ee
leaq 0x30(%rsp), %rdi
callq 0x46c8
jmp 0x1530b
movq (%r14), %rdi
callq 0x5e34
movq (%rbx), %rdx
addl 0xc4(%rdx), %eax
addl 0xc8(%rdx), %eax
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
addq $0x94, %rdx
leaq 0x10(%rsp), %rdi
callq 0x15d9c
leaq 0x20(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1648e
leaq 0x18(%rsp), %rdi
callq 0x8b66
movq (%rbx), %rax
movq 0x20(%rbx), %rdi
cvtsi2sdl 0x94(%rax), %xmm0
movsd 0x562c(%rip), %xmm1     # 0x1a8e8
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
callq 0xbefe
movq (%r14), %rdi
callq 0x5e34
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x94, %edx
addq (%rbx), %rdx
leaq 0x10(%rsp), %rdi
callq 0x15d9c
leaq 0x30(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1648e
leaq 0x18(%rsp), %rdi
callq 0x8b66
movq 0x30(%rbx), %rdi
callq 0xbee0
callq 0x4220
movq %rax, 0x78(%rbx)
xorl %eax, %eax
xchgq %rax, 0x70(%rbx)
xorl %ebp, %ebp
movq (%rbx), %rax
movl 0xd4(%rax), %eax
cmpl $0x2, %eax
jl 0x153ae
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq 0x129ca(%rip), %r15     # 0x27d10
leaq 0x28(%rsp), %r12
leaq 0x8(%rsp), %r13
cmpl %eax, %ebp
jge 0x153ba
andq $0x0, 0x28(%rsp)
pushq $0x18
popq %rdi
callq 0x4340
movq %r15, (%rax)
movq %rbx, 0x8(%rax)
movl %ebp, 0x10(%rax)
movq %rax, 0x8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x4300
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1538e
movq (%rdi), %rax
callq *0x8(%rax)
movq %r14, %rdi
movq %r12, %rsi
callq 0x16a86
movq %r12, %rdi
callq 0x15c6c
incl %ebp
movq (%rbx), %rax
movl 0xd4(%rax), %eax
jmp 0x15350
movq %rbx, %rdi
xorl %esi, %esi
callq 0x14258
jmp 0x153de
movq 0x10(%rsp), %r14
cmpq 0x18(%rsp), %r14
je 0x153d4
movq %r14, %rdi
callq 0x45a0
addq $0x8, %r14
jmp 0x153bf
leaq 0x10(%rsp), %rdi
callq 0x15c7a
leaq 0x20(%rbx), %rsi
leaq 0x30(%rbx), %rdx
leaq 0x8(%rsp), %r8
andl $0x0, (%r8)
leaq 0x10(%rsp), %rdi
movq %rbx, %rcx
callq 0x15bfb
leaq 0x60(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x168a8
leaq 0x18(%rsp), %rdi
callq 0x8b66
movq %rbx, %rdi
callq 0x102f0
movq %rbx, %rdi
callq 0xfa4e
movq (%rbx), %rax
cmpl $0x0, 0x128(%rax)
jle 0x15438
movq %rbx, %rdi
callq 0xfe96
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 0x12b95(%rip), %rdi     # 0x27ff0
leaq 0x6560(%rip), %rsi      # 0x1b9c2
callq 0x4330
movq %rax, %rdi
callq 0x4190
pushq $0x1
popq %rdi
callq 0x43b0
movq 0x12b72(%rip), %rdi     # 0x27ff0
leaq 0x655c(%rip), %rsi      # 0x1b9e1
callq 0x4330
movq %rax, %rdi
callq 0x4190
jmp 0x1546f
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x154a6
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x46c8
jmp 0x154eb
jmp 0x154b3
jmp 0x154b3
jmp 0x154b3
movq %rax, %rbx
jmp 0x154eb
jmp 0x154de
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x15c6c
jmp 0x154e1
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x154e1
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x154e1
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x15c7a
leaq 0x70(%rsp), %rdi
callq 0x40e0
movq %rbx, %rdi
callq 0x45d0
nop