// File: /workspace/github_cpp_makefile_star2_O1/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 0x4140
cmpq $0x1, %rax
jne 0x4144
movsd 0x7ec9(%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, 0x28(%rsp)
cvtsi2sd %rax, %xmm0
movapd %xmm0, 0x10(%rsp)
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x7e97(%rip), %xmm0     # 0xc010
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
movl $0x4, %esi
callq 0x31a0
movq %rax, %r15
movsd 0x7e7f(%rip), %xmm2     # 0xc018
addsd 0x10(%rsp), %xmm2
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm2, 0x30(%rsp)
ucomisd %xmm1, %xmm2
jbe 0x4286
leaq 0x80(%rsp), %r12
movl $0x1, %ebx
xorl %ebp, %ebp
movsd 0x7e34(%rip), %xmm3     # 0xc008
movsd %xmm0, 0x8(%rsp)
leaq 0x1(%rbp), %rax
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movapd 0x10(%rsp), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x4267
movq %rbx, %r13
addsd %xmm3, %xmm1
movsd %xmm1, 0x40(%rsp)
movq 0x8(%r14), %rax
movq (%rax,%rbp,8), %rsi
movq (%rax,%r13,8), %rdx
movq %r12, %rdi
callq 0x8856
cmpl $-0x1, %eax
je 0x4242
incl (%r15,%rbp,4)
incl (%r15,%r13,4)
movsd 0x8(%rsp), %xmm0
movsd 0x7dd6(%rip), %xmm1     # 0xc008
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm1, %xmm3
jmp 0x424a
movsd 0x7dbe(%rip), %xmm3     # 0xc008
incq %r13
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movapd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movsd 0x40(%rsp), %xmm1
ja 0x41f9
movq 0x38(%rsp), %rbp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
incq %rbx
movsd 0x30(%rsp), %xmm2
ucomisd %xmm0, %xmm2
ja 0x41da
movapd 0x10(%rsp), %xmm0
addsd 0x7d8c(%rip), %xmm0     # 0xc020
cvttsd2si %xmm0, %eax
testl %eax, %eax
movsd 0x8(%rsp), %xmm0
js 0x42e7
leal 0x1(%rax), %ecx
xorl %edx, %edx
movl (%r15,%rdx,4), %esi
movl 0x4(%r15,%rdx,4), %edi
cmpl %edi, %esi
jle 0x42d3
movl %edi, (%r15,%rdx,4)
movl %esi, 0x4(%r15,%rdx,4)
movq 0x8(%r14), %rsi
movq (%rsi,%rdx,8), %rdi
movq 0x8(%rsi,%rdx,8), %r8
movq %r8, (%rsi,%rdx,8)
movq %rdi, 0x8(%rsi,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x42a7
leal -0x1(%rax), %edx
decq %rcx
testl %eax, %eax
movl %edx, %eax
jg 0x42a5
cvttsd2si %xmm0, %rax
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%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