// File: epfml[P]Bi-Sent2Vec/src/fasttext.cc
// Function: fasttext::FastText::quantize(std::shared_ptr<fasttext::Args>)
void FastText::quantize(std::shared_ptr<Args> qargs) {
  if (qargs->output.empty()) {
      std::cerr<<"No model provided!"<<std::endl; exit(1);
  }
  loadModel(qargs->output + ".bin");

  args_->input = qargs->input;
  args_->qout = qargs->qout;
  args_->output = qargs->output;


  if (qargs->cutoff > 0 && qargs->cutoff < input_->m_) {
    auto idx = selectEmbeddings(qargs->cutoff);
    dict_->prune(idx);
    std::shared_ptr<Matrix> ninput =
      std::make_shared<Matrix> (idx.size(), args_->dim);
    for (auto i = 0; i < idx.size(); i++) {
      for (auto j = 0; j < args_->dim; j++) {
        ninput->at(i,j) = input_->at(idx[i], j);
      }
    }
    input_ = ninput;
    if (qargs->retrain) {
      args_->epoch = qargs->epoch;
      args_->lr = qargs->lr;
      args_->thread = qargs->thread;
      args_->verbose = qargs->verbose;
      tokenCount = 0;
      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();
      }
    }
  }

  qinput_ = std::make_shared<QMatrix>(*input_, qargs->dsub, qargs->qnorm);

  if (args_->qout) {
    qoutput_ = std::make_shared<QMatrix>(*output_, 2, qargs->qnorm);
  }

  quant_ = true;
  saveModel();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rsi, -0x100(%rbp)
movq %rdi, %rax
movq -0x100(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
callq 0xe6e0
movq %rax, %rdi
addq $0x40, %rdi
callq 0x5710
testb $0x1, %al
jne 0x2a59d
jmp 0x2a5c9
movq 0x34a4c(%rip), %rdi     # 0x5eff0
leaq 0x1921b(%rip), %rsi     # 0x437c6
callq 0x5420
movq %rax, %rdi
movq 0x349d6(%rip), %rsi     # 0x5ef90
callq 0x5460
movl $0x1, %edi
callq 0x54f0
movq -0xf8(%rbp), %rdi
callq 0xe6e0
movq %rax, %rsi
addq $0x40, %rsi
leaq 0x19187(%rip), %rdx     # 0x4376a
leaq -0x30(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x1ed90
movq -0xf0(%rbp), %rdi
movq -0x108(%rbp), %rsi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x295b0
jmp 0x2a60f
leaq -0x30(%rbp), %rdi
callq 0x58d8
movq -0xf8(%rbp), %rdi
callq 0xe6e0
movq -0xf0(%rbp), %rdi
movq %rax, -0x120(%rbp)
callq 0xe6e0
movq -0x120(%rbp), %rsi
movq %rax, %rdi
callq 0x5070
movq -0xf8(%rbp), %rdi
callq 0xe6e0
movq -0xf0(%rbp), %rdi
movb 0x12c(%rax), %al
movb %al, -0x111(%rbp)
callq 0xe6e0
movb -0x111(%rbp), %cl
movq -0xf8(%rbp), %rdi
andb $0x1, %cl
movb %cl, 0x12c(%rax)
callq 0xe6e0
movq -0xf0(%rbp), %rdi
addq $0x40, %rax
movq %rax, -0x110(%rbp)
callq 0xe6e0
movq -0x110(%rbp), %rsi
movq %rax, %rdi
addq $0x40, %rdi
callq 0x5070
movq -0xf8(%rbp), %rdi
callq 0xe6e0
cmpq $0x0, 0x130(%rax)
jbe 0x2ab4b
movq -0xf8(%rbp), %rdi
callq 0xe6e0
movq -0xf0(%rbp), %rdi
movq 0x130(%rax), %rax
movq %rax, -0x128(%rbp)
addq $0x20, %rdi
callq 0x235f0
movq %rax, %rcx
movq -0x128(%rbp), %rax
cmpq 0x8(%rcx), %rax
jae 0x2ab4b
movq -0xf8(%rbp), %rdi
callq 0xe6e0
movq -0xf0(%rbp), %rsi
movl 0x130(%rax), %edx
leaq -0x58(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x2a250
movq -0xf0(%rbp), %rdi
addq $0x10, %rdi
callq 0x34050
movq -0x130(%rbp), %rsi
movq %rax, %rdi
callq 0xb2a0
jmp 0x2a751
leaq -0x58(%rbp), %rdi
callq 0xed50
movq -0xf0(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0xe6e0
movq %rax, %rdx
addq $0x94, %rdx
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x34870
jmp 0x2a783
movl $0x0, -0x74(%rbp)
movslq -0x74(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xed50
movq %rax, %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
jae 0x2a8c4
movl $0x0, -0x78(%rbp)
movq -0xf0(%rbp), %rdi
movl -0x78(%rbp), %eax
movl %eax, -0x13c(%rbp)
callq 0xe6e0
movq %rax, %rcx
movl -0x13c(%rbp), %eax
cmpl 0x94(%rcx), %eax
jge 0x2a8b4
movq -0xf0(%rbp), %rdi
addq $0x20, %rdi
callq 0x235f0
movq %rax, -0x150(%rbp)
movslq -0x74(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xe240
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
movslq -0x78(%rbp), %rdx
callq 0x1e820
movq %rax, -0x148(%rbp)
jmp 0x2a822
movq -0x148(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x15c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x235f0
movq %rax, %rdi
movslq -0x74(%rbp), %rsi
movslq -0x78(%rbp), %rdx
callq 0x1e820
movq %rax, -0x158(%rbp)
jmp 0x2a857
movq -0x158(%rbp), %rax
movss -0x15c(%rbp), %xmm0
movss %xmm0, (%rax)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x2a7b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x58d8
jmp 0x2ac73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2ab3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2ab34
jmp 0x2a8b6
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x2a78a
movq -0xf0(%rbp), %rdi
addq $0x20, %rdi
leaq -0x68(%rbp), %rsi
callq 0x23670
movq -0xf8(%rbp), %rdi
callq 0xe6e0
testb $0x1, 0x12d(%rax)
je 0x2ab20
movq -0xf8(%rbp), %rdi
callq 0xe6e0
movq -0xf0(%rbp), %rdi
movl 0xa0(%rax), %eax
movl %eax, -0x174(%rbp)
callq 0xe6e0
movl -0x174(%rbp), %ecx
movq -0xf8(%rbp), %rdi
movl %ecx, 0xa0(%rax)
callq 0xe6e0
movq -0xf0(%rbp), %rdi
movsd 0x80(%rax), %xmm0
movsd %xmm0, -0x170(%rbp)
callq 0xe6e0
movsd -0x170(%rbp), %xmm0
movq -0xf8(%rbp), %rdi
movsd %xmm0, 0x80(%rax)
callq 0xe6e0
movq -0xf0(%rbp), %rdi
movl 0xd4(%rax), %eax
movl %eax, -0x164(%rbp)
callq 0xe6e0
movl -0x164(%rbp), %ecx
movq -0xf8(%rbp), %rdi
movl %ecx, 0xd4(%rax)
callq 0xe6e0
movq -0xf0(%rbp), %rdi
movl 0x100(%rax), %eax
movl %eax, -0x160(%rbp)
callq 0xe6e0
movl -0x160(%rbp), %ecx
movq -0xf0(%rbp), %rdi
movl %ecx, 0x100(%rax)
addq $0x70, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x348f0
leaq -0x90(%rbp), %rdi
callq 0x34980
movl $0x0, -0x94(%rbp)
movq -0xf0(%rbp), %rdi
movl -0x94(%rbp), %eax
movl %eax, -0x178(%rbp)
callq 0xe6e0
movq %rax, %rcx
movl -0x178(%rbp), %eax
cmpl 0xd4(%rcx), %eax
jge 0x2aa9f
movq -0xf0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x2ac80
jmp 0x2aa3f
leaq -0x90(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x349a0
jmp 0x2aa54
leaq -0xa0(%rbp), %rdi
callq 0x349d0
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x2a9e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2ab12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x349d0
jmp 0x2ab12
leaq -0x90(%rbp), %rdi
callq 0x34a00
movq %rax, -0xb8(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x34a70
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x34a30
testb $0x1, %al
jne 0x2aade
jmp 0x2ab04
leaq -0xb8(%rbp), %rdi
callq 0x34aa0
movq %rax, %rdi
callq 0x5750
jmp 0x2aaf4
jmp 0x2aaf6
leaq -0xb8(%rbp), %rdi
callq 0x34ac0
jmp 0x2aab2
leaq -0x90(%rbp), %rdi
callq 0x34ae0
jmp 0x2ab20
leaq -0x90(%rbp), %rdi
callq 0x34ae0
jmp 0x2ab34
leaq -0x68(%rbp), %rdi
callq 0x23810
leaq -0x58(%rbp), %rdi
callq 0xe530
jmp 0x2ab4b
leaq -0x68(%rbp), %rdi
callq 0x23810
leaq -0x58(%rbp), %rdi
callq 0xe530
jmp 0x2ac73
movq -0xf0(%rbp), %rdi
addq $0x20, %rdi
callq 0x23880
movq -0xf8(%rbp), %rdi
movq %rax, -0x188(%rbp)
callq 0xe6e0
movq -0xf8(%rbp), %rdi
addq $0x138, %rax            # imm = 0x138
movq %rax, -0x180(%rbp)
callq 0xe6e0
movq -0x188(%rbp), %rsi
movq -0x180(%rbp), %rdx
movq %rax, %rcx
addq $0x12e, %rcx            # imm = 0x12E
leaq -0xd0(%rbp), %rdi
callq 0x34b40
movq -0xf0(%rbp), %rdi
addq $0x40, %rdi
leaq -0xd0(%rbp), %rsi
callq 0x34520
leaq -0xd0(%rbp), %rdi
callq 0x237f0
movq -0xf0(%rbp), %rdi
callq 0xe6e0
testb $0x1, 0x12c(%rax)
je 0x2ac57
movq -0xf0(%rbp), %rdi
addq $0x30, %rdi
callq 0x23880
movq -0xf8(%rbp), %rdi
movq %rax, -0x190(%rbp)
movl $0x2, -0xe4(%rbp)
callq 0xe6e0
movq -0x190(%rbp), %rsi
movq %rax, %rcx
addq $0x12e, %rcx            # imm = 0x12E
leaq -0xe0(%rbp), %rdi
leaq -0xe4(%rbp), %rdx
callq 0x34bc0
movq -0xf0(%rbp), %rdi
addq $0x50, %rdi
leaq -0xe0(%rbp), %rsi
callq 0x34520
leaq -0xe0(%rbp), %rdi
callq 0x237f0
movq -0xf0(%rbp), %rdi
movb $0x1, 0x80(%rdi)
callq 0x28f90
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x57a0
nopl (%rax)