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

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

    return pairs;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movslq (%rax), %rdi
movl $0x4, %esi
callq 0x1090
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x1310
movq %rax, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2ff0
movl %eax, %ecx
movl -0x54(%rbp), %eax
cmpl %ecx, %eax
jge 0x1b6d
movq -0x28(%rbp), %rdi
callq 0x3000
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x1340
movq %rax, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2ff0
movl %eax, %ecx
movl -0x58(%rbp), %eax
cmpl %ecx, %eax
jge 0x1b56
movq -0x30(%rbp), %rdi
callq 0x3000
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1b0f
movq -0x30(%rbp), %rdi
callq 0x2fd0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1ac9
movq -0x28(%rbp), %rdi
callq 0x2fd0
movq -0x20(%rbp), %rax
movslq -0x4(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x8(%rbp), %edi
callq 0x2080
movq %rax, -0x48(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1c29
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jle 0x1c19
movq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x12b0
movl %eax, -0x74(%rbp)
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x12b0
movl %eax, %ecx
movl -0x74(%rbp), %eax
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
callq 0x1100
movq -0x70(%rbp), %rdi
movl -0x64(%rbp), %esi
movaps %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
divsd %xmm1, %xmm0
callq 0x2540
jmp 0x1c1b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1b98
movq -0x20(%rbp), %rdi
callq 0x1030
movq -0x48(%rbp), %rdi
callq 0x27d0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x20f0
movq -0x50(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)