// File: /workspace/github_c_makefile_star2_O1/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 $0x138, %rsp            # imm = 0x138
leaq 0x159f(%rip), %rdi      # 0x3086
leaq 0x3622(%rip), %rbx      # 0x5110
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1030
callq 0x184f
leaq 0x1505(%rip), %rsi      # 0x3009
movq %rbx, %rdi
callq 0x10c0
movq %rax, %rbx
leaq 0x363a(%rip), %rdi      # 0x5150
leaq 0x158a(%rip), %rsi      # 0x30a7
callq 0x10c0
movq %rax, %r14
leaq 0x40(%rsp), %r15
movb $0x0, (%r15)
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x1090
movq %r15, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
testl %eax, %eax
je 0x1b77
movq %r14, %rdi
callq 0x10a0
movq %rbx, %rdi
callq 0x10a0
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $-0x1, %rax
movl $0x3e732f3c, %r13d      # imm = 0x3E732F3C
leaq 0x80(%rsp), %r15
leaq 0x40(%rsp), %r12
movabsq $0xa7c5ac471b47843, %rbp # imm = 0xA7C5AC471B47843
movq $0x0, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq %rax, 0x38(%rsp)
movl 0x40(%rsp), %eax
xorl %r13d, %eax
movzbl 0x44(%rsp), %ecx
orl %eax, %ecx
jne 0x1bff
movl $0xa, %edi
movq %r14, %rsi
callq 0x1100
movq %r15, %rdi
movq %r12, %rsi
callq 0x1090
movq %r12, %rdi
movq %rbx, %rsi
callq 0x128c
movq %rbx, %rdi
callq 0x1140
testl %eax, %eax
je 0x1bbb
jmp 0x1b55
movq 0x20(%rsp), %rcx
incq %rcx
movq %rcx, %rax
shrq $0x5, %rax
mulq %rbp
movq %rcx, %rbp
cmpl $0x2, 0x34bd(%rip)      # 0x50d8
jl 0x1c6d
shrq $0x7, %rdx
imulq $0x186a0, %rdx, %rax    # imm = 0x186A0
movq %rbp, %rcx
subq %rax, %rcx
jne 0x1c6d
movq %rbp, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
shrq $0x4, %rdx
leaq 0x145b(%rip), %rdi      # 0x30aa
movq %rdx, %rsi
movl $0xd, %edx
xorl %eax, %eax
callq 0x1030
movq 0x336b(%rip), %rax      # 0x4fd0
movq (%rax), %rdi
callq 0x10b0
movq %rbp, 0x20(%rsp)
movq %r12, %rdi
callq 0x137d
movl %eax, 0x14(%rsp)
movslq %eax, %rdx
movq 0x8(%rsp), %rax
cmpl $-0x1, %edx
je 0x1c9d
movq 0x34fe(%rip), %rax      # 0x5190
movq %rdx, %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
xorl %ebp, %ebp
leaq 0xc0(%rsp), %rdi
leaq 0x1385(%rip), %rsi      # 0x303d
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1050
movb $0x0, 0xfb(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x137d
cmpl $-0x1, %eax
je 0x1d0a
cmpl $-0x1, 0x14(%rsp)
setne %cl
cmpq $-0x1, 0x38(%rsp)
setne %bpl
cltq
movq 0x3496(%rip), %rdx      # 0x5190
shlq $0x4, %rax
movq (%rdx,%rax), %rax
movq %rax, 0x18(%rsp)
andb %cl, %bpl
movslq 0x33cb(%rip), %rax      # 0x50dc
xorps %xmm0, %xmm0
movq 0x28(%rsp), %rdx
cmpq %rax, %rdx
jl 0x1d61
cmpq %rax, 0x8(%rsp)
jl 0x1d61
testb %bpl, %bpl
je 0x1d61
movq 0x18(%rsp), %rcx
subq %rax, %rcx
cvtsi2ss %rcx, %xmm1
xorps %xmm0, %xmm0
cvtsi2ssq 0x8(%rsp), %xmm0
divss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
divss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2ssq 0x344b(%rip), %xmm0 # 0x51a8
mulss %xmm1, %xmm0
ucomiss 0x3388(%rip), %xmm0     # 0x50f0
leaq 0x1352(%rip), %rsi      # 0x30c1
leaq 0x12c9(%rip), %rax      # 0x303f
cmovaq %rax, %rsi
movl $0x0, %eax
cmovaq %rax, %rdx
movq %rdx, %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, 0x8(%rsp)
testl %eax, %eax
movabsq $0xa7c5ac471b47843, %rbp # imm = 0xA7C5AC471B47843
movq 0x30(%rsp), %rax
je 0x1bb6
jmp 0x1b55