// File: /workspace/github_cpp_makefile_star2_O3/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, (%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 0x911a
xorpd %xmm0, %xmm0
testq %r14, %r14
jle 0x9022
movq %r14, 0x20(%rsp)
xorl %ebp, %ebp
leaq 0x68(%rsp), %r14
leaq 0x8(%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, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x914c
movq %rbp, 0x10(%rsp)
movq %rax, 0x30(%rsp)
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xa4d0
movq 0x8(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
cmpq %rax, (%rsp)
xorpd %xmm0, %xmm0
jle 0x8e9e
movq %rax, (%rsp)
incq %rbp
cmpq %rbp, 0x20(%rsp)
jne 0x8e4d
cmpq $0x0, 0x20(%rsp)
jle 0x9022
movsd %xmm0, 0x38(%rsp)
xorl %r14d, %r14d
leaq 0x68(%rsp), %r15
movq %rsp, %r12
leaq 0x98(%rsp), %r13
leaq 0x10(%rsp), %rbp
movq %r15, %rdi
movq %r12, %rsi
callq 0x914c
cmpq $0x0, 0x18(%rax)
jne 0x8eea
incq (%rsp)
jmp 0x8ed2
movq %r14, 0x58(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x914c
movq 0x10(%rax), %r14
movq 0x8(%r14), %rax
movq %rax, 0x8(%rsp)
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x91b2
movb $0x1, (%rax)
xorps %xmm0, %xmm0
cvtsi2sdq (%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x914c
movq %rax, %rdi
movq %r14, %rsi
callq 0xa98a
movq 0x10(%rbx), %rax
movq 0x8(%rsp), %rcx
movslq (%rax,%rcx,8), %r14
cmpq %r14, 0x8(%rax,%rcx,8)
jle 0x8ffd
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rax
movq %rax, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x91b2
cmpb $0x0, (%rax)
jne 0x8fec
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 0x914c
movq %rax, %rdi
movq %rbp, %rsi
callq 0xaa42
movq 0x28(%rsp), %rax
decq %rax
movq %rax, 0x60(%rsp)
movq %r15, %rdi
leaq 0x60(%rsp), %rsi
callq 0x9218
movq %rax, 0x30(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
leaq 0x30(%rsp), %rdx
callq 0xab82
movq 0x28(%rsp), %rcx
leaq -0x1(%rcx), %rax
cmpq (%rsp), %rcx
jg 0x8fde
movq %rax, (%rsp)
movq 0x10(%rsp), %rcx
movq 0x40(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
incq %r14
movq 0x10(%rbx), %rax
movq 0x8(%rsp), %rcx
jmp 0x8f49
movsd 0x18(%rsp), %xmm0
maxsd 0x38(%rsp), %xmm0
movq 0x58(%rsp), %r14
incq %r14
movsd %xmm0, 0x38(%rsp)
cmpq 0x20(%rsp), %r14
jne 0x8ed2
leaq 0x35ac(%rip), %rdi      # 0xc5d5
movsd %xmm0, 0x18(%rsp)
movb $0x1, %al
callq 0x3050
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x904d
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x32d0
leaq 0x98(%rsp), %rdi
callq 0x9288
leaq 0x68(%rsp), %rdi
callq 0x92d8
movsd 0x18(%rsp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x908c
jmp 0x908c
jmp 0x908c
jmp 0x908c
jmp 0x908c
jmp 0x908c
jmp 0x908c
jmp 0x908c
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x90a6
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x32d0
leaq 0x98(%rsp), %rdi
callq 0x9288
leaq 0x68(%rsp), %rdi
callq 0x92d8
movq %rbx, %rdi
callq 0x34c0