// File: /workspace/github_c_makefile_star2_O2/Leeheng86[P]word2vec/word2phrase.c
// Function: TrainModel()
void TrainModel() {
  long long pa = 0, pb = 0, pab = 0, oov, i, li = -1, cn = 0;
  char word[MAX_STRING], last_word[MAX_STRING], bigram_word[MAX_STRING * 2];
  real score;
  FILE *fo, *fin;
  printf("Starting training using file %s\n", train_file);
  LearnVocabFromTrainFile();
  fin = fopen(train_file, "rb");
  fo = fopen(output_file, "wb");
  word[0] = 0;
  while (1) {
    strcpy(last_word, word);
    ReadWord(word, fin);
    if (feof(fin)) break;
    if (!strcmp(word, "
")) {
      fprintf(fo, "\n");
      continue;
    }
    cn++;
    if ((debug_mode > 1) && (cn % 100000 == 0)) {
      printf("Words written: %lldK%c", cn / 1000, 13);
      fflush(stdout);
    }
    oov = 0;
    i = SearchVocab(word);
    if (i == -1) oov = 1; else pb = vocab[i].cn;
    if (li == -1) oov = 1;
    li = i;
    sprintf(bigram_word, "%s_%s", last_word, word);
    bigram_word[MAX_STRING - 1] = 0;
    i = SearchVocab(bigram_word);
    if (i == -1) oov = 1; else pab = vocab[i].cn;
    if (pa < min_count) oov = 1;
    if (pb < min_count) oov = 1;
    if (oov) score = 0; else score = (pab - min_count) / (real)pa / (real)pb * (real)train_words;
    if (score > threshold) {
      fprintf(fo, "_%s", word);
      pb = 0;
    } else fprintf(fo, " %s", word);
    pa = pb;
  }
  fclose(fo);
  fclose(fin);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
leaq 0x7b5(%rip), %rdi       # 0x2086
leaq 0x2838(%rip), %rbx      # 0x4110
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1030
callq 0x1684
leaq 0x71b(%rip), %rsi       # 0x2009
movq %rbx, %rdi
callq 0x10c0
movq %rax, %rbx
leaq 0x2850(%rip), %rdi      # 0x4150
leaq 0x7a0(%rip), %rsi       # 0x20a7
callq 0x10c0
movq %rax, %r14
leaq 0x100(%rsp), %r15
movb $0x0, (%r15)
pushq $-0x1
popq %rax
leaq 0xc0(%rsp), %r12
leaq 0x6d7(%rip), %r13       # 0x2004
pushq $0x5
popq %rbp
movq $0x0, 0x28(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x38(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x1080
movq %r15, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
testl %eax, %eax
jne 0x1b1f
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x10a0
testl %eax, %eax
jne 0x1995
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x1100
jmp 0x1950
movq 0x10(%rsp), %rax
incq %rax
movl 0x2735(%rip), %ecx      # 0x40d8
movq %rax, 0x10(%rsp)
xorl %edx, %edx
movl $0x186a0, %esi          # imm = 0x186A0
divq %rsi
cmpl $0x2, %ecx
jl 0x19ee
testq %rdx, %rdx
jne 0x19ee
movq 0x10(%rsp), %rax
xorl %edx, %edx
movl $0x3e8, %ecx            # imm = 0x3E8
divq %rcx
leaq 0x6d8(%rip), %rdi       # 0x20aa
movq %rax, %rsi
pushq $0xd
popq %rdx
xorl %eax, %eax
callq 0x1030
movq 0x25ea(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x10b0
movq %r15, %rdi
callq 0x1349
movl %eax, 0x24(%rsp)
movslq %eax, %rdx
movq 0x8(%rsp), %rax
cmpl $-0x1, %edx
je 0x1a19
movq 0x2782(%rip), %rax      # 0x4190
movq %rdx, %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x18(%rsp)
movq %rdx, 0x30(%rsp)
movl $0x0, 0x4(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x606(%rip), %rsi       # 0x203d
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x1050
movb $0x0, 0x7b(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x1349
cmpl $-0x1, %eax
je 0x1a87
cmpl $-0x1, 0x24(%rsp)
setne %cl
cmpq $-0x1, 0x38(%rsp)
setne %sil
cltq
movq 0x271d(%rip), %rdx      # 0x4190
shlq $0x4, %rax
movq (%rdx,%rax), %rax
movq %rax, 0x28(%rsp)
andb %cl, %sil
movl %esi, 0x4(%rsp)
movslq 0x264e(%rip), %rax      # 0x40dc
xorps %xmm0, %xmm0
movq 0x18(%rsp), %rdx
cmpq %rax, %rdx
jl 0x1ad7
cmpq %rax, 0x8(%rsp)
jl 0x1ad7
cmpb $0x0, 0x4(%rsp)
je 0x1ad7
movq 0x28(%rsp), %rcx
subq %rax, %rcx
cvtsi2ss %rcx, %xmm1
cvtsi2ssq 0x8(%rsp), %xmm0
divss %xmm0, %xmm1
cvtsi2ss %rdx, %xmm0
divss %xmm0, %xmm1
cvtsi2ssq 0x26d5(%rip), %xmm0 # 0x41a8
mulss %xmm1, %xmm0
ucomiss 0x2612(%rip), %xmm0     # 0x40f0
leaq 0x5dc(%rip), %rsi       # 0x20c1
leaq 0x553(%rip), %rax       # 0x203f
cmovaq %rax, %rsi
movl $0x0, %eax
cmovaq %rax, %rdx
movq %rdx, 0x18(%rsp)
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1120
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rax
jmp 0x194b
movq %r14, %rdi
callq 0x1090
movq %rbx, %rdi
callq 0x1090
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq