// File: /workspace/github_cpp_makefile_star2_O1/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), %r14
movq %r14, 0x8(%rsp)
leaq 0x70(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0xa0(%rsp), %rax
movl %ecx, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0x40(%rsp), %rdi
movq %rcx, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
movq %r14, %rsi
callq 0x90da
movq %r14, 0x20(%rsp)
testq %r14, %r14
jle 0x8e57
xorl %ebp, %ebp
leaq 0x68(%rsp), %r14
movq %rsp, %r15
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
movq 0x10(%rbx), %rax
movq 0x8(%rax,%rbp,8), %rcx
subq (%rax,%rbp,8), %rcx
movq %rcx, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x910c
movq %rbp, 0x10(%rsp)
movq %rax, 0x30(%rsp)
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xa50a
movq (%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
jle 0x8e4d
movq %rax, 0x8(%rsp)
incq %rbp
cmpq %rbp, 0x20(%rsp)
jne 0x8dfc
cmpq $0x0, 0x20(%rsp)
jle 0x8fdf
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
xorl %r14d, %r14d
leaq 0x68(%rsp), %r15
leaq 0x8(%rsp), %r12
leaq 0x98(%rsp), %r13
leaq 0x10(%rsp), %rbp
movq %r15, %rdi
movq %r12, %rsi
callq 0x910c
cmpq $0x0, 0x18(%rax)
jne 0x8ea0
incq 0x8(%rsp)
jmp 0x8e87
movq %r14, 0x58(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x910c
movq 0x10(%rax), %r14
movq 0x8(%r14), %rax
movq %rax, (%rsp)
movq %r13, %rdi
movq %rsp, %rsi
callq 0x9172
movb $0x1, (%rax)
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x910c
movq %rax, %rdi
movq %r14, %rsi
callq 0xa9fc
movq 0x10(%rbx), %rax
movq (%rsp), %rcx
movslq (%rax,%rcx,8), %r14
cmpq %r14, 0x8(%rax,%rcx,8)
jle 0x8fb8
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rax
movq %rax, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x9172
cmpb $0x0, (%rax)
jne 0x8fa8
movq 0x10(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, 0x28(%rsp)
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x910c
movq %rax, %rdi
movq %rbp, %rsi
callq 0xaac4
movq 0x28(%rsp), %rax
decq %rax
movq %rax, 0x60(%rsp)
movq %r15, %rdi
leaq 0x60(%rsp), %rsi
callq 0x91d8
movq %rax, 0x30(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
leaq 0x30(%rsp), %rdx
callq 0xabfa
movq 0x28(%rsp), %rax
cmpq 0x8(%rsp), %rax
jg 0x8f97
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%rsp)
decq %rax
movq 0x10(%rsp), %rcx
movq 0x40(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
incq %r14
movq 0x10(%rbx), %rax
movq (%rsp), %rcx
jmp 0x8efc
movsd 0x18(%rsp), %xmm0
maxsd 0x38(%rsp), %xmm0
movq 0x58(%rsp), %r14
incq %r14
movsd %xmm0, 0x38(%rsp)
cmpq 0x20(%rsp), %r14
jne 0x8e87
jmp 0x8fe3
xorpd %xmm0, %xmm0
leaq 0x35cb(%rip), %rdi      # 0xc5b5
movsd %xmm0, 0x18(%rsp)
movb $0x1, %al
callq 0x3050
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x900e
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x32d0
leaq 0x98(%rsp), %rdi
callq 0x924a
leaq 0x68(%rsp), %rdi
callq 0x929a
movsd 0x18(%rsp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x904d
jmp 0x904d
jmp 0x904d
jmp 0x904d
jmp 0x904d
jmp 0x904d
jmp 0x904d
jmp 0x904d
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x9067
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x32d0
leaq 0x98(%rsp), %rdi
callq 0x924a
leaq 0x68(%rsp), %rdi
callq 0x929a
movq %rbx, %rdi
callq 0x34c0