// File: /workspace/github_cpp_makefile_star2_O2/epfml[P]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);
  } else {
    input_ = std::make_shared<Matrix>(dict_->nwords()+args_->bucket+args_->bucketChar, args_->dim);
    input_->uniform(1.0 / args_->dim);
  }

  if (args_->model == model_name::sup) {
    output_ = std::make_shared<Matrix>(dict_->nlabels(), args_->dim);
  } else {
    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::sup && args_->model != model_name::sent2vec && args_->model != model_name::cbowCWNgrams) {
    saveVectors();
    if (args_->saveOutput > 0) {
      saveOutput();
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdi, %rbx
callq 0xed86
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x156d4
leaq 0x10(%rbx), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x15f9e
leaq 0x58(%rsp), %rdi
callq 0x8d50
movq (%rbx), %rdi
leaq 0x5e91(%rip), %rsi      # 0x1ac43
callq 0x5cfb
testb %al, %al
jne 0x15068
movq (%rbx), %rsi
leaq 0x50(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x4520
leaq 0xc8(%rsp), %rdi
callq 0x40c0
testb %al, %al
je 0x1508b
movq (%r14), %rdi
leaq 0x50(%rsp), %rsi
callq 0x684c
leaq 0x50(%rsp), %rdi
callq 0x40a0
movq (%rbx), %rsi
cmpq $0x0, 0x110(%rsi)
je 0x14e32
addq $0x108, %rsi            # imm = 0x108
leaq 0x30(%rsp), %rdi
callq 0x4460
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x14602
leaq 0x30(%rsp), %rdi
callq 0x46c8
jmp 0x14e9d
movq (%r14), %rdi
callq 0x5f90
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 0x15a3e
leaq 0x20(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x16130
leaq 0x18(%rsp), %rdi
callq 0x8d50
movq (%rbx), %rax
movq 0x20(%rbx), %rdi
cvtsi2sdl 0x94(%rax), %xmm0
movsd 0x4ac8(%rip), %xmm1     # 0x19958
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
callq 0xc0e6
movq (%rbx), %rax
cmpl $0x3, 0xc0(%rax)
jne 0x14ecc
movq (%r14), %rdi
callq 0x5f94
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x94, %edx
addq (%rbx), %rdx
leaq 0x10(%rsp), %rdi
callq 0x15a3e
jmp 0x14eed
movq (%r14), %rdi
callq 0x5f90
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x94, %edx
addq (%rbx), %rdx
leaq 0x10(%rsp), %rdi
callq 0x15a3e
leaq 0x30(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x16130
leaq 0x18(%rsp), %rdi
callq 0x8d50
movq 0x30(%rbx), %rdi
callq 0xc0c8
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 0x14fb1
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq 0x11dc7(%rip), %r15     # 0x26d10
leaq 0x28(%rsp), %r12
leaq 0x8(%rsp), %r13
cmpl %eax, %ebp
jge 0x14fbd
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 0x14f91
movq (%rdi), %rax
callq *0x8(%rax)
movq %r14, %rdi
movq %r12, %rsi
callq 0x16728
movq %r12, %rdi
callq 0x15878
incl %ebp
movq (%rbx), %rax
movl 0xd4(%rax), %eax
jmp 0x14f53
movq %rbx, %rdi
xorl %esi, %esi
callq 0x14136
jmp 0x14fe1
movq 0x10(%rsp), %r14
cmpq 0x18(%rsp), %r14
je 0x14fd7
movq %r14, %rdi
callq 0x45a0
addq $0x8, %r14
jmp 0x14fc2
leaq 0x10(%rsp), %rdi
callq 0x15886
leaq 0x30(%rbx), %rdx
leaq 0x20(%rbx), %rsi
leaq 0x8(%rsp), %r8
andl $0x0, (%r8)
leaq 0x10(%rsp), %rdi
movq %rbx, %rcx
callq 0x15807
leaq 0x60(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1654a
leaq 0x18(%rsp), %rdi
callq 0x8d50
movq %rbx, %rdi
callq 0x10254
movq (%rbx), %rax
movl 0xc0(%rax), %eax
addl $-0x3, %eax
cmpl $0x3, %eax
jb 0x1504c
movq %rbx, %rdi
callq 0xfc3a
movq (%rbx), %rax
cmpl $0x0, 0x128(%rax)
jle 0x1504c
movq %rbx, %rdi
callq 0xfdfa
leaq 0x50(%rsp), %rdi
callq 0x40e0
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x11f81(%rip), %rdi     # 0x26ff0
leaq 0x5bcf(%rip), %rsi      # 0x1ac45
callq 0x4330
movq %rax, %rdi
callq 0x4190
pushq $0x1
popq %rdi
callq 0x43b0
movq 0x11f5e(%rip), %rdi     # 0x26ff0
leaq 0x5bcb(%rip), %rsi      # 0x1ac64
callq 0x4330
movq %rax, %rdi
callq 0x4190
jmp 0x15083
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x46c8
jmp 0x150f7
jmp 0x150bf
jmp 0x150bf
jmp 0x150bf
jmp 0x150bf
movq %rax, %rbx
jmp 0x150f7
jmp 0x150ea
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x15878
jmp 0x150ed
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x150ed
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x150ed
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x15886
leaq 0x50(%rsp), %rdi
callq 0x40e0
movq %rbx, %rdi
callq 0x45d0
nop