// File: /workspace/github_cpp_makefile_star2_O3/epfml[P]Bi-Sent2Vec/src/productquantizer.cc
// Function: fasttext::ProductQuantizer::kmeans(float const*, float*, int, int)
void ProductQuantizer::kmeans(const real *x, real* c, int32_t n, int32_t d) {
  std::vector<int32_t> perm(n,0);
  std::iota(perm.begin(), perm.end(), 0);
  std::shuffle(perm.begin(), perm.end(), rng);
  for (auto i = 0; i < ksub_; i++) {
    memcpy (&c[i * d], x + perm[i] * d, d * sizeof(real));
  }
  uint8_t* codes = new uint8_t[n];
  for (auto i = 0; i < niter_; i++) {
    Estep(x, c, codes, d, n);
    MStep(x, c, codes, d, n);
  }
  delete [] codes;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, %ebp
movq %rdx, 0x38(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
movl %ecx, 0x8(%rsp)
movslq %ecx, %rsi
leaq 0x64(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x48(%rsp), %r14
leaq 0xf(%rsp), %rcx
movq %r14, %rdi
movq %rsi, 0x28(%rsp)
callq 0xdafc
movq (%r14), %rdi
movq 0x8(%r14), %rsi
cmpq %rsi, %rdi
je 0xd201
movq %rsi, %rax
subq %rdi, %rax
addq $-0x4, %rax
movq %rax, %xmm0
shrq $0x2, %rax
addq $0x4, %rax
andq $-0x4, %rax
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
psrlq $0x2, %xmm0
xorl %ecx, %ecx
movdqa 0x11b8a(%rip), %xmm1    # 0x1ecc0
movdqa 0x11b92(%rip), %xmm2    # 0x1ecd0
movdqa 0x11b9a(%rip), %xmm3    # 0x1ece0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movq %rcx, %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, %edx
notl %edx
testb $0x1, %dl
je 0xd193
movl %ecx, (%rdi,%rcx,4)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0xd1a8
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rdi,%rcx,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, %edx
testb $0x1, %dl
je 0xd1e3
leal 0x2(%rcx), %edx
movl %edx, 0x8(%rdi,%rcx,4)
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0xd1f4
leal 0x3(%rcx), %edx
movl %edx, 0xc(%rdi,%rcx,4)
addq $0x4, %rcx
cmpq %rcx, %rax
jne 0xd14e
leaq 0x48(%rbx), %rdx
callq 0xdc78
cmpl $0x0, 0x4(%rbx)
movl %ebp, 0x34(%rsp)
movslq %ebp, %rbp
movq 0x20(%rsp), %r12
movq %rbx, %r15
jle 0xd263
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq (,%rbp,4), %r13
xorl %ebx, %ebx
movq 0x38(%rsp), %r14
movq 0x10(%rsp), %rax
movslq (%rax,%rbx,4), %rax
imulq %rbp, %rax
leaq (%r12,%rax,4), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x4260
incq %rbx
movslq 0x4(%r15), %rax
addq %r13, %r14
cmpq %rax, %rbx
jl 0xd238
movq %rbp, 0x10(%rsp)
movq 0x28(%rsp), %rdi
callq 0x4030
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x14(%r15)
movl 0x34(%rsp), %ebx
jle 0xd321
movl 0x8(%rsp), %ecx
movq %rcx, 0x40(%rsp)
shlq $0x2, 0x10(%rsp)
xorl %ecx, %ecx
movq 0x38(%rsp), %r12
movl %ecx, 0x28(%rsp)
cmpl $0x0, 0x8(%rsp)
movl %ebx, %eax
movq 0x10(%rsp), %rcx
jle 0xd2f2
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r13
movq 0x40(%rsp), %rbp
movq %rcx, 0x10(%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r15, %rbx
movl %eax, %r15d
movl %eax, %r8d
callq 0xcd2c
movq 0x10(%rsp), %rcx
movl %r15d, %eax
movq %rbx, %r15
incq %r13
addq %rcx, %r14
decq %rbp
jne 0xd2c2
movq %r15, %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
movl %eax, %ebx
movl %eax, %r8d
movl 0x8(%rsp), %r9d
callq 0xce14
movl 0x28(%rsp), %ecx
incl %ecx
cmpl 0x14(%r15), %ecx
jl 0xd29c
movq 0x18(%rsp), %rdi
callq 0x43e0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xd342
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd355
jmp 0xd355
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xd36f
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x4300
movq %rbx, %rdi
callq 0x45b0
nop