// File: /workspace/github_cpp_makefile_star2_O3/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 0x40c5
cmpq $0x1, %rax
jne 0x40c9
movsd 0x7f44(%rip), %xmm0     # 0xc008
retq
xorps %xmm0, %xmm0
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
movq %rsi, 0x20(%rsp)
cvtsi2sd %rax, %xmm0
movapd %xmm0, 0x10(%rsp)
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x7f12(%rip), %xmm0     # 0xc010
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
movl $0x4, %esi
callq 0x31a0
movq %rax, %r15
movsd 0x7efa(%rip), %xmm0     # 0xc018
addsd 0x10(%rsp), %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, 0x28(%rsp)
ucomisd %xmm1, %xmm0
xorpd %xmm2, %xmm2
jbe 0x4206
leaq 0x80(%rsp), %r12
movl $0x1, %ebx
xorl %ebp, %ebp
movsd 0x7eb5(%rip), %xmm3     # 0xc008
leaq 0x1(%rbp), %rax
movq %rax, 0x38(%rsp)
xorps %xmm4, %xmm4
cvtsi2sd %eax, %xmm4
movapd 0x10(%rsp), %xmm0
movsd %xmm4, 0x30(%rsp)
ucomisd %xmm4, %xmm0
jbe 0x41ec
movq %rbx, %r13
movsd %xmm1, 0x8(%rsp)
addsd %xmm3, %xmm2
movsd %xmm2, 0x40(%rsp)
movq 0x8(%r14), %rax
movq (%rax,%rbp,8), %rsi
movq (%rax,%r13,8), %rdx
movq %r12, %rdi
callq 0x87c2
cmpl $-0x1, %eax
je 0x41c1
incl (%r15,%rbp,4)
incl (%r15,%r13,4)
movsd 0x8(%rsp), %xmm1
movsd 0x7e51(%rip), %xmm0     # 0xc008
addsd %xmm0, %xmm1
movapd %xmm0, %xmm3
jmp 0x41cf
movsd 0x8(%rsp), %xmm1
movsd 0x7e39(%rip), %xmm3     # 0xc008
incq %r13
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movapd 0x10(%rsp), %xmm2
ucomisd %xmm0, %xmm2
movsd 0x40(%rsp), %xmm2
ja 0x4178
incq %rbx
movsd 0x28(%rsp), %xmm0
ucomisd 0x30(%rsp), %xmm0
movq 0x38(%rsp), %rbp
ja 0x4153
movapd 0x10(%rsp), %xmm0
addsd 0x7e0c(%rip), %xmm0     # 0xc020
cvttsd2si %xmm0, %eax
testl %eax, %eax
js 0x4261
leal 0x1(%rax), %ecx
movl (%r15), %edx
xorl %esi, %esi
movl 0x4(%r15,%rsi,4), %edi
cmpl %edi, %edx
jle 0x424b
movl %edi, (%r15,%rsi,4)
movl %edx, 0x4(%r15,%rsi,4)
movq 0x8(%r14), %rdi
movdqu (%rdi,%rsi,8), %xmm0
pshufd $0x4e, %xmm0, %xmm0     # xmm0 = xmm0[2,3,0,1]
movdqu %xmm0, (%rdi,%rsi,8)
jmp 0x424d
movl %edi, %edx
incq %rsi
cmpq %rsi, %rcx
jne 0x4224
leal -0x1(%rax), %edx
decq %rcx
testl %eax, %eax
movl %edx, %eax
jg 0x421f
cvttsd2si %xmm1, %rax
divsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp)
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x3340
movsd 0x8(%rsp), %xmm0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq