// File: /workspace/github_c_makefile_star2_O0/stanfordnlp[P]GloVe/src/cooccur.c
// Function: main
int main(int argc, char **argv) {
    int i;
    real rlimit, n = 1e5;
    vocab_file = malloc(sizeof(char) * MAX_STRING_LENGTH);
    file_head = malloc(sizeof(char) * MAX_STRING_LENGTH);
    
    if (argc == 1) {
        printf("Tool to calculate word-word cooccurrence statistics\n");
        printf("Author: Jeffrey Pennington (jpennin@stanford.edu)\n\n");
        printf("Usage options:\n");
        printf("\t-verbose <int>\n");
        printf("\t\tSet verbosity: 0, 1, 2 (default), or 3\n");
        printf("\t-symmetric <int>\n");
        printf("\t\tIf <int> = 0, only use left context; if <int> = 1 (default), use left and right\n");
        printf("\t-window-size <int>\n");
        printf("\t\tNumber of context words to the left (and to the right, if symmetric = 1); default 15\n");
        printf("\t-vocab-file <file>\n");
        printf("\t\tFile containing vocabulary (truncated unigram counts, produced by 'vocab_count'); default vocab.txt\n");
        printf("\t-memory <float>\n");
        printf("\t\tSoft limit for memory consumption, in GB -- based on simple heuristic, so not extremely accurate; default 4.0\n");
        printf("\t-max-product <int>\n");
        printf("\t\tLimit the size of dense cooccurrence array by specifying the max product <int> of the frequency counts of the two cooccurring words.\n\t\tThis value overrides that which is automatically produced by '-memory'. Typically only needs adjustment for use with very large corpora.\n");
        printf("\t-overflow-length <int>\n");
        printf("\t\tLimit to length <int> the sparse overflow array, which buffers cooccurrence data that does not fit in the dense array, before writing to disk. \n\t\tThis value overrides that which is automatically produced by '-memory'. Typically only needs adjustment for use with very large corpora.\n");
        printf("\t-overflow-file <file>\n");
        printf("\t\tFilename, excluding extension, for temporary files; default overflow\n");
        printf("\t-distance-weighting <int>\n");
        printf("\t\tIf <int> = 0, do not weight cooccurrence count by distance between words; if <int> = 1 (default), weight the cooccurrence count by inverse of distance between words\n");

        printf("\nExample usage:\n");
        printf("./cooccur -verbose 2 -symmetric 0 -window-size 10 -vocab-file vocab.txt -memory 8.0 -overflow-file tempoverflow < corpus.txt > cooccurrences.bin\n\n");
        free(vocab_file);
        free(file_head);
        return 0;
    }

    if ((i = find_arg((char *)"-verbose", argc, argv)) > 0) verbose = atoi(argv[i + 1]);
    if ((i = find_arg((char *)"-symmetric", argc, argv)) > 0) symmetric = atoi(argv[i + 1]);
    if ((i = find_arg((char *)"-window-size", argc, argv)) > 0) window_size = atoi(argv[i + 1]);
    if ((i = find_arg((char *)"-vocab-file", argc, argv)) > 0) strcpy(vocab_file, argv[i + 1]);
    else strcpy(vocab_file, (char *)"vocab.txt");
    if ((i = find_arg((char *)"-overflow-file", argc, argv)) > 0) strcpy(file_head, argv[i + 1]);
    else strcpy(file_head, (char *)"overflow");
    if ((i = find_arg((char *)"-memory", argc, argv)) > 0) memory_limit = atof(argv[i + 1]);
    if ((i = find_arg((char *)"-distance-weighting", argc, argv)) > 0)  distance_weighting = atoi(argv[i + 1]);
    
    /* The memory_limit determines a limit on the number of elements in bigram_table and the overflow buffer */
    /* Estimate the maximum value that max_product can take so that this limit is still satisfied */
    rlimit = 0.85 * (real)memory_limit * 1073741824/(sizeof(CREC));
    while (fabs(rlimit - n * (log(n) + 0.1544313298)) > 1e-3) n = rlimit / (log(n) + 0.1544313298);
    max_product = (long long) n;
    overflow_length = (long long) rlimit/6; // 0.85 + 1/6 ~= 1
    
    /* Override estimates by specifying limits explicitly on the command line */
    if ((i = find_arg((char *)"-max-product", argc, argv)) > 0) max_product = atoll(argv[i + 1]);
    if ((i = find_arg((char *)"-overflow-length", argc, argv)) > 0) overflow_length = atoll(argv[i + 1]);
    
    const int returned_value = get_cooccurrence();
    free(vocab_file);
    free(file_head);
    return returned_value;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd 0x143a(%rip), %xmm0     # 0x4018
movsd %xmm0, -0x28(%rbp)
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x1150
movq %rax, 0x453c(%rip)      # 0x7130
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x1150
movq %rax, 0x4513(%rip)      # 0x7118
cmpl $0x1, -0x8(%rbp)
jne 0x2d75
leaq 0x173f(%rip), %rdi      # 0x4355
movb $0x0, %al
callq 0x10e0
leaq 0x1766(%rip), %rdi      # 0x438a
movb $0x0, %al
callq 0x10e0
leaq 0x178c(%rip), %rdi      # 0x43be
movb $0x0, %al
callq 0x10e0
leaq 0x178e(%rip), %rdi      # 0x43ce
movb $0x0, %al
callq 0x10e0
leaq 0x1791(%rip), %rdi      # 0x43df
movb $0x0, %al
callq 0x10e0
leaq 0x17ad(%rip), %rdi      # 0x4409
movb $0x0, %al
callq 0x10e0
leaq 0x17b2(%rip), %rdi      # 0x441c
movb $0x0, %al
callq 0x10e0
leaq 0x17f7(%rip), %rdi      # 0x446f
movb $0x0, %al
callq 0x10e0
leaq 0x17fe(%rip), %rdi      # 0x4484
movb $0x0, %al
callq 0x10e0
leaq 0x1848(%rip), %rdi      # 0x44dc
movb $0x0, %al
callq 0x10e0
leaq 0x184f(%rip), %rdi      # 0x44f1
movb $0x0, %al
callq 0x10e0
leaq 0x18a8(%rip), %rdi      # 0x4558
movb $0x0, %al
callq 0x10e0
leaq 0x18ac(%rip), %rdi      # 0x456a
movb $0x0, %al
callq 0x10e0
leaq 0x190f(%rip), %rdi      # 0x45db
movb $0x0, %al
callq 0x10e0
leaq 0x1916(%rip), %rdi      # 0x45f0
movb $0x0, %al
callq 0x10e0
leaq 0x1a1b(%rip), %rdi      # 0x4703
movb $0x0, %al
callq 0x10e0
leaq 0x1a26(%rip), %rdi      # 0x471c
movb $0x0, %al
callq 0x10e0
leaq 0x1b36(%rip), %rdi      # 0x483a
movb $0x0, %al
callq 0x10e0
leaq 0x1b40(%rip), %rdi      # 0x4852
movb $0x0, %al
callq 0x10e0
leaq 0x1b7a(%rip), %rdi      # 0x489a
movb $0x0, %al
callq 0x10e0
leaq 0x1b88(%rip), %rdi      # 0x48b6
movb $0x0, %al
callq 0x10e0
leaq 0x1c22(%rip), %rdi      # 0x495e
movb $0x0, %al
callq 0x10e0
leaq 0x1c25(%rip), %rdi      # 0x496f
movb $0x0, %al
callq 0x10e0
movq 0x43d8(%rip), %rdi      # 0x7130
callq 0x1030
movq 0x43b4(%rip), %rdi      # 0x7118
callq 0x1030
movl $0x0, -0x4(%rbp)
jmp 0x30b0
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1c7f(%rip), %rdi      # 0x4a02
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x2dac
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1180
movl %eax, 0x4344(%rip)      # 0x70f0
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1c51(%rip), %rdi      # 0x4a0b
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x2de3
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1180
movl %eax, 0x4315(%rip)      # 0x70f8
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1c25(%rip), %rdi      # 0x4a16
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x2e1a
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1180
movl %eax, 0x42da(%rip)      # 0x70f4
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1bfb(%rip), %rdi      # 0x4a23
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x2e54
movq 0x42f4(%rip), %rdi      # 0x7130
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1060
jmp 0x2e67
movq 0x42d5(%rip), %rdi      # 0x7130
leaq 0x1bcd(%rip), %rsi      # 0x4a2f
callq 0x1060
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1bc4(%rip), %rdi      # 0x4a39
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x2ea1
movq 0x428f(%rip), %rdi      # 0x7118
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1060
jmp 0x2eb4
movq 0x4270(%rip), %rdi      # 0x7118
leaq 0x1b99(%rip), %rsi      # 0x4a48
callq 0x1060
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1b8f(%rip), %rdi      # 0x4a51
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x2eed
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10a0
movsd %xmm0, 0x4213(%rip)     # 0x7100
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1b5e(%rip), %rdi      # 0x4a59
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x2f24
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1180
movl %eax, 0x41e4(%rip)      # 0x7108
movsd 0x1104(%rip), %xmm0     # 0x4030
mulsd 0x41cc(%rip), %xmm0     # 0x7100
movsd 0x10ec(%rip), %xmm1     # 0x4028
mulsd %xmm1, %xmm0
movsd 0x10d8(%rip), %xmm1     # 0x4020
divsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x1100
movsd -0x40(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x38(%rbp), %xmm0
movsd 0x10bc(%rip), %xmm3     # 0x4040
addsd %xmm3, %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps 0x10a2(%rip), %xmm1     # 0x4050
pand %xmm1, %xmm0
movsd 0x107e(%rip), %xmm1     # 0x4038
ucomisd %xmm1, %xmm0
jbe 0x2ff6
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x1100
movaps %xmm0, %xmm1
movsd -0x48(%rbp), %xmm0
movsd 0x105c(%rip), %xmm2     # 0x4040
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x2f51
cvttsd2si -0x28(%rbp), %rax
movq %rax, 0x4125(%rip)      # 0x7128
cvttsd2si -0x20(%rbp), %rax
movl $0x6, %ecx
cqto
idivq %rcx
movq %rax, 0x4106(%rip)      # 0x7120
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1a45(%rip), %rdi      # 0x4a6d
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x3052
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1120
movq %rax, 0x40d6(%rip)      # 0x7128
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1a1a(%rip), %rdi      # 0x4a7a
callq 0x3390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jle 0x308a
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1120
movq %rax, 0x4096(%rip)      # 0x7120
callq 0x1f00
movl %eax, -0x2c(%rbp)
movq 0x4097(%rip), %rdi      # 0x7130
callq 0x1030
movq 0x4073(%rip), %rdi      # 0x7118
callq 0x1030
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)