// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
movq (%rdi), %rax
callq *0x40(%rax)
xorl %ecx, %ecx
testl %ebx, %ebx
cmovlel %ecx, %ebx
movl %ebx, 0x10(%rsp)
leal -0x1(%rax), %r12d
testl %eax, %eax
cmovlel %ecx, %eax
movq %rax, 0x18(%rsp)
testl %ebp, %ebp
cmovlel %ecx, %ebp
movl %ebp, 0x8(%rsp)
xorl %eax, %eax
cmpl 0x8(%rsp), %eax
je 0xad58
xorl %ebx, %ebx
movl %eax, 0xc(%rsp)
cmpl 0x18(%rsp), %ebx
je 0xad51
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
callq *0xb8(%rax)
movq 0x8(%rax), %rcx
movq %rax, 0x20(%rsp)
subq (%rax), %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq %rcx, 0x28(%rsp)
xorl %ecx, %ecx
movl %ebx, 0x14(%rsp)
cmpq 0x28(%rsp), %rcx
je 0xad46
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x30(%rsp)
movl (%rax,%rcx,4), %eax
movl %eax, 0x4(%rsp)
movl 0x10(%rsp), %ebp
subl $0x1, %ebp
jb 0xad39
xorl %edi, %edi
movl %r12d, %esi
callq 0xaafe
cmpl %eax, %ebx
je 0xabfb
movl %eax, %r15d
cmpl %eax, 0x4(%rsp)
je 0xabfb
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
movl 0x4(%rsp), %edx
callq *0x50(%rax)
testb %al, %al
jne 0xabfb
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0x60(%rax)
testl %eax, %eax
je 0xabfb
movl %eax, %r13d
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0xb8(%rax)
movq %r14, %rbx
movl %r12d, %r14d
movq %rax, %r12
pushq $0x1
popq %rdi
movl %r13d, %esi
callq 0xaafe
movq (%r12), %rcx
movl %r14d, %r12d
movq %rbx, %r14
movl 0x14(%rsp), %ebx
cltq
movl -0x4(%rcx,%rax,4), %r13d
cmpl %r13d, %ebx
je 0xabfb
cmpl %r13d, 0x4(%rsp)
je 0xabfb
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
movl %r13d, %edx
callq *0x50(%rax)
testb %al, %al
jne 0xabfb
movq 0xd315(%rip), %rax      # 0x17fc0
movq (%rax), %rdi
callq 0x2260
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
movl 0x4(%rsp), %ebp
movl %ebp, %edx
callq *0x38(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq *0x38(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
movl %r13d, %edx
callq *0x30(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq *0x30(%rax)
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
cmpl $0x1, %eax
jne 0xad39
movq (%r14), %rax
movq %r14, %rdi
movl 0x4(%rsp), %ebp
movl %ebp, %esi
movl %ebx, %edx
callq *0x38(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq *0x38(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq *0x30(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq *0x30(%rax)
movq 0x30(%rsp), %rcx
incq %rcx
jmp 0xabd8
incl %ebx
movl 0xc(%rsp), %eax
jmp 0xab9b
incl %eax
jmp 0xab8b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop