// File: /workspace/github_c_makefile_star2_O0/stanfordnlp[P]GloVe/src/glove.c
// Function: train_glove
int train_glove(void) {
    long long a, file_size;
    int save_params_return_code;
    int b;
    FILE *fin;
    real total_cost = 0;

    fprintf(stderr, "TRAINING MODEL\n");
    
    fin = fopen(input_file, "rb");
    if (fin == NULL) {log_file_loading_error("cooccurrence file", input_file); return 1;}
    fseeko(fin, 0, SEEK_END);
    file_size = ftello(fin);
    num_lines = file_size/(sizeof(CREC)); // Assuming the file isn't corrupt and consists only of CREC's
    fclose(fin);
    fprintf(stderr,"Read %lld lines.\n", num_lines);
    if (verbose > 1) fprintf(stderr,"Initializing parameters...");
    initialize_parameters();
    if (verbose > 1) fprintf(stderr,"done.\n");
    if (save_init_param) {
        if (verbose > 1) fprintf(stderr,"Saving initial parameters... ");
        save_params_return_code = save_params(0);
        if (save_params_return_code != 0)
            return save_params_return_code;
        if (verbose > 1) fprintf(stderr,"done.\n");
    }
    if (verbose > 0) fprintf(stderr,"vector size: %d\n", vector_size);
    if (verbose > 0) fprintf(stderr,"vocab size: %lld\n", vocab_size);
    if (verbose > 0) fprintf(stderr,"x_max: %lf\n", x_max);
    if (verbose > 0) fprintf(stderr,"alpha: %lf\n", alpha);
    pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t));
    lines_per_thread = (long long *) malloc(num_threads * sizeof(long long));
    
    time_t rawtime;
    struct tm *info;
    char time_buffer[80];
    // Lock-free asynchronous SGD
    for (b = 0; b < num_iter; b++) {
        total_cost = 0;
        for (a = 0; a < num_threads - 1; a++) lines_per_thread[a] = num_lines / num_threads;
        lines_per_thread[a] = num_lines / num_threads + num_lines % num_threads;
        long long *thread_ids = (long long*)malloc(sizeof(long long) * num_threads);
        for (a = 0; a < num_threads; a++) thread_ids[a] = a;
        for (a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, glove_thread, (void *)&thread_ids[a]);
        for (a = 0; a < num_threads; a++) pthread_join(pt[a], NULL);
        for (a = 0; a < num_threads; a++) total_cost += cost[a];
        free(thread_ids);

        time(&rawtime);
        info = localtime(&rawtime);
        strftime(time_buffer,80,"%x - %I:%M.%S%p", info);
        fprintf(stderr, "%s, iter: %03d, cost: %lf\n", time_buffer,  b+1, total_cost/num_lines);

        if (checkpoint_every > 0 && (b + 1) % checkpoint_every == 0) {
            fprintf(stderr,"    saving intermediate parameters for iter %03d...", b+1);
            save_params_return_code = save_params(b+1);
            if (save_params_return_code != 0) {
                free(pt);
                free(lines_per_thread);
                return save_params_return_code;
            }
            fprintf(stderr,"done.\n");
        }
    }
    free(pt);
    free(lines_per_thread);
    return save_params(-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x524e(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x2420(%rip), %rsi      # 0x51d4
movb $0x0, %al
callq 0x1140
leaq 0x5bee(%rip), %rdi      # 0x89b0
leaq 0x2277(%rip), %rsi      # 0x5040
callq 0x11d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2df8
leaq 0x2404(%rip), %rdi      # 0x51e4
leaq 0x5bc9(%rip), %rsi      # 0x89b0
callq 0x4120
movl $0x1, -0x4(%rbp)
jmp 0x32cb
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x11c0
movq -0x28(%rbp), %rdi
callq 0x1070
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
shrq $0x4, %rax
movq %rax, 0x5f72(%rip)      # 0x8d98
movq -0x28(%rbp), %rdi
callq 0x10d0
movq 0x51c2(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq 0x5f58(%rip), %rdx      # 0x8d98
leaq 0x23af(%rip), %rsi      # 0x51f6
movb $0x0, %al
callq 0x1140
cmpl $0x1, 0x52f3(%rip)      # 0x8148
jle 0x2e6f
movq 0x519a(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x23a0(%rip), %rsi      # 0x5208
movb $0x0, %al
callq 0x1140
callq 0x1460
cmpl $0x1, 0x52cd(%rip)      # 0x8148
jle 0x2e95
movq 0x5174(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x2395(%rip), %rsi      # 0x5223
movb $0x0, %al
callq 0x1140
cmpl $0x0, 0x530c(%rip)      # 0x81a8
je 0x2efd
cmpl $0x1, 0x52a3(%rip)      # 0x8148
jle 0x2ebf
movq 0x514a(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x2372(%rip), %rsi      # 0x522a
movb $0x0, %al
callq 0x1140
xorl %edi, %edi
callq 0x2010
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x2eda
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x32cb
cmpl $0x1, 0x5267(%rip)      # 0x8148
jle 0x2efb
movq 0x510e(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x232f(%rip), %rsi      # 0x5223
movb $0x0, %al
callq 0x1140
jmp 0x2efd
cmpl $0x0, 0x5244(%rip)      # 0x8148
jle 0x2f24
movq 0x50eb(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl 0x5242(%rip), %edx      # 0x8158
leaq 0x232b(%rip), %rsi      # 0x5248
movb $0x0, %al
callq 0x1140
cmpl $0x0, 0x521d(%rip)      # 0x8148
jle 0x2f4c
movq 0x50c4(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq 0x5272(%rip), %rdx      # 0x81b0
leaq 0x2314(%rip), %rsi      # 0x5259
movb $0x0, %al
callq 0x1140
cmpl $0x0, 0x51f5(%rip)      # 0x8148
jle 0x2f75
movq 0x509c(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movsd 0x5209(%rip), %xmm0     # 0x8170
leaq 0x22fd(%rip), %rsi      # 0x526b
movb $0x1, %al
callq 0x1140
cmpl $0x0, 0x51cc(%rip)      # 0x8148
jle 0x2f9e
movq 0x5073(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movsd 0x51d8(%rip), %xmm0     # 0x8168
leaq 0x22e0(%rip), %rsi      # 0x5277
movb $0x1, %al
callq 0x1140
movslq 0x51ab(%rip), %rdi      # 0x8150
shlq $0x3, %rdi
callq 0x1180
movq %rax, -0x38(%rbp)
movslq 0x5197(%rip), %rdi      # 0x8150
shlq $0x3, %rdi
callq 0x1180
movq %rax, 0x5ddf(%rip)      # 0x8da8
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl 0x517b(%rip), %eax      # 0x8154
jge 0x32a9
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x5157(%rip), %ecx      # 0x8150
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x3037
movq 0x5d8d(%rip), %rax      # 0x8d98
movslq 0x513e(%rip), %rcx      # 0x8150
cqto
idivq %rcx
movq %rax, %rdx
movq 0x5d87(%rip), %rax      # 0x8da8
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x2fef
movq 0x5d5a(%rip), %rax      # 0x8d98
movslq 0x510b(%rip), %rcx      # 0x8150
cqto
idivq %rcx
movq %rax, -0xb0(%rbp)
movq 0x5d40(%rip), %rax      # 0x8d98
movslq 0x50f1(%rip), %rcx      # 0x8150
cqto
idivq %rcx
movq %rdx, %rax
movq -0xb0(%rbp), %rdx
addq %rax, %rdx
movq 0x5d30(%rip), %rax      # 0x8da8
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq 0x50c9(%rip), %rdi      # 0x8150
shlq $0x3, %rdi
callq 0x1180
movq %rax, -0xa8(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movslq 0x50a6(%rip), %rcx      # 0x8150
cmpq %rcx, %rax
jge 0x30d0
movq -0x10(%rbp), %rdx
movq -0xa8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x309f
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movslq 0x506d(%rip), %rcx      # 0x8150
cmpq %rcx, %rax
jge 0x3127
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0xa8(%rbp), %rcx
movq -0x10(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0x1a34(%rip), %rdx     # 0x16e0
callq 0x11a0
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x30d8
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movslq 0x5016(%rip), %rcx      # 0x8150
cmpq %rcx, %rax
jge 0x3162
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1240
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x312f
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movslq 0x4fdb(%rip), %rcx      # 0x8150
cmpq %rcx, %rax
jge 0x31a2
movq 0x5c1f(%rip), %rax      # 0x8da0
movq -0x10(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x316a
movq -0xa8(%rbp), %rdi
callq 0x1030
leaq -0x40(%rbp), %rdi
callq 0x1160
leaq -0x40(%rbp), %rdi
callq 0x1040
movq %rax, -0x48(%rbp)
leaq -0xa0(%rbp), %rdi
movq -0x48(%rbp), %rcx
movl $0x50, %esi
leaq 0x20a8(%rip), %rdx      # 0x5283
callq 0x11b0
movq 0x4e11(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq -0xa0(%rbp), %rdx
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movsd -0x30(%rbp), %xmm0
cvtsi2sdq 0x5b93(%rip), %xmm1 # 0x8d98
divsd %xmm1, %xmm0
leaq 0x2083(%rip), %rsi      # 0x5293
movb $0x1, %al
callq 0x1140
cmpl $0x0, 0x4f82(%rip)      # 0x81a0
jle 0x3299
movl -0x20(%rbp), %eax
addl $0x1, %eax
cltd
idivl 0x4f73(%rip)            # 0x81a0
cmpl $0x0, %edx
jne 0x3299
movq 0x4dbf(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x20(%rbp), %edx
addl $0x1, %edx
leaq 0x2065(%rip), %rsi      # 0x52ae
movb $0x0, %al
callq 0x1140
movl -0x20(%rbp), %edi
addl $0x1, %edi
callq 0x2010
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3281
movq -0x38(%rbp), %rdi
callq 0x1030
movq 0x5b34(%rip), %rdi      # 0x8da8
callq 0x1030
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x32cb
movq 0x4d70(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x1f91(%rip), %rsi      # 0x5223
movb $0x0, %al
callq 0x1140
jmp 0x329b
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2fd0
movq -0x38(%rbp), %rdi
callq 0x1030
movq 0x5aef(%rip), %rdi      # 0x8da8
callq 0x1030
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2010
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)