// File: /workspace/github_c_makefile_star2_O2/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 0x2afc(%rip), %rax      # 0x4198
xorl %ecx, %ecx
cmpq $0x1dcd6500, %rcx       # imm = 0x1DCD6500
je 0x16b0
orl $-0x1, (%rax,%rcx,4)
incq %rcx
jmp 0x169e
leaq 0x2a59(%rip), %rdi      # 0x4110
leaq 0x94b(%rip), %rsi       # 0x2009
callq 0x10c0
testq %rax, %rax
je 0x18a5
movq %rax, %rbx
andq $0x0, 0x2ac9(%rip)      # 0x41a0
leaq 0x926(%rip), %r14       # 0x2004
movq %r14, %rdi
callq 0x13e5
leaq 0xc0(%rsp), %r15
pushq $0x5
popq %r12
movq %rsp, %rbp
leaq 0x80(%rsp), %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
testl %eax, %eax
jne 0x1853
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x10a0
testl %eax, %eax
je 0x16fd
movq 0x2a77(%rip), %rcx      # 0x41a8
incq %rcx
movq %rcx, 0x2a6d(%rip)      # 0x41a8
movl 0x2997(%rip), %esi      # 0x40d8
movq %rcx, %rax
cqto
movl $0x186a0, %edi          # imm = 0x186A0
idivq %rdi
cmpl $0x2, %esi
jl 0x1797
testq %rdx, %rdx
jne 0x1797
movq %rcx, %rax
cqto
movl $0x3e8, %ecx            # imm = 0x3E8
idivq %rcx
movq %rax, %rsi
movq 0x2a31(%rip), %rax      # 0x41a0
cqto
idivq %rcx
leaq 0x891(%rip), %rdi       # 0x200c
movq %rax, %rdx
pushq $0xd
popq %rcx
xorl %eax, %eax
callq 0x1030
movq 0x2841(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x10b0
movq %r15, %rdi
callq 0x1349
cmpl $-0x1, %eax
je 0x17b7
cltq
movq 0x29e3(%rip), %rcx      # 0x4190
shlq $0x4, %rax
incq (%rcx,%rax)
jmp 0x17d4
movq %r15, %rdi
callq 0x13e5
cltq
movq 0x29c8(%rip), %rcx      # 0x4190
shlq $0x4, %rax
movq $0x1, (%rcx,%rax)
movq %rbp, %rdi
leaq 0x85f(%rip), %rsi       # 0x203d
movq %r13, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x1050
movb $0x0, 0x3b(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x1080
movq %rbp, %rdi
callq 0x1349
cmpl $-0x1, %eax
je 0x181b
cltq
movq 0x297f(%rip), %rcx      # 0x4190
shlq $0x4, %rax
incq (%rcx,%rax)
jmp 0x1838
movq %rbp, %rdi
callq 0x13e5
cltq
movq 0x2964(%rip), %rcx      # 0x4190
shlq $0x4, %rax
movq $0x1, (%rcx,%rax)
cmpq $0x14dc9381, 0x295d(%rip) # imm = 0x14DC9381
jl 0x16fd
callq 0x1597
jmp 0x16fd
callq 0x14bc
cmpl $0x0, 0x2879(%rip)      # 0x40d8
jle 0x188b
movq 0x2938(%rip), %rsi      # 0x41a0
leaq 0x7d4(%rip), %rdi       # 0x2043
xorl %eax, %eax
callq 0x1030
movq 0x292b(%rip), %rsi      # 0x41a8
leaq 0x7e7(%rip), %rdi       # 0x206b
xorl %eax, %eax
callq 0x1030
movq %rbx, %rdi
callq 0x1090
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x85e(%rip), %rdi       # 0x210a
callq 0x1130
pushq $0x1
popq %rdi
callq 0x10e0