// File: /workspace/github_cpp_makefile_star2_O2/sjain12[P]CliqueCounting/Graph.cpp
// Function: Escape::degeneracy(Escape::CGraph&)
double Escape::degeneracy(CGraph &g)
{
  // CGraph cg = g.copy();
  VertexIdx n = g.nVertices;
  VertexIdx min_deg = n;
  double degen = 0;

  map <VertexIdx, unordered_set<VertexIdx> > deg_list;    
  map <VertexIdx, bool> touched;
  vector<VertexIdx> cur_degs;
  cur_degs.resize(n);
	//deg_list.resize(40000);
	//printf("before for\n");
  for (int i=0; i<n; i++)
  {
    VertexIdx deg = g.degree(i);
    deg_list[deg].insert(i);
    cur_degs[i] = deg;
    if (min_deg > deg) min_deg = deg;
  }
	//printf("after for\n");
  for(int i=0; i<n; i++)
  {
	//printf("Inside first for\n");
    while(deg_list[min_deg].size() == 0)
      min_deg++;
    unordered_set<VertexIdx>::iterator it = deg_list[min_deg].begin();
    VertexIdx source = *it;
    touched[source] = true;
    if (degen < min_deg) 
    {
      degen = min_deg;
      // printf("degen = %f\n", degen);
    }
    deg_list[min_deg].erase(it);
   //printf("Calling second for\n"); 
    for (int j=g.offsets[source]; j<g.offsets[source+1]; j++)
    {
      VertexIdx nbr = g.nbors[j];
      if (touched[nbr] == true)
          continue;
      VertexIdx deg = cur_degs[nbr];
      deg_list[deg].erase(nbr);
      deg_list[deg-1].insert(nbr);
      if (deg-1 < min_deg)
          min_deg = deg-1;
      cur_degs[nbr] = deg - 1;
            
    }

  }
  printf("returning degen = %f\n", degen);
  return degen;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movq (%rdi), %rbp
leaq 0x70(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0xa0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rbp, (%rsp)
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq %rbp, %rsi
callq 0x7858
xorl %r13d, %r13d
testq %rbp, %rbp
cmovleq %r13, %rbp
leaq 0x68(%rsp), %r14
leaq 0x8(%rsp), %r15
leaq 0x10(%rsp), %r12
cmpq %r13, %rbp
je 0x7602
movq 0x10(%rbx), %rax
movq 0x8(%rax,%r13,8), %rcx
subq (%rax,%r13,8), %rcx
movq %rcx, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x788a
movq %r13, 0x10(%rsp)
movq %rax, %rdi
movq %r12, %rsi
callq 0x908e
movq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
cmpq %rax, (%rsp)
jle 0x75fd
movq %rax, (%rsp)
incq %r13
jmp 0x75b3
movq %rbp, 0x50(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r14d, %r14d
leaq 0x68(%rsp), %r15
movq %rsp, %r12
leaq 0x98(%rsp), %r13
leaq 0x10(%rsp), %rbp
cmpq 0x50(%rsp), %r14
je 0x777d
movq %r15, %rdi
movq %r12, %rsi
callq 0x788a
cmpq $0x0, 0x18(%rax)
jne 0x764c
incq (%rsp)
jmp 0x7634
movq %r14, 0x58(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x788a
movq 0x10(%rax), %r14
movq 0x8(%r14), %rax
movq %rax, 0x8(%rsp)
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x78da
movb $0x1, (%rax)
cvtsi2sdq (%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x788a
movq %rax, %rdi
movq %r14, %rsi
callq 0x9686
movsd 0x20(%rsp), %xmm0
maxsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x10(%rbx), %rax
movq 0x8(%rsp), %rcx
movslq (%rax,%rcx,8), %r14
cmpq %r14, 0x8(%rax,%rcx,8)
jle 0x7764
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rax
movq %rax, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x78da
cmpb $0x0, (%rax)
jne 0x7753
movq 0x10(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, 0x28(%rsp)
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x788a
movq %rax, %rdi
movq %rbp, %rsi
callq 0x9788
movq 0x28(%rsp), %rax
decq %rax
movq %rax, 0x60(%rsp)
movq %r15, %rdi
leaq 0x60(%rsp), %rsi
callq 0x792a
movq %rax, %rdi
movq %rbp, %rsi
callq 0x989c
movq 0x28(%rsp), %rcx
leaq -0x1(%rcx), %rax
cmpq (%rsp), %rcx
jg 0x7745
movq %rax, (%rsp)
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
incq %r14
movq 0x10(%rbx), %rax
movq 0x8(%rsp), %rcx
jmp 0x76ba
movq 0x58(%rsp), %r14
incq %r14
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x7629
leaq 0x3e21(%rip), %rdi      # 0xb5a5
movsd 0x18(%rsp), %xmm0
movb $0x1, %al
callq 0x3040
leaq 0x30(%rsp), %rdi
callq 0x8bfc
leaq 0x98(%rsp), %rdi
callq 0x797a
leaq 0x68(%rsp), %rdi
callq 0x79d2
movsd 0x18(%rsp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x77da
jmp 0x77da
jmp 0x77da
jmp 0x77da
jmp 0x77da
jmp 0x77da
jmp 0x77da
jmp 0x77da
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8bfc
leaq 0x98(%rsp), %rdi
callq 0x797a
leaq 0x68(%rsp), %rdi
callq 0x79d2
movq %rbx, %rdi
callq 0x34b0