// File: /workspace/github_c_makefile_star2_O3/Leeheng86[P]word2vec/word2phrase.c
// Function: LearnVocabFromTrainFile()
void LearnVocabFromTrainFile() {
  char word[MAX_STRING], last_word[MAX_STRING], bigram_word[MAX_STRING * 2];
  FILE *fin;
  long long a, i, start = 1;
  for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1;
  fin = fopen(train_file, "rb");
  if (fin == NULL) {
    printf("ERROR: training data file not found!\n");
    exit(1);
  }
  vocab_size = 0;
  AddWordToVocab((char *)"
");
  while (1) {
    ReadWord(word, fin);
    if (feof(fin)) break;
    if (!strcmp(word, "
")) {
      start = 1;
      continue;
    } else start = 0;
    train_words++;
    if ((debug_mode > 1) && (train_words % 100000 == 0)) {
      printf("Words processed: %lldK     Vocab size: %lldK  %c", train_words / 1000, vocab_size / 1000, 13);
      fflush(stdout);
    }
    i = SearchVocab(word);
    if (i == -1) {
      a = AddWordToVocab(word);
      vocab[a].cn = 1;
    } else vocab[i].cn++;
    if (start) continue;
    sprintf(bigram_word, "%s_%s", last_word, word);
    bigram_word[MAX_STRING - 1] = 0;
    strcpy(last_word, word);
    i = SearchVocab(bigram_word);
    if (i == -1) {
      a = AddWordToVocab(bigram_word);
      vocab[a].cn = 1;
    } else vocab[i].cn++;
    if (vocab_size > vocab_hash_size * 0.7) ReduceVocab();
  }
  SortVocab();
  if (debug_mode > 0) {
    printf("\nVocab size (unigrams + bigrams): %lld\n", vocab_size);
    printf("Words in train file: %lld\n", train_words);
  }
  fclose(fin);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq 0x3902(%rip), %rdi      # 0x5198
movl $0x77359400, %edx       # imm = 0x77359400
movl $0xff, %esi
callq 0x1070
leaq 0x3864(%rip), %rdi      # 0x5110
leaq 0x1756(%rip), %rsi      # 0x3009
callq 0x10c0
testq %rax, %rax
je 0x1ae8
movq %rax, %rbx
movq $0x0, 0x38d1(%rip) # 0x51a0
leaq 0x172e(%rip), %rdi      # 0x3004
callq 0x1476
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
testl %eax, %eax
jne 0x1a96
movl $0x3e732f3c, %r15d      # imm = 0x3E732F3C
movq %rsp, %r14
leaq 0x1737(%rip), %r13      # 0x303d
leaq 0x40(%rsp), %rbp
leaq 0xc0(%rsp), %r12
movl (%rsp), %eax
xorl %r15d, %eax
movzbl 0x4(%rsp), %ecx
orl %eax, %ecx
je 0x1a7b
movq 0x387b(%rip), %rsi      # 0x51a8
leaq 0x1(%rsi), %rcx
movq %rcx, %rax
movabsq $0x29f16b11c6d1e109, %rdx # imm = 0x29F16B11C6D1E109
imulq %rdx
movq %rcx, 0x3860(%rip)      # 0x51a8
cmpl $0x2, 0x3789(%rip)      # 0x50d8
jl 0x19cc
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xe, %rdx
addq %rax, %rdx
imulq $0x186a0, %rdx, %rax    # imm = 0x186A0
negq %rax
addq %rsi, %rax
incq %rax
testq %rax, %rax
jne 0x19cc
movq %rcx, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq %rcx, %rax
imulq 0x3804(%rip)            # 0x51a0
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
leaq 0x165b(%rip), %rdi      # 0x300c
movl $0xd, %ecx
xorl %eax, %eax
callq 0x1030
movq 0x360c(%rip), %rax      # 0x4fd0
movq (%rax), %rdi
callq 0x10b0
movq %r14, %rdi
callq 0x137d
cmpl $-0x1, %eax
je 0x19ec
cltq
movq 0x37ae(%rip), %rcx      # 0x5190
shlq $0x4, %rax
incq (%rcx,%rax)
jmp 0x1a09
movq %r14, %rdi
callq 0x1476
cltq
movq 0x3793(%rip), %rcx      # 0x5190
shlq $0x4, %rax
movq $0x1, (%rcx,%rax)
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1050
movb $0x0, 0x7b(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
movq %rbp, %rdi
callq 0x137d
cmpl $-0x1, %eax
je 0x1a4c
cltq
movq 0x374e(%rip), %rcx      # 0x5190
shlq $0x4, %rax
incq (%rcx,%rax)
jmp 0x1a69
movq %rbp, %rdi
callq 0x1476
cltq
movq 0x3733(%rip), %rcx      # 0x5190
shlq $0x4, %rax
movq $0x1, (%rcx,%rax)
cmpq $0x14dc9381, 0x372c(%rip) # imm = 0x14DC9381
jl 0x1a7b
callq 0x16f8
movq %r14, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
testl %eax, %eax
je 0x1913
callq 0x15a6
cmpl $0x0, 0x3636(%rip)      # 0x50d8
jle 0x1ace
movq 0x36f5(%rip), %rsi      # 0x51a0
leaq 0x1591(%rip), %rdi      # 0x3043
xorl %eax, %eax
callq 0x1030
movq 0x36e8(%rip), %rsi      # 0x51a8
leaq 0x15a4(%rip), %rdi      # 0x306b
xorl %eax, %eax
callq 0x1030
movq %rbx, %rdi
callq 0x10a0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x161b(%rip), %rdi      # 0x310a
callq 0x1130
movl $0x1, %edi
callq 0x10e0