// File: /workspace/github_c_makefile_star2_O0/ComplexNetworks-DCC-FCUP[P]gtrieScanner/Random.cpp
// Function: Random::markovChainPerEdge(Graph*, int, int)
void Random::markovChainPerEdge(Graph *g, int num, int tries) {
  int i, j, k, n, edges, nodes = g->numNodes();
  int a, b, c, d, aux;
  vector<int> *v, *u;
  vector<int>:: iterator ii;

  a=b=c=d=0;
  for (n=0; n<num; n++)
    for (i=0; i<nodes; i++) {
      v = g->outEdges(i);
      edges = v->size();
      a = i;
      for (j=0; j<edges; j++) {
	b = (*v)[j];
	for (k=0; k<tries; k++) {
	  c = getInteger(0, nodes-1);
	  if (a==c || b==c || g->hasEdge(c,b)) continue;
	  aux = g->nodeOutEdges(c); 
	  if (aux==0) continue;
	  u = g->outEdges(c);
	  d = getInteger(1, aux);
	  d = (*u)[d-1];
	  if (a==d || b==d || g->hasEdge(a,d)) continue;
	  break;
	}
	if (k<tries) { // Found an edge to swap!
	  fflush(stdout);
	  g->rmEdge(a,b);  g->rmEdge(c,d);
	  g->addEdge(a,d); g->addEdge(c,b);
	  if (g->type() == UNDIRECTED) {
	    g->rmEdge(b,a);  g->rmEdge(d,c);
	    g->addEdge(d,a); g->addEdge(b,c);
	  }
	}
      }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, -0x28(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x88a0
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x18f67
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x18f57
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0xb8(%rax)
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x8700
movl %eax, -0x24(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x18f47
movq -0x48(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x8720
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x18e8b
movl -0x28(%rbp), %esi
subl $0x1, %esi
xorl %edi, %edi
callq 0x18c80
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x18dfe
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x18dfe
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x30(%rbp), %edx
movq (%rdi), %rax
callq *0x50(%rax)
testb $0x1, %al
jne 0x18dfe
jmp 0x18e00
jmp 0x18e7d
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movq (%rdi), %rax
callq *0x60(%rax)
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x18e18
jmp 0x18e7d
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movq (%rdi), %rax
callq *0xb8(%rax)
movq %rax, -0x50(%rbp)
movl -0x3c(%rbp), %esi
movl $0x1, %edi
callq 0x18c80
movl %eax, -0x38(%rbp)
movq -0x50(%rbp), %rdi
movl -0x38(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8720
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x18e79
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x18e79
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x38(%rbp), %edx
movq (%rdi), %rax
callq *0x50(%rax)
testb $0x1, %al
jne 0x18e79
jmp 0x18e7b
jmp 0x18e7d
jmp 0x18e8b
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x18dbc
movl -0x1c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x18f37
movq 0x12122(%rip), %rax     # 0x2afc0
movq (%rax), %rdi
callq 0x3300
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
movq (%rdi), %rax
callq *0x38(%rax)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
movq (%rdi), %rax
callq *0x38(%rax)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x38(%rbp), %edx
movq (%rdi), %rax
callq *0x30(%rax)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x30(%rbp), %edx
movq (%rdi), %rax
callq *0x30(%rax)
movq -0x8(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
cmpl $0x1, %eax
jne 0x18f35
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
movq (%rdi), %rax
callq *0x38(%rax)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
movq (%rdi), %rax
callq *0x38(%rax)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x2c(%rbp), %edx
movq (%rdi), %rax
callq *0x30(%rax)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
movq (%rdi), %rax
callq *0x30(%rax)
jmp 0x18f37
jmp 0x18f39
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x18d97
jmp 0x18f49
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x18d5e
jmp 0x18f59
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x18d4b
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)