// File: /workspace/github_c_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
leaq 0x1570(%rip), %rdi      # 0x3086
leaq 0x35f3(%rip), %rbx      # 0x5110
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1030
callq 0x187e
leaq 0x14d6(%rip), %rsi      # 0x3009
movq %rbx, %rdi
callq 0x10c0
movq %rax, %rbx
leaq 0x360b(%rip), %rdi      # 0x5150
leaq 0x155b(%rip), %rsi      # 0x30a7
callq 0x10c0
movq %rax, %r14
leaq 0x20(%rsp), %r15
movb $0x0, (%r15)
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x1090
movq %r15, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
testl %eax, %eax
je 0x1ba3
movq %r14, %rdi
callq 0x10a0
movq %rbx, %rdi
callq 0x10a0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $-0x1, %r13
leaq 0x60(%rsp), %r15
leaq 0x20(%rsp), %r12
movabsq $0xa7c5ac471b47843, %rbp # imm = 0xA7C5AC471B47843
xorl %edx, %edx
movq $0x0, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movl 0x20(%rsp), %eax
movl $0x3e732f3c, %ecx       # imm = 0x3E732F3C
xorl %ecx, %eax
movzbl 0x24(%rsp), %ecx
orl %eax, %ecx
jne 0x1c1c
movl $0xa, %edi
movq %r14, %rsi
movq %rdx, %r13
callq 0x1100
movq %r15, %rdi
movq %r12, %rsi
callq 0x1090
movq %r12, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
movq %r13, %rdx
testl %eax, %eax
je 0x1bce
jmp 0x1b81
movq %rdx, 0x8(%rsp)
movq 0x10(%rsp), %rcx
incq %rcx
movq %rcx, %rax
shrq $0x5, %rax
mulq %rbp
movq %rcx, %rbp
cmpl $0x2, 0x349b(%rip)      # 0x50d8
jl 0x1c8f
shrq $0x7, %rdx
imulq $0x186a0, %rdx, %rax    # imm = 0x186A0
movq %rbp, %rcx
subq %rax, %rcx
jne 0x1c8f
movq %rbp, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
shrq $0x4, %rdx
leaq 0x1439(%rip), %rdi      # 0x30aa
movq %rdx, %rsi
movl $0xd, %edx
xorl %eax, %eax
callq 0x1030
movq 0x3349(%rip), %rax      # 0x4fd0
movq (%rax), %rdi
callq 0x10b0
movq %rbp, 0x10(%rsp)
movq %r12, %rdi
callq 0x137d
movl %eax, 0x4(%rsp)
movslq %eax, %r13
movq 0x8(%rsp), %rbp
cmpl $-0x1, %r13d
je 0x1cc0
movq 0x34db(%rip), %rax      # 0x5190
movq %r13, %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rbp
leaq 0xa0(%rsp), %rdi
leaq 0x136e(%rip), %rsi      # 0x303d
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1050
movb $0x0, 0xdb(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x137d
xorps %xmm0, %xmm0
cmpl $-0x1, %eax
je 0x1d71
cmpl $-0x1, 0x4(%rsp)
sete %dl
cmpq $-0x1, 0x18(%rsp)
sete %sil
movslq 0x33ca(%rip), %rcx      # 0x50dc
movq 0x8(%rsp), %r9
cmpq %rcx, %r9
setl %dil
cmpq %rcx, %rbp
setl %r8b
orb %dil, %r8b
orb %dl, %sil
orb %r8b, %sil
jne 0x1d71
movq 0x3459(%rip), %rdx      # 0x5190
cltq
shlq $0x4, %rax
movq (%rdx,%rax), %rax
subq %rcx, %rax
cvtsi2ss %rax, %xmm1
xorps %xmm0, %xmm0
cvtsi2ss %r9, %xmm0
divss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2ss %rbp, %xmm0
divss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2ssq 0x343b(%rip), %xmm0 # 0x51a8
mulss %xmm1, %xmm0
ucomiss 0x3378(%rip), %xmm0     # 0x50f0
leaq 0x1342(%rip), %rsi      # 0x30c1
leaq 0x12b9(%rip), %rax      # 0x303f
cmovaq %rax, %rsi
movl $0x0, %eax
cmovaq %rax, %rbp
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1120
movq %r15, %rdi
movq %r12, %rsi
callq 0x1090
movq %r12, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
movq %rbp, %rdx
testl %eax, %eax
movabsq $0xa7c5ac471b47843, %rbp # imm = 0xA7C5AC471B47843
je 0x1bc9
jmp 0x1b81