// File: /workspace/github_cpp_makefile_star2_O1/epfml[P]Bi-Sent2Vec/src/productquantizer.cc
// Function: fasttext::ProductQuantizer::train(int, float const*)
void ProductQuantizer::train(int32_t n, const real * x) {
  if (n < ksub_) {
    std::cerr<<"Matrix too small for quantization, must have > 256 rows"<<std::endl;
    exit(1);
  }
  std::vector<int32_t> perm(n, 0);
  std::iota(perm.begin(), perm.end(), 0);
  auto d = dsub_;
  auto np = std::min(n, max_points_);
  real* xslice = new real[np * dsub_];
  for (auto m = 0; m < nsubq_; m++) {
    if (m == nsubq_-1) {d = lastdsub_;}
    if (np != n) {std::shuffle(perm.begin(), perm.end(), rng);}
    for (auto j = 0; j < np; j++) {
      memcpy (xslice + j * d, x + perm[j] * dim_ + m * dsub_, d * sizeof(real));
    }
    kmeans(xslice, get_centroids(m, 0), np, d);
  }
  delete [] xslice;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, 0x50(%rsp)
cmpl %esi, 0x4(%rdi)
jg 0xd4f1
movl %esi, %ebp
movq %rdi, %r14
movslq %esi, %rsi
leaq 0x74(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x30(%rsp), %rbx
leaq 0x7(%rsp), %rcx
movq %rbx, %rdi
callq 0xd97e
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rcx, %rax
je 0xd370
xorl %edx, %edx
movl %edx, (%rax)
incl %edx
addq $0x4, %rax
cmpq %rcx, %rax
jne 0xd363
movl 0xc(%r14), %eax
movl 0x24(%r14), %ecx
cmpl %ebp, %eax
movl %ebp, %ebx
movl %eax, 0x1c(%rsp)
cmovll %eax, %ebx
movl %ebx, %eax
movl %ecx, (%rsp)
imull %ecx, %eax
cltq
leaq (,%rax,4), %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x4030
movq %rax, 0x8(%rsp)
movl 0x20(%r14), %eax
testl %eax, %eax
jle 0xd4c1
leaq 0x48(%r14), %rcx
movq %rcx, 0x48(%rsp)
movl %ebx, %ecx
xorl %r15d, %r15d
movl %ebp, 0x14(%rsp)
movq %r14, 0x20(%rsp)
movl %ebx, 0x18(%rsp)
movq %rcx, 0x58(%rsp)
decl %eax
cmpl %eax, %r15d
jne 0xd3e6
movl 0x28(%r14), %eax
movl %eax, (%rsp)
cmpl %ebp, 0x1c(%rsp)
jge 0xd400
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0xd9fb
movq %r15, 0x60(%rsp)
movslq %r15d, %rax
movq %rax, 0x28(%rsp)
testl %ebx, %ebx
movq 0x58(%rsp), %r14
jle 0xd472
movq 0x30(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x20(%rsp), %rax
movslq 0x1c(%rax), %r12
movslq 0x24(%rax), %rax
imulq 0x28(%rsp), %rax
movq 0x50(%rsp), %rcx
leaq (%rcx,%rax,4), %r15
movslq (%rsp), %rbx
shlq $0x2, %rbx
movq 0x8(%rsp), %r13
xorl %ebp, %ebp
movq 0x68(%rsp), %rax
movslq (%rax,%rbp,4), %rax
imulq %r12, %rax
leaq (%r15,%rax,4), %rsi
movq %r13, %rdi
movq %rbx, %rdx
callq 0x4260
incq %rbp
addq %rbx, %r13
cmpq %rbp, %r14
jne 0xd44b
movq 0x20(%rsp), %r14
movslq 0x4(%r14), %rax
imulq 0x28(%rsp), %rax
movslq 0x24(%r14), %rdx
imulq %rax, %rdx
shlq $0x2, %rdx
addq 0x30(%r14), %rdx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movl 0x18(%rsp), %ebx
movl %ebx, %ecx
movl (%rsp), %r8d
callq 0xd138
movq 0x60(%rsp), %r15
incl %r15d
movl 0x20(%r14), %eax
cmpl %eax, %r15d
movl 0x14(%rsp), %ebp
jl 0xd3d8
movq 0x8(%rsp), %rdi
callq 0x43e0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xd4e2
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1caf8(%rip), %rdi     # 0x29ff0
leaq 0x117c1(%rip), %rsi     # 0x1ecc0
callq 0x42e0
movq %rax, %rdi
callq 0x4170
movl $0x1, %edi
callq 0x4380
jmp 0xd518
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xd532
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
movq %rbx, %rdi
callq 0x45b0