// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cvtsi2sdq (%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4623
jp 0x4623
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x4893
movsd -0x20(%rbp), %xmm0
movsd 0x149d8(%rip), %xmm1    # 0x19008
ucomisd %xmm1, %xmm0
jne 0x464a
jp 0x464a
movsd 0x149c8(%rip), %xmm0    # 0x19008
movsd %xmm0, -0x8(%rbp)
jmp 0x4893
movsd -0x20(%rbp), %xmm0
movsd 0x149b9(%rip), %xmm2    # 0x19010
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rdi
movq %rdi, %rcx
sarq $0x3f, %rcx
andq %rcx, %rax
orq %rax, %rdi
movl $0x4, %esi
callq 0x31d0
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cvtsi2sdl -0x3c(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
movsd 0x1496c(%rip), %xmm2    # 0x19008
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x475b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
cvtsi2sdl -0x40(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x474b
movq -0x60(%rbp), %rdi
movsd 0x14935(%rip), %xmm0    # 0x19008
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
callq 0xda80
cmpl $-0x1, %eax
je 0x473b
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movsd 0x148d7(%rip), %xmm0    # 0x19008
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x473d
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x46b3
jmp 0x474d
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x468a
movsd -0x30(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x20(%rbp), %xmm0
movsd 0x148a1(%rip), %xmm1    # 0x19018
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jl 0x4873
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jg 0x4863
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x38(%rbp), %rcx
movl -0x58(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x4853
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rax
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x58(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x4855
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x4793
jmp 0x4865
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x4782
cvttsd2si -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rdi
callq 0x33d0
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x60, %rsp
popq %rbp
retq
nop