// File: /workspace/github_c_makefile_star2_O0/saulvargas[P]re-C-sys/similarity_veccosine.c
// Function: similarity_veccosine_calculate
idpairs_t* similarity_veccosine_calculate(int uid, int k, void* args) {
    recdata_t* recdata;
    double* norm;
    double* coo;
    idpairs_t* ud;
    idpairs_t* id;
    int i;
    int j;
    int vid;
    int iid;
    double r;
    topn_t* topn;
    idpairs_t* pairs;
    
    recdata = ((similarity_veccosine_args_t*) args)->recdata;
    norm = ((similarity_veccosine_args_t*) args)->norm;
    
    coo = calloc(recdata->N_users, sizeof(double));
    
    ud = recdata_userdata(recdata, uid);
    for (i = 0; i < idpairs_size(ud); i++) {
        iid = idpairs_keys(ud)[i];
        r = idpairs_values(ud)[i];
        id = recdata_itemdata(recdata, iid);
        for (j = 0; j < idpairs_size(id); j++) {
            vid = idpairs_keys(id)[j];
            coo[vid] += r * idpairs_values(id)[j];
        }
        idpairs_close_shallow(id);
    }
    idpairs_close_shallow(ud);
    
    coo[uid] = 0.0;
    
    topn = topn_create(k);
    for (vid = 0; vid < recdata->N_users; vid++) {
        if (coo[vid] > 0) {
            topn_add(topn, vid, coo[vid] * norm[uid] * norm[vid]);
        }
    }
    
    free(coo);

    pairs = topn_get_pairs(topn);
    
    topn_close(topn);

    return pairs;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x1090
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x1310
movq %rax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2ff0
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
jge 0x1dfa
movq -0x30(%rbp), %rdi
callq 0x3000
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3020
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x1340
movq %rax, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2ff0
movl %eax, %ecx
movl -0x68(%rbp), %eax
cmpl %ecx, %eax
jge 0x1de3
movq -0x38(%rbp), %rdi
callq 0x3000
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x44(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3020
movsd -0x70(%rbp), %xmm0
movslq -0x40(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1d72
movq -0x38(%rbp), %rdi
callq 0x2fd0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1d15
movq -0x30(%rbp), %rdi
callq 0x2fd0
movq -0x28(%rbp), %rax
movslq -0x4(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x8(%rbp), %edi
callq 0x2080
movq %rax, -0x58(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1e87
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1e7a
movq -0x58(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x4(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x44(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
callq 0x2540
jmp 0x1e7c
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1e26
movq -0x28(%rbp), %rdi
callq 0x1030
movq -0x58(%rbp), %rdi
callq 0x27d0
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x20f0
movq -0x60(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq