// File: /workspace/github_cpp_makefile_star2_O2/sjain12[P]CliqueCounting/tests/../Escape/CliquesTuranShadow.h
// Function: get_density(Escape::CGraph, VertexSet*, long&)
double get_density(CGraph CG, VertexSet *nbrs, EdgeIdx& num_edges)
{
    double n = nbrs->nVertices;
    double total = 0;
    double actual = 0;
    if (n==0) return 0;
    if (n==1) return 1;

    int *degrees = (int *) calloc(n, sizeof(int));

    for (int i=0; i<n-1; i++)
    {
        for (int j=i+1; j<n; j++)
        {
            total++;
            if (CG.isEdge(nbrs->vertices[i], nbrs->vertices[j]) != -1)
            {
                degrees[i]++;
                degrees[j]++;
                actual++;
            }
        }
    }

    double density = actual/total;

    VertexIdx tmp;

    for (int i=n-2; i>=0; i--)
    {
        for (int j=0; j<=i; j++)
        {
            if (degrees[j] > degrees[j+1])
            {
                tmp = degrees[j];
                degrees[j] = degrees[j+1];
                degrees[j+1] = tmp;
                tmp = nbrs->vertices[j];
                nbrs->vertices[j] = nbrs->vertices[j+1];
                nbrs->vertices[j+1] = tmp;
            }
        }
    }
    num_edges = actual;
	free(degrees);
    return density;
}

// Assembly:
movq (%rdi), %rax
testq %rax, %rax
je 0x3db5
cmpq $0x1, %rax
jne 0x3db9
movsd 0x7254(%rip), %xmm0     # 0xb008
retq
xorps %xmm0, %xmm0
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
movq %rsi, 0x20(%rsp)
cvtsi2sd %rax, %xmm0
movapd %xmm0, 0x10(%rsp)
leaq 0x70(%rsp), %r12
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x721d(%rip), %xmm0     # 0xb010
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
pushq $0x4
popq %rsi
callq 0x3190
movq %rax, %r15
movsd 0x7207(%rip), %xmm0     # 0xb018
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
xorpd %xmm1, %xmm1
pushq $0x1
popq %rbx
xorl %ebp, %ebp
movsd 0x71da(%rip), %xmm4     # 0xb008
xorpd %xmm2, %xmm2
cvtsi2sd %ebp, %xmm0
movsd 0x28(%rsp), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x3ec7
movq %rbx, %r13
cvtsi2sd %r13d, %xmm0
movapd 0x10(%rsp), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x3ebc
movsd %xmm1, 0x8(%rsp)
addsd %xmm4, %xmm2
movsd %xmm2, 0x30(%rsp)
movq 0x8(%r14), %rax
movq (%rax,%rbp,8), %rsi
movq (%rax,%r13,8), %rdx
movq %r12, %rdi
callq 0x7112
cmpl $-0x1, %eax
je 0x3ea3
incl (%r15,%rbp,4)
incl (%r15,%r13,4)
movsd 0x8(%rsp), %xmm1
movsd 0x716f(%rip), %xmm0     # 0xb008
addsd %xmm0, %xmm1
movapd %xmm0, %xmm4
jmp 0x3eb1
movsd 0x8(%rsp), %xmm1
movsd 0x7157(%rip), %xmm4     # 0xb008
incq %r13
movsd 0x30(%rsp), %xmm2
jmp 0x3e49
incq %rbp
incq %rbx
jmp 0x3e32
movapd 0x10(%rsp), %xmm0
addsd 0x714b(%rip), %xmm0     # 0xb020
cvttsd2si %xmm0, %eax
cltq
movq 0x20(%rsp), %rdi
testq %rax, %rax
js 0x3f1f
xorl %ecx, %ecx
cmpq %rax, %rcx
jg 0x3f1a
movl (%r15,%rcx,4), %edx
movl 0x4(%r15,%rcx,4), %esi
cmpl %esi, %edx
jle 0x3f15
movl %esi, (%r15,%rcx,4)
movl %edx, 0x4(%r15,%rcx,4)
movq 0x8(%r14), %rdx
movdqu (%rdx,%rcx,8), %xmm0
pshufd $0x4e, %xmm0, %xmm0     # xmm0 = xmm0[2,3,0,1]
movdqu %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x3ee7
decq %rax
jmp 0x3ee0
cvttsd2si %xmm1, %rax
divsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %rax, (%rdi)
movq %r15, %rdi
callq 0x3300
movsd 0x8(%rsp), %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq