// File: epfml[P]sent2vec/src/fasttext.cc
// Function: fasttext::FastText::loadModel(std::istream&, bool)
void FastText::loadModel(std::istream& in, bool load_output_matrix /* = true */) {
  args_ = std::make_shared<Args>();
  dict_ = std::make_shared<Dictionary>(args_);
  input_ = std::make_shared<Matrix>();
  output_ = std::make_shared<Matrix>();
  qinput_ = std::make_shared<QMatrix>();
  qoutput_ = std::make_shared<QMatrix>();
  args_->load(in);

  dict_->load(in);

  bool quant_input;
  in.read((char*) &quant_input, sizeof(bool));
  if (quant_input) {
    quant_ = true;
    qinput_->load(in);
  } else {
    input_->load(in);
  }

  // Only load qoutput_ and output_ matrices if explicitly requested
  if (load_output_matrix) {
      in.read((char*) &args_->qout, sizeof(bool));
      if (quant_ && args_->qout) {
        qoutput_->load(in);
      } else {
        output_->load(in);
      }
  }

  model_ = std::make_shared<Model>(input_, output_, args_, 0);
  model_->quant_ = quant_;
  model_->setQuantizePointer(qinput_, qoutput_, args_->qout);

  if (args_->model == model_name::sup) {
    model_->setTargetCounts(dict_->getCounts(entry_type::label));
  } else {
    model_->setTargetCounts(dict_->getCounts(entry_type::word));
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x33b10
movq -0x100(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x33b80
leaq -0x28(%rbp), %rdi
callq 0xe540
movq -0x100(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x33bb0
movq -0x100(%rbp), %rdi
addq $0x10, %rdi
leaq -0x38(%rbp), %rsi
callq 0x33c20
leaq -0x38(%rbp), %rdi
callq 0x33c50
leaq -0x48(%rbp), %rdi
callq 0x33eb0
movq -0x100(%rbp), %rdi
addq $0x20, %rdi
leaq -0x48(%rbp), %rsi
callq 0x33f20
leaq -0x48(%rbp), %rdi
callq 0x23bb0
leaq -0x58(%rbp), %rdi
callq 0x33eb0
movq -0x100(%rbp), %rdi
addq $0x30, %rdi
leaq -0x58(%rbp), %rsi
callq 0x33f20
leaq -0x58(%rbp), %rdi
callq 0x23bb0
leaq -0x68(%rbp), %rdi
callq 0x33f50
movq -0x100(%rbp), %rdi
addq $0x40, %rdi
leaq -0x68(%rbp), %rsi
callq 0x33fc0
leaq -0x68(%rbp), %rdi
callq 0x23b90
leaq -0x78(%rbp), %rdi
callq 0x33f50
movq -0x100(%rbp), %rdi
addq $0x50, %rdi
leaq -0x78(%rbp), %rsi
callq 0x33fc0
leaq -0x78(%rbp), %rdi
callq 0x23b90
movq -0x100(%rbp), %rdi
callq 0xea70
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x7c80
movq -0x100(%rbp), %rdi
addq $0x10, %rdi
callq 0x33af0
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0xb370
movq -0x10(%rbp), %rdi
leaq -0x79(%rbp), %rsi
movl $0x1, %edx
callq 0x5540
testb $0x1, -0x79(%rbp)
je 0x29c4d
movq -0x100(%rbp), %rdi
movb $0x1, 0x80(%rdi)
addq $0x40, %rdi
callq 0x23c00
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x206d0
jmp 0x29c69
movq -0x100(%rbp), %rdi
addq $0x20, %rdi
callq 0x23990
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x1ea80
testb $0x1, -0x11(%rbp)
je 0x29d06
movq -0x100(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
callq 0xea70
movq -0x108(%rbp), %rdi
movq %rax, %rsi
addq $0x12c, %rsi            # imm = 0x12C
movl $0x1, %edx
callq 0x5540
movq -0x100(%rbp), %rax
testb $0x1, 0x80(%rax)
je 0x29ce8
movq -0x100(%rbp), %rdi
callq 0xea70
testb $0x1, 0x12c(%rax)
je 0x29ce8
movq -0x100(%rbp), %rdi
addq $0x50, %rdi
callq 0x23c00
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x206d0
jmp 0x29d04
movq -0x100(%rbp), %rdi
addq $0x30, %rdi
callq 0x23990
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x1ea80
jmp 0x29d06
movq -0x100(%rbp), %rcx
movq %rcx, %rsi
addq $0x20, %rsi
movq %rcx, %rdx
addq $0x30, %rdx
movl $0x0, -0x94(%rbp)
leaq -0x90(%rbp), %rdi
movq %rdi, -0x138(%rbp)
leaq -0x94(%rbp), %r8
callq 0x33ff0
movq -0x138(%rbp), %rsi
movq -0x100(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0x128(%rbp)
callq 0x34080
movq -0x138(%rbp), %rdi
callq 0x340b0
movq -0x128(%rbp), %rdi
movq -0x100(%rbp), %rax
movb 0x80(%rax), %al
movb %al, -0x129(%rbp)
callq 0x340d0
movb -0x129(%rbp), %cl
movq -0x128(%rbp), %rdi
andb $0x1, %cl
movb %cl, 0x118(%rax)
callq 0x340d0
movq -0x100(%rbp), %rsi
movq %rax, -0x120(%rbp)
addq $0x40, %rsi
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x340f0
movq -0x100(%rbp), %rsi
addq $0x50, %rsi
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x340f0
movq -0x100(%rbp), %rdi
callq 0xea70
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rsi
movq -0x110(%rbp), %rdx
movzbl 0x12c(%rax), %ecx
andl $0x1, %ecx
callq 0x21df0
jmp 0x29e18
leaq -0xb8(%rbp), %rdi
callq 0x23b90
leaq -0xa8(%rbp), %rdi
callq 0x23b90
movq -0x100(%rbp), %rdi
callq 0xea70
cmpl $0x3, 0xc0(%rax)
jne 0x29f03
movq -0x100(%rbp), %rdi
addq $0x60, %rdi
callq 0x340d0
movq -0x100(%rbp), %rdi
movq %rax, -0x148(%rbp)
addq $0x10, %rdi
callq 0x33af0
movq %rax, %rsi
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x140(%rbp)
movl $0x1, %edx
callq 0xa150
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
callq 0x231c0
jmp 0x29ea0
leaq -0xe0(%rbp), %rdi
callq 0xf080
jmp 0x29f85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x23b90
leaq -0xa8(%rbp), %rdi
callq 0x23b90
jmp 0x29f8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xf080
jmp 0x29f8e
movq -0x100(%rbp), %rdi
addq $0x60, %rdi
callq 0x340d0
movq -0x100(%rbp), %rdi
movq %rax, -0x158(%rbp)
addq $0x10, %rdi
callq 0x33af0
movq %rax, %rsi
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
xorl %edx, %edx
callq 0xa150
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x231c0
jmp 0x29f57
leaq -0xf8(%rbp), %rdi
callq 0xf080
jmp 0x29f85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xf080
jmp 0x29f8e
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x57a0
nopw (%rax,%rax)