// File: /workspace/github_cpp_makefile_star2_O3/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, 0x58(%rsp)
cmpl %esi, 0x4(%rdi)
jg 0xd648
movl %esi, %ebp
movq %rdi, %r14
movslq %esi, %rsi
leaq 0x74(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x38(%rsp), %rbx
leaq 0xb(%rsp), %rcx
movq %rbx, %rdi
callq 0xdafc
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rcx, %rax
je 0xd4c4
subq %rax, %rcx
addq $-0x4, %rcx
movq %rcx, %xmm0
shrq $0x2, %rcx
addq $0x4, %rcx
andq $-0x4, %rcx
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
psrlq $0x2, %xmm0
xorl %edx, %edx
movdqa 0x118cb(%rip), %xmm1    # 0x1ecc0
movdqa 0x118d3(%rip), %xmm2    # 0x1ecd0
movdqa 0x118db(%rip), %xmm3    # 0x1ece0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movq %rdx, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movdqa %xmm5, %xmm6
por %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0xd453
movl %edx, (%rax,%rdx,4)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0xd469
leal 0x1(%rdx), %esi
movl %esi, 0x4(%rax,%rdx,4)
por %xmm1, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
pxor %xmm4, %xmm5
pextrw $0x0, %xmm5, %esi
testb $0x1, %sil
je 0xd4a5
leal 0x2(%rdx), %esi
movl %esi, 0x8(%rax,%rdx,4)
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0xd4b7
leal 0x3(%rdx), %esi
movl %esi, 0xc(%rax,%rdx,4)
addq $0x4, %rdx
cmpq %rdx, %rcx
jne 0xd40d
movl 0xc(%r14), %eax
movl 0x24(%r14), %ecx
cmpl %ebp, %eax
movl %ebp, %ebx
movl %eax, 0x24(%rsp)
cmovll %eax, %ebx
movl %ebx, %eax
movl %ecx, 0x4(%rsp)
imull %ecx, %eax
cltq
leaq (,%rax,4), %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x4030
movq %rax, 0x10(%rsp)
movl 0x20(%r14), %eax
testl %eax, %eax
jle 0xd618
leaq 0x48(%r14), %rcx
movq %rcx, 0x50(%rsp)
movl %ebx, %ecx
xorl %r15d, %r15d
movl %ebp, 0x1c(%rsp)
movq %r14, 0x28(%rsp)
movl %ebx, 0x20(%rsp)
movq %rcx, 0x60(%rsp)
decl %eax
cmpl %eax, %r15d
jne 0xd53c
movl 0x28(%r14), %eax
movl %eax, 0x4(%rsp)
cmpl %ebp, 0x24(%rsp)
jge 0xd556
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0xdc78
movq %r15, 0x30(%rsp)
movl 0x24(%r14), %eax
movl %eax, 0xc(%rsp)
testl %ebx, %ebx
movq 0x60(%rsp), %r14
jle 0xd5ca
movq 0x38(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x28(%rsp), %rax
movslq 0x1c(%rax), %r12
movl 0xc(%rsp), %eax
imull 0x30(%rsp), %eax
cltq
movq 0x58(%rsp), %rcx
leaq (%rcx,%rax,4), %r15
movslq 0x4(%rsp), %rbx
shlq $0x2, %rbx
movq 0x10(%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 0xd5a3
movq 0x28(%rsp), %r14
movl 0x4(%r14), %eax
movq 0x30(%rsp), %r15
imull %r15d, %eax
imull 0xc(%rsp), %eax
movslq %eax, %rdx
shlq $0x2, %rdx
addq 0x30(%r14), %rdx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movl 0x20(%rsp), %ebx
movl %ebx, %ecx
movl 0x4(%rsp), %r8d
callq 0xd0b0
incl %r15d
movl 0x20(%r14), %eax
cmpl %eax, %r15d
movl 0x1c(%rsp), %ebp
jl 0xd52d
movq 0x10(%rsp), %rdi
callq 0x43e0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xd639
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1c9a1(%rip), %rdi     # 0x29ff0
leaq 0x1169a(%rip), %rsi     # 0x1ecf0
callq 0x42e0
movq %rax, %rdi
callq 0x4170
movl $0x1, %edi
callq 0x4380
jmp 0xd66f
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xd689
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
movq %rbx, %rdi
callq 0x45b0
nop