// File: /workspace/github_c_makefile_star2_O0/stanfordnlp[P]GloVe/src/vocab_count.c
// Function: get_counts
int get_counts(void) {
    long long i = 0, j = 0, vocab_size = 12500;
    // char format[20];
    char str[MAX_STRING_LENGTH + 1];
    HASHREC **vocab_hash = inithashtable();
    HASHREC *htmp;
    VOCAB *vocab;
    FILE *fid = stdin;
    
    fprintf(stderr, "BUILDING VOCABULARY\n");
    if (verbose > 1) fprintf(stderr, "Processed %lld tokens.", i);
    // sprintf(format,"%%%ds",MAX_STRING_LENGTH);
    while ( ! feof(fid)) {
        // Insert all tokens into hashtable
        int nl = get_word(str, fid);
        if (nl) continue; // just a newline marker or feof
        if (strcmp(str, "<unk>") == 0) {
            fprintf(stderr, "\nError, <unk> vector found in corpus.\nPlease remove <unk>s from your corpus (e.g. cat text8 | sed -e 's/<unk>/<raw_unk>/g' > text8.new)");
            free_table(vocab_hash);
            return 1;
        }
        hashinsert(vocab_hash, str);
        if (((++i)%100000) == 0) if (verbose > 1) fprintf(stderr,"\033[11G%lld tokens.", i);
    }
    if (verbose > 1) fprintf(stderr, "\033[0GProcessed %lld tokens.\n", i);
    vocab = malloc(sizeof(VOCAB) * vocab_size);
    for (i = 0; i < TSIZE; i++) { // Migrate vocab to array
        htmp = vocab_hash[i];
        while (htmp != NULL) {
            vocab[j].word = htmp->word;
            vocab[j].count = htmp->num;
            j++;
            if (j>=vocab_size) {
                vocab_size += 2500;
                vocab = (VOCAB *)realloc(vocab, sizeof(VOCAB) * vocab_size);
            }
            htmp = htmp->next;
        }
    }
    if (verbose > 1) fprintf(stderr, "Counted %lld unique words.\n", j);
    if (max_vocab > 0 && max_vocab < j)
        // If the vocabulary exceeds limit, first sort full vocab by frequency without alphabetical tie-breaks.
        // This results in pseudo-random ordering for words with same frequency, so that when truncated, the words span whole alphabet
        qsort(vocab, j, sizeof(VOCAB), CompareVocab);
    else max_vocab = j;
    qsort(vocab, max_vocab, sizeof(VOCAB), CompareVocabTie); //After (possibly) truncating, sort (possibly again), breaking ties alphabetically
    
    for (i = 0; i < max_vocab; i++) {
        if (vocab[i].count < min_count) { // If a minimum frequency cutoff exists, truncate vocabulary
            if (verbose > 0) fprintf(stderr, "Truncating vocabulary at min count %lld.\n",min_count);
            break;
        }
        printf("%s %lld\n",vocab[i].word,vocab[i].count);
    }
    
    if (i == max_vocab && max_vocab < j) if (verbose > 0) fprintf(stderr, "Truncating vocabulary at size %lld.\n", max_vocab);
    fprintf(stderr, "Using vocabulary of size %lld.\n\n", i);
    free_table(vocab_hash);
    free(vocab);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x30d4, -0x20(%rbp)    # imm = 0x30D4
callq 0x1b50
movq %rax, -0x418(%rbp)
movq 0x2b32(%rip), %rax      # 0x3fd8
movq (%rax), %rax
movq %rax, -0x430(%rbp)
movq 0x2b41(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xb43(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x10e0
cmpl $0x1, 0x2be9(%rip)      # 0x40b8
jle 0x14ed
movq 0x2b20(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xb33(%rip), %rsi       # 0x2019
movb $0x0, %al
callq 0x10e0
jmp 0x14ef
movq -0x430(%rbp), %rdi
callq 0x10f0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x150c
jmp 0x15d3
leaq -0x410(%rbp), %rdi
movq -0x430(%rbp), %rsi
callq 0x1ba0
movl %eax, -0x434(%rbp)
cmpl $0x0, -0x434(%rbp)
je 0x1530
jmp 0x14ef
leaq -0x410(%rbp), %rdi
leaq 0xaf2(%rip), %rsi       # 0x2030
callq 0x10d0
cmpl $0x0, %eax
jne 0x1578
movq 0x2aa9(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xadd(%rip), %rsi       # 0x2036
movb $0x0, %al
callq 0x10e0
movq -0x418(%rbp), %rdi
callq 0x1de0
movl $0x1, -0x4(%rbp)
jmp 0x189e
movq -0x418(%rbp), %rdi
leaq -0x410(%rbp), %rsi
callq 0x1310
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl $0x186a0, %ecx          # imm = 0x186A0
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x15ce
cmpl $0x1, 0x2b0a(%rip)      # 0x40b8
jle 0x15cc
movq 0x2a41(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xaf9(%rip), %rsi       # 0x20be
movb $0x0, %al
callq 0x10e0
jmp 0x15ce
jmp 0x14ef
cmpl $0x1, 0x2ade(%rip)      # 0x40b8
jle 0x15f8
movq 0x2a15(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xadf(%rip), %rsi       # 0x20d0
movb $0x0, %al
callq 0x10e0
movq -0x20(%rbp), %rdi
shlq $0x4, %rdi
callq 0x1100
movq %rax, -0x428(%rbp)
movq $0x0, -0x10(%rbp)
cmpq $0x100000, -0x10(%rbp)  # imm = 0x100000
jge 0x16ef
movq -0x418(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x420(%rbp)
cmpq $0x0, -0x420(%rbp)
je 0x16dc
movq -0x420(%rbp), %rax
movq (%rax), %rcx
movq -0x428(%rbp), %rax
movq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x420(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x428(%rbp), %rax
movq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0x16c5
movq -0x20(%rbp), %rax
addq $0x9c4, %rax            # imm = 0x9C4
movq %rax, -0x20(%rbp)
movq -0x428(%rbp), %rdi
movq -0x20(%rbp), %rsi
shlq $0x4, %rsi
callq 0x1120
movq %rax, -0x428(%rbp)
movq -0x420(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x420(%rbp)
jmp 0x1638
jmp 0x16de
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x1614
cmpl $0x1, 0x29c2(%rip)      # 0x40b8
jle 0x1714
movq 0x28f9(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x9df(%rip), %rsi       # 0x20ec
movb $0x0, %al
callq 0x10e0
cmpq $0x0, 0x29b4(%rip)      # 0x40d0
jle 0x1749
movq 0x29ab(%rip), %rax      # 0x40d0
cmpq -0x18(%rbp), %rax
jge 0x1749
movq -0x428(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x10, %edx
leaq -0x482(%rip), %rcx      # 0x12c0
callq 0x1060
jmp 0x1754
movq -0x18(%rbp), %rax
movq %rax, 0x297c(%rip)      # 0x40d0
movq -0x428(%rbp), %rdi
movq 0x296e(%rip), %rsi      # 0x40d0
movl $0x10, %edx
leaq -0x51e(%rip), %rcx      # 0x1250
callq 0x1060
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq 0x294a(%rip), %rax      # 0x40d0
jge 0x181f
movq -0x428(%rbp), %rax
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
cmpq 0x2917(%rip), %rax      # 0x40c0
jge 0x17d5
cmpl $0x0, 0x2906(%rip)      # 0x40b8
jle 0x17d3
movq 0x283d(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq 0x28fb(%rip), %rdx      # 0x40c0
leaq 0x93c(%rip), %rsi       # 0x2108
movb $0x0, %al
callq 0x10e0
jmp 0x181f
movq -0x428(%rbp), %rax
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movq -0x428(%rbp), %rax
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
leaq 0x92b(%rip), %rdi       # 0x2132
movb $0x0, %al
callq 0x10a0
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x177b
movq -0x10(%rbp), %rax
cmpq 0x28a6(%rip), %rax      # 0x40d0
jne 0x1863
movq 0x289d(%rip), %rax      # 0x40d0
cmpq -0x18(%rbp), %rax
jge 0x1863
cmpl $0x0, 0x2878(%rip)      # 0x40b8
jle 0x1861
movq 0x27af(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq 0x287d(%rip), %rdx      # 0x40d0
leaq 0x8e1(%rip), %rsi       # 0x213b
movb $0x0, %al
callq 0x10e0
jmp 0x1863
movq 0x278e(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x8e8(%rip), %rsi       # 0x2160
movb $0x0, %al
callq 0x10e0
movq -0x418(%rbp), %rdi
callq 0x1de0
movq -0x428(%rbp), %rdi
callq 0x1030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
nopw (%rax,%rax)