// File: dtsaras[P]GCW/rwgraph.cpp
// Function: Graph::calculate_sim_stats(int, int, double*)
void Graph::calculate_sim_stats(int P, int ev, double * stats){
    float** aware_all_ev = new float*[P];
    for (int p = 0; p < P; ++p){
        aware_all_ev[p] = new float[getSize() + 1];
        for(int v = 0; v <= getSize(); v++){
            aware_all_ev[p][v] = 0;
        }
    }

    for (int ev = 0; ev < P; ev++){
        if (model == 0){
            rand_LT();
            BFS_LT(ev, aware_all_ev);
        }
        else
            BFS_IC(ev, aware_all_ev);
    }
    double similarity_Sj = 0;
    double similarity_S_Sj = 0;
    double total_sim  = 0;
    double max_weight;
    double max_weight_not_ev;
    int max_event;
    for (int v = 1; v <= getSize(); ++v){
        // if (aware_all_ev[ev][v] == 1){
        //     similarity_Sj += similarities[v][ev];
        // }
        max_weight = 0;
        max_weight_not_ev = 0;
        for (int p = 0; p < P; ++p){
            if (aware_all_ev[p][v] == 1 && similarities[v][p] > max_weight_not_ev && p != ev){
                max_weight_not_ev = similarities[v][p];
            }
            if (aware_all_ev[p][v] == 1 && similarities[v][p] > max_weight){
                max_weight = similarities[v][p];
                max_event = p;
            }
        }
        if (max_event == ev){
            similarity_Sj += max_weight;
        }
        total_sim += max_weight;
        similarity_S_Sj += max_weight_not_ev;
    }
    for (int p = 0; p < P; ++p){
        delete [] aware_all_ev[p];
    }
    delete [] aware_all_ev;

    stats[0] = total_sim;
    stats[1] = similarity_Sj;
    stats[2] = similarity_S_Sj;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movl %esi, 0x7c(%rsp)
movl %edx, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x18(%rsp)
movslq 0x7c(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x7c(%rsp), %eax
jge 0x22669
movq 0x18(%rsp), %rdi
callq 0x1db70
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, %rdx
movq 0x68(%rsp), %rax
movslq 0x64(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, 0x60(%rsp)
movq 0x18(%rsp), %rdi
movl 0x60(%rsp), %eax
movl %eax, 0x14(%rsp)
callq 0x1db70
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jg 0x22657
movq 0x68(%rsp), %rax
movslq 0x64(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x60(%rsp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x22613
jmp 0x22659
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x225bc
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x7c(%rsp), %eax
jge 0x226ca
movq 0x18(%rsp), %rax
cmpl $0x0, 0xa60(%rax)
jne 0x226a8
movq 0x18(%rsp), %rdi
callq 0x21590
movq 0x18(%rsp), %rdi
movl 0x5c(%rsp), %esi
movq 0x68(%rsp), %rdx
callq 0x21a80
jmp 0x226bb
movq 0x18(%rsp), %rdi
movl 0x5c(%rsp), %esi
movq 0x68(%rsp), %rdx
callq 0x21610
jmp 0x226bd
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x22671
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movl $0x1, 0x28(%rsp)
movq 0x18(%rsp), %rdi
movl 0x28(%rsp), %eax
movl %eax, 0x10(%rsp)
callq 0x1db70
movl %eax, %ecx
movl 0x10(%rsp), %eax
cmpl %ecx, %eax
jg 0x228af
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x7c(%rsp), %eax
jge 0x2285f
movq 0x68(%rsp), %rax
movslq 0x24(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x28(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss 0xf8f7(%rip), %xmm1     # 0x3204c
ucomiss %xmm1, %xmm0
jne 0x227c2
jp 0x227c2
movq 0x18(%rsp), %rdi
addq $0xae0, %rdi            # imm = 0xAE0
movslq 0x28(%rsp), %rsi
callq 0xf180
movq %rax, %rdi
movslq 0x24(%rsp), %rsi
callq 0xeb00
movsd (%rax), %xmm0
ucomisd 0x30(%rsp), %xmm0
jbe 0x227c2
movl 0x24(%rsp), %eax
cmpl 0x78(%rsp), %eax
je 0x227c2
movq 0x18(%rsp), %rdi
addq $0xae0, %rdi            # imm = 0xAE0
movslq 0x28(%rsp), %rsi
callq 0xf180
movq %rax, %rdi
movslq 0x24(%rsp), %rsi
callq 0xeb00
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x68(%rsp), %rax
movslq 0x24(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x28(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss 0xf86a(%rip), %xmm1     # 0x3204c
ucomiss %xmm1, %xmm0
jne 0x2284d
jp 0x2284d
movq 0x18(%rsp), %rdi
addq $0xae0, %rdi            # imm = 0xAE0
movslq 0x28(%rsp), %rsi
callq 0xf180
movq %rax, %rdi
movslq 0x24(%rsp), %rsi
callq 0xeb00
movsd (%rax), %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0x2284d
movq 0x18(%rsp), %rdi
addq $0xae0, %rdi            # imm = 0xAE0
movslq 0x28(%rsp), %rsi
callq 0xf180
movq %rax, %rdi
movslq 0x24(%rsp), %rsi
callq 0xeb00
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x2c(%rsp)
jmp 0x2284f
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x22727
movl 0x2c(%rsp), %eax
cmpl 0x78(%rsp), %eax
jne 0x2287b
movsd 0x38(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x38(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x30(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x226ed
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x7c(%rsp), %eax
jge 0x228f3
movq 0x68(%rsp), %rax
movslq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x228e4
movq 0x8(%rsp), %rdi
callq 0x44c0
jmp 0x228e6
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x228b7
movq 0x68(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x2290b
movq (%rsp), %rdi
callq 0x44c0
movsd 0x40(%rsp), %xmm0
movq 0x70(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x50(%rsp), %xmm0
movq 0x70(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movsd 0x48(%rsp), %xmm0
movq 0x70(%rsp), %rax
movsd %xmm0, 0x10(%rax)
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)