// File: /workspace/github_c_makefile_star2_O3/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, 0x4(%rsp)
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, (%rsp)
movl %ebx, 0x18(%rsp)
testl %ebx, %ebx
jle 0xb609
cvtsi2sdl (%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
cmpl $0x0, (%rsp)
jle 0xb5f8
xorl %ebx, %ebx
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
callq *0xb8(%rax)
movq 0x8(%rax), %rcx
movq %rax, 0x28(%rsp)
subq (%rax), %rcx
shrq $0x2, %rcx
movq %rcx, 0x8(%rsp)
testl %ecx, %ecx
jle 0xb5ed
movq 0x8(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
cmpl $0x0, 0x4(%rsp)
jle 0xb53e
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %ebp
movl 0x4(%rsp), %r12d
movl %ebp, 0x1c(%rsp)
callq 0x2100
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x6946(%rip), %xmm0     # 0x11db8
mulsd 0x30(%rsp), %xmm0
addsd 0x5b90(%rip), %xmm0     # 0x11010
cvttsd2si %xmm0, %r15d
cmpl %r15d, %ebx
je 0xb535
cmpl %r15d, %ebp
je 0xb535
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq *0x50(%rax)
testb %al, %al
jne 0xb535
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0x60(%rax)
testl %eax, %eax
je 0xb535
movl %eax, %r13d
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0xb8(%rax)
movq %r14, %rbp
movl %ebx, %r14d
movq %rax, %rbx
callq 0x2100
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x68cb(%rip), %xmm0     # 0x11db8
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
mulsd %xmm0, %xmm1
addsd 0x681f(%rip), %xmm1     # 0x11d20
cvttsd2si %xmm1, %eax
movq (%rbx), %rcx
movl %r14d, %ebx
movq %rbp, %r14
movl 0x1c(%rsp), %ebp
cltq
movl -0x4(%rcx,%rax,4), %r13d
cmpl %r13d, %ebx
je 0xb535
cmpl %r13d, %ebp
je 0xb535
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
movl %r13d, %edx
callq *0x50(%rax)
testb %al, %al
je 0xb55b
decl %r12d
jne 0xb45d
movq 0x10(%rsp), %rcx
incq %rcx
movq %rcx, 0x10(%rsp)
cmpq 0x8(%rsp), %rcx
jne 0xb439
jmp 0xb5ed
movq 0xca5e(%rip), %rax      # 0x17fc0
movq (%rax), %rdi
callq 0x2240
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
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 0xb53e
movq (%r14), %rax
movq %r14, %rdi
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)
jmp 0xb53e
incl %ebx
cmpl (%rsp), %ebx
jne 0xb3f6
movq 0x20(%rsp), %rax
incl %eax
cmpl 0x18(%rsp), %eax
jne 0xb3e5
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq