// File: /workspace/github_c_makefile_star2_O3/Leeheng86[P]word2vec/word2vec.c
// Function: SortVocab()
void SortVocab() {
  int a, size;
  unsigned int hash;
  // Sort the vocabulary and keep 
 at the first position
  qsort(&vocab[1], vocab_size - 1, sizeof(struct vocab_word), VocabCompare);
  for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1;
  size = vocab_size;
  train_words = 0;
  for (a = 0; a < size; a++) {
    // Words occuring less than min_count times will be discarded from the vocab
    if ((vocab[a].cn < min_count) && (a != 0)) {
      vocab_size--;
      free(vocab[a].word);
    } else {
      // Hash will be re-computed, as after the sorting it is not actual
      hash=GetWordHash(vocab[a].word);
      while (vocab_hash[hash] != -1) hash = (hash + 1) % vocab_hash_size;
      vocab_hash[hash] = a;
      train_words += vocab[a].cn;
    }
  }
  vocab = (struct vocab_word *)realloc(vocab, (vocab_size + 1) * sizeof(struct vocab_word));
  // Allocate memory for the binary tree construction
  for (a = 0; a < vocab_size; a++) {
    vocab[a].code = (char *)calloc(MAX_CODE_LENGTH, sizeof(char));
    vocab[a].point = (int *)calloc(MAX_CODE_LENGTH, sizeof(int));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x898b(%rip), %rdi      # 0xb478
addq $0x28, %rdi
movq 0x8998(%rip), %rsi      # 0xb490
decq %rsi
leaq -0x2c(%rip), %rcx       # 0x2ad6
movl $0x28, %edx
callq 0x2450
movq 0x8975(%rip), %rdi      # 0xb488
movl $0x7270e00, %edx        # imm = 0x7270E00
movl $0xff, %esi
callq 0x2150
movq 0x8967(%rip), %r15      # 0xb490
movq $0x0, 0x8964(%rip) # 0xb498
movq 0x893d(%rip), %rbx      # 0xb478
testl %r15d, %r15d
jle 0x2c20
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r12d, %r12d
xorl %ebp, %ebp
leaq (,%rbp,4), %rax
addq %rbp, %rax
movq (%rbx,%rax,8), %r13
testq %rbp, %rbp
je 0x2b8d
movslq 0x86f9(%rip), %rcx      # 0xb264
cmpq %rcx, %r13
jge 0x2b8d
decq 0x8919(%rip)            # 0xb490
movq 0x10(%rbx,%rax,8), %rdi
callq 0x22b0
movq 0x88f0(%rip), %rbx      # 0xb478
jmp 0x2c0d
leaq (%rbx,%rax,8), %rax
movq 0x10(%rax), %r14
movq %r14, %rdi
callq 0x2110
xorl %ecx, %ecx
testq %rax, %rax
je 0x2be0
xorl %edx, %edx
movq %rcx, %rsi
shlq $0x8, %rsi
addq %rcx, %rsi
movsbq (%r14,%rdx), %rcx
addq %rsi, %rcx
incq %rdx
cmpq %rdx, %rax
jne 0x2ba6
movq %rcx, %rax
shrq $0x7, %rax
movabsq $0x23ca98ce50e9b5d, %rdx # imm = 0x23CA98CE50E9B5D
mulq %rdx
shrq $0xb, %rdx
imull $0x1c9c380, %edx, %eax  # imm = 0x1C9C380
subl %eax, %ecx
movq 0x88a1(%rip), %rax      # 0xb488
movl %ecx, %edx
cmpl $-0x1, (%rax,%rdx,4)
je 0x2c03
movl %ecx, %edx
incl %edx
cmpl $0x1c9c380, %edx        # imm = 0x1C9C380
cmovel %r12d, %edx
cmpl $-0x1, (%rax,%rdx,4)
jne 0x2bf1
movl %ebp, (%rax,%rdx,4)
addq %r13, 0x888b(%rip)      # 0xb498
incq %rbp
cmpq %r15, %rbp
jne 0x2b50
movq 0x8870(%rip), %r15      # 0xb490
leaq (%r15,%r15,4), %rax
leaq 0x28(,%rax,8), %rsi
movq %rbx, %rdi
callq 0x23c0
movq %rax, 0x883d(%rip)      # 0xb478
movq 0x884e(%rip), %rbx      # 0xb490
testq %rbx, %rbx
jle 0x2c89
xorl %r14d, %r14d
movl $0x28, %edi
movl $0x1, %esi
callq 0x2160
movq 0x8818(%rip), %rcx      # 0xb478
movq %rax, 0x18(%rcx,%r14)
movl $0x28, %edi
movl $0x4, %esi
callq 0x2160
movq 0x87fd(%rip), %rcx      # 0xb478
movq %rax, 0x8(%rcx,%r14)
addq $0x28, %r14
decq %rbx
jne 0x2c4a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq